[glass, wpilib] Rewrite Mechanism2d (#3281)

Substantially improves Mechanism2d by moving it to NetworkTables and adding
a robot API to create the mechanism elements, instead of requiring a JSON file.

Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
This commit is contained in:
Starlight220
2021-04-30 23:43:59 +03:00
committed by GitHub
parent ee0eed143a
commit ff52f207cc
28 changed files with 1780 additions and 479 deletions

View File

@@ -11,6 +11,7 @@
#include "glass/networktables/NTField2D.h"
#include "glass/networktables/NTGyro.h"
#include "glass/networktables/NTMecanumDrive.h"
#include "glass/networktables/NTMechanism2D.h"
#include "glass/networktables/NTPIDController.h"
#include "glass/networktables/NTSpeedController.h"
#include "glass/networktables/NTStringChooser.h"
@@ -117,6 +118,18 @@ void glass::AddStandardNetworkTablesViews(NetworkTablesProvider& provider) {
return MakeFunctionView(
[=] { DisplayDrive(static_cast<NTMecanumDriveModel*>(model)); });
});
provider.Register(
NTMechanism2DModel::kType,
[](NT_Inst inst, const char* path) {
return std::make_unique<NTMechanism2DModel>(inst, path);
},
[=](Window* win, Model* model, const char* path) {
win->SetDefaultPos(400, 400);
win->SetDefaultSize(200, 200);
win->SetPadding(0, 0);
return std::make_unique<Mechanism2DView>(
static_cast<NTMechanism2DModel*>(model));
});
provider.Register(
NTPIDControllerModel::kType,
[](NT_Inst inst, const char* path) {