Add simulation GUI plugin

This uses Dear Imgui to provide a cross-platform integrated GUI for robot
simulation. The GUI provides fully integrated DS and joystick support so it's
not necessary to run the official DS.
This commit is contained in:
Peter Johnson
2019-09-23 00:24:10 -07:00
parent f97d16073a
commit 2b4894038e
42 changed files with 2673 additions and 1 deletions

View File

@@ -0,0 +1,59 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "CompressorGui.h"
#include <cstdio>
#include <hal/Ports.h>
#include <hal/Value.h>
#include <imgui.h>
#include <mockdata/PCMData.h>
#include "SimDeviceGui.h"
using namespace halsimgui;
static void DisplayCompressors() {
static int numPcm = HAL_GetNumPCMModules();
for (int i = 0; i < numPcm; ++i) {
if (!HALSIM_GetPCMCompressorInitialized(i)) continue;
char name[32];
std::snprintf(name, sizeof(name), "Compressor[%d]", i);
if (SimDeviceGui::StartDevice(name)) {
HAL_Value value;
// enabled
value = HAL_MakeBoolean(HALSIM_GetPCMCompressorOn(i));
if (SimDeviceGui::DisplayValue("Running", false, &value))
HALSIM_SetPCMCompressorOn(i, value.data.v_boolean);
// closed loop
value = HAL_MakeEnum(HALSIM_GetPCMClosedLoopEnabled(i) ? 1 : 0);
static const char* enabledOptions[] = {"disabled", "enabled"};
if (SimDeviceGui::DisplayValue("Closed Loop", true, &value,
enabledOptions, 2))
HALSIM_SetPCMClosedLoopEnabled(i, value.data.v_enum);
// pressure switch
value = HAL_MakeEnum(HALSIM_GetPCMPressureSwitch(i) ? 1 : 0);
static const char* switchOptions[] = {"full", "low"};
if (SimDeviceGui::DisplayValue("Pressure", false, &value, switchOptions,
2))
HALSIM_SetPCMPressureSwitch(i, value.data.v_enum);
// compressor current
value = HAL_MakeDouble(HALSIM_GetPCMCompressorCurrent(i));
if (SimDeviceGui::DisplayValue("Current (A)", false, &value))
HALSIM_SetPCMCompressorCurrent(i, value.data.v_double);
SimDeviceGui::FinishDevice();
}
}
}
void CompressorGui::Initialize() { SimDeviceGui::Add(DisplayCompressors); }