mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Add timing window to simulation GUI
This shows the FPGA time and notifier timing, and has buttons to start/pause/step the simulation. The GUI also pauses DS new data notifications when paused. This could be done globally instead by blocking NotifyNewData at the HAL level?
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <mockdata/DriverStationData.h>
|
||||
#include <mockdata/MockHooks.h>
|
||||
#include <wpi/Format.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/StringRef.h>
|
||||
@@ -328,7 +329,7 @@ static void DriverStationExecute() {
|
||||
|
||||
// Send new data every 20 ms (may be slower depending on GUI refresh rate)
|
||||
static double lastNewDataTime = 0.0;
|
||||
if ((curTime - lastNewDataTime) > 0.02) {
|
||||
if ((curTime - lastNewDataTime) > 0.02 && !HALSIM_IsTimingPaused()) {
|
||||
lastNewDataTime = curTime;
|
||||
HALSIM_NotifyDriverStationNewData();
|
||||
}
|
||||
@@ -367,7 +368,7 @@ static void DisplayFMS() {
|
||||
ImGuiInputTextFlags_EnterReturnsTrue)) {
|
||||
HALSIM_SetDriverStationMatchTime(matchTime);
|
||||
startMatchTime = curTime - matchTime;
|
||||
} else if (!HALSIM_GetDriverStationEnabled()) {
|
||||
} else if (!HALSIM_GetDriverStationEnabled() || HALSIM_IsTimingPaused()) {
|
||||
startMatchTime = curTime - matchTime;
|
||||
} else if (matchTimeEnabled) {
|
||||
HALSIM_SetDriverStationMatchTime(curTime - startMatchTime);
|
||||
|
||||
60
simulation/halsim_gui/src/main/native/cpp/TimingGui.cpp
Normal file
60
simulation/halsim_gui/src/main/native/cpp/TimingGui.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 "TimingGui.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include <hal/HALBase.h>
|
||||
#include <imgui.h>
|
||||
#include <mockdata/MockHooks.h>
|
||||
#include <mockdata/NotifierData.h>
|
||||
|
||||
#include "HALSimGui.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
static void DisplayTiming() {
|
||||
int32_t status = 0;
|
||||
uint64_t curTime = HAL_GetFPGATime(&status);
|
||||
|
||||
if (ImGui::Button("Run")) HALSIM_ResumeTiming();
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Pause")) HALSIM_PauseTiming();
|
||||
ImGui::SameLine();
|
||||
ImGui::PushButtonRepeat(true);
|
||||
if (ImGui::Button("Step")) {
|
||||
HALSIM_PauseTiming();
|
||||
uint64_t nextTimeout = HALSIM_GetNextNotifierTimeout();
|
||||
if (nextTimeout != UINT64_MAX) HALSIM_StepTiming(nextTimeout - curTime);
|
||||
}
|
||||
ImGui::PopButtonRepeat();
|
||||
ImGui::PushItemWidth(ImGui::GetFontSize() * 4);
|
||||
ImGui::LabelText("FPGA Time", "%.3f", curTime / 1000000.0);
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
static std::vector<HALSIM_NotifierInfo> notifiers;
|
||||
int32_t num = HALSIM_GetNotifierInfo(notifiers.data(), notifiers.size());
|
||||
if (static_cast<uint32_t>(num) > notifiers.size()) {
|
||||
notifiers.resize(num);
|
||||
HALSIM_GetNotifierInfo(notifiers.data(), notifiers.size());
|
||||
}
|
||||
if (num > 0) ImGui::Separator();
|
||||
ImGui::PushItemWidth(ImGui::GetFontSize() * 4);
|
||||
for (int32_t i = 0; i < num; ++i)
|
||||
ImGui::LabelText(notifiers[i].name, "%.3f",
|
||||
notifiers[i].timeout / 1000000.0);
|
||||
ImGui::PopItemWidth();
|
||||
}
|
||||
|
||||
void TimingGui::Initialize() {
|
||||
HALSimGui::AddWindow("Timing", DisplayTiming,
|
||||
ImGuiWindowFlags_AlwaysAutoResize);
|
||||
HALSimGui::SetDefaultWindowPos("Timing", 5, 150);
|
||||
}
|
||||
17
simulation/halsim_gui/src/main/native/cpp/TimingGui.h
Normal file
17
simulation/halsim_gui/src/main/native/cpp/TimingGui.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace halsimgui {
|
||||
|
||||
class TimingGui {
|
||||
public:
|
||||
static void Initialize();
|
||||
};
|
||||
|
||||
} // namespace halsimgui
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "RoboRioGui.h"
|
||||
#include "SimDeviceGui.h"
|
||||
#include "SolenoidGui.h"
|
||||
#include "TimingGui.h"
|
||||
|
||||
using namespace halsimgui;
|
||||
|
||||
@@ -45,6 +46,7 @@ __declspec(dllexport)
|
||||
HALSimGui::Add(RoboRioGui::Initialize);
|
||||
HALSimGui::Add(SimDeviceGui::Initialize);
|
||||
HALSimGui::Add(SolenoidGui::Initialize);
|
||||
HALSimGui::Add(TimingGui::Initialize);
|
||||
|
||||
wpi::outs() << "Simulator GUI Initializing.\n";
|
||||
if (!HALSimGui::Initialize()) return 0;
|
||||
|
||||
Reference in New Issue
Block a user