2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "RoboRioSimGui.hpp"
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/glass/hardware/RoboRio.hpp"
|
|
|
|
|
#include "wpi/hal/simulation/RoboRioData.h"
|
|
|
|
|
#include "wpi/halsim/gui/HALDataSource.hpp"
|
|
|
|
|
#include "wpi/halsim/gui/HALSimGui.hpp"
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
using namespace halsimgui;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
HALSIMGUI_DATASOURCE_DOUBLE(RoboRioVInVoltage, "Rio Input Voltage");
|
|
|
|
|
HALSIMGUI_DATASOURCE_DOUBLE(RoboRioUserVoltage3V3, "Rio 3.3V Voltage");
|
|
|
|
|
HALSIMGUI_DATASOURCE_DOUBLE(RoboRioUserCurrent3V3, "Rio 3.3V Current");
|
|
|
|
|
HALSIMGUI_DATASOURCE_BOOLEAN(RoboRioUserActive3V3, "Rio 3.3V Active");
|
|
|
|
|
HALSIMGUI_DATASOURCE_INT(RoboRioUserFaults3V3, "Rio 3.3V Faults");
|
2021-10-13 19:14:27 -07:00
|
|
|
HALSIMGUI_DATASOURCE_DOUBLE(RoboRioBrownoutVoltage, "Rio Brownout Voltage");
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
class RoboRioUser3V3RailSimModel : public glass::RoboRioRailModel {
|
|
|
|
|
public:
|
|
|
|
|
void Update() override {}
|
|
|
|
|
bool Exists() override { return true; }
|
2025-01-03 13:36:40 -08:00
|
|
|
glass::DoubleSource* GetVoltageData() override { return &m_voltage; }
|
|
|
|
|
glass::DoubleSource* GetCurrentData() override { return &m_current; }
|
|
|
|
|
glass::BooleanSource* GetActiveData() override { return &m_active; }
|
|
|
|
|
glass::IntegerSource* GetFaultsData() override { return &m_faults; }
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
void SetVoltage(double val) override { HALSIM_SetRoboRioUserVoltage3V3(val); }
|
|
|
|
|
void SetCurrent(double val) override { HALSIM_SetRoboRioUserCurrent3V3(val); }
|
|
|
|
|
void SetActive(bool val) override { HALSIM_SetRoboRioUserActive3V3(val); }
|
|
|
|
|
void SetFaults(int val) override { HALSIM_SetRoboRioUserFaults3V3(val); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
RoboRioUserVoltage3V3Source m_voltage;
|
|
|
|
|
RoboRioUserCurrent3V3Source m_current;
|
|
|
|
|
RoboRioUserActive3V3Source m_active;
|
|
|
|
|
RoboRioUserFaults3V3Source m_faults;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RoboRioSimModel : public glass::RoboRioModel {
|
|
|
|
|
public:
|
|
|
|
|
void Update() override {}
|
|
|
|
|
|
|
|
|
|
bool Exists() override { return true; }
|
|
|
|
|
|
|
|
|
|
glass::RoboRioRailModel* GetUser3V3Rail() override { return &m_user3V3Rail; }
|
|
|
|
|
|
2025-01-03 13:36:40 -08:00
|
|
|
glass::DoubleSource* GetVInVoltageData() override { return &m_vInVoltage; }
|
|
|
|
|
glass::DoubleSource* GetBrownoutVoltage() override {
|
2021-10-13 19:14:27 -07:00
|
|
|
return &m_brownoutVoltage;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
void SetVInVoltage(double val) override { HALSIM_SetRoboRioVInVoltage(val); }
|
2021-10-13 19:14:27 -07:00
|
|
|
void SetBrownoutVoltage(double val) override {
|
|
|
|
|
HALSIM_SetRoboRioBrownoutVoltage(val);
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
RoboRioVInVoltageSource m_vInVoltage;
|
|
|
|
|
RoboRioUser3V3RailSimModel m_user3V3Rail;
|
2021-10-13 19:14:27 -07:00
|
|
|
RoboRioBrownoutVoltageSource m_brownoutVoltage;
|
2020-09-12 10:55:46 -07:00
|
|
|
};
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
void RoboRioSimGui::Initialize() {
|
[glass] Use JSON files for storage instead of imgui ini
Storage is now nested.
Separate "roots" can be configured which save to separate files.
In particular, this is used to save wpigui and ImGui window position
to a -window.json file.
ImGui's ini (for window position) is mapped to JSON.
You can optionally specify a directory to load from on the command line.
If one isn't provided, it uses the global system directory.
Any changes made are automatically saved here.
Workspace | Open: select directory, the current layout is replaced with that
workspace, and future auto-saves also switch to that location. The main
window size/location is not changed, only the contents.
Workspace | Save As: select directory, the current layout is saved there,
and future auto-saves also switch to that location.
Workspace | Reset: window locations are preserved, but all other settings
are reset to default (including e.g. removing plot windows). This will also
end up clearing the current save file. as with load, the main window
size/location is not changed.
Workspace | Save As Global: "save as" to the global system location
Notably, the main window size/location is only loaded at startup, but is
auto-saved as part of the current workspace.
2021-11-25 00:51:00 -08:00
|
|
|
HALSimGui::halProvider->Register(
|
2020-09-12 10:55:46 -07:00
|
|
|
"RoboRIO", [] { return true; },
|
|
|
|
|
[] { return std::make_unique<RoboRioSimModel>(); },
|
|
|
|
|
[](glass::Window* win, glass::Model* model) {
|
|
|
|
|
win->SetFlags(ImGuiWindowFlags_AlwaysAutoResize);
|
|
|
|
|
win->SetDefaultPos(5, 125);
|
|
|
|
|
return glass::MakeFunctionView(
|
|
|
|
|
[=] { DisplayRoboRio(static_cast<RoboRioSimModel*>(model)); });
|
|
|
|
|
});
|
|
|
|
|
}
|