mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
[glass] Add Profiled PID controller support & IZone Support (#5959)
This commit is contained in:
@@ -29,6 +29,16 @@ void glass::DisplayPIDController(PIDControllerModel* m) {
|
||||
callback(*v);
|
||||
}
|
||||
};
|
||||
// Workaround to allow for the input of inf, -inf, and nan
|
||||
auto createTuningParameterNoFilter =
|
||||
[flag](const char* name, double* v,
|
||||
std::function<void(double)> callback) {
|
||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
||||
if (ImGui::InputScalar(name, ImGuiDataType_Double, v, NULL, NULL,
|
||||
"%.3f", flag)) {
|
||||
callback(*v);
|
||||
}
|
||||
};
|
||||
|
||||
if (auto p = m->GetPData()) {
|
||||
double value = p->GetValue();
|
||||
@@ -47,6 +57,11 @@ void glass::DisplayPIDController(PIDControllerModel* m) {
|
||||
createTuningParameter("Setpoint", &value,
|
||||
[=](auto v) { m->SetSetpoint(v); });
|
||||
}
|
||||
if (auto s = m->GetIZoneData()) {
|
||||
double value = s->GetValue();
|
||||
createTuningParameterNoFilter("IZone", &value,
|
||||
[=](auto v) { m->SetIZone(v); });
|
||||
}
|
||||
} else {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(96, 96, 96, 255));
|
||||
ImGui::Text("Unknown PID Controller");
|
||||
|
||||
69
glass/src/lib/native/cpp/other/ProfiledPIDController.cpp
Normal file
69
glass/src/lib/native/cpp/other/ProfiledPIDController.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
// 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.
|
||||
|
||||
#include "glass/other/ProfiledPIDController.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
#include "glass/Context.h"
|
||||
#include "glass/DataSource.h"
|
||||
|
||||
using namespace glass;
|
||||
|
||||
void glass::DisplayProfiledPIDController(ProfiledPIDControllerModel* m) {
|
||||
if (auto name = m->GetName()) {
|
||||
ImGui::Text("%s", name);
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
if (m->Exists()) {
|
||||
auto flag = m->IsReadOnly() ? ImGuiInputTextFlags_ReadOnly
|
||||
: ImGuiInputTextFlags_None;
|
||||
auto createTuningParameter = [flag](const char* name, double* v,
|
||||
std::function<void(double)> callback) {
|
||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
||||
if (ImGui::InputDouble(name, v, 0.0, 0.0, "%.3f", flag)) {
|
||||
callback(*v);
|
||||
}
|
||||
};
|
||||
// Workaround to allow for the input of inf, -inf, and nan
|
||||
auto createTuningParameterNoFilter =
|
||||
[flag](const char* name, double* v,
|
||||
std::function<void(double)> callback) {
|
||||
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
|
||||
if (ImGui::InputScalar(name, ImGuiDataType_Double, v, NULL, NULL,
|
||||
"%.3f", flag)) {
|
||||
callback(*v);
|
||||
}
|
||||
};
|
||||
|
||||
if (auto p = m->GetPData()) {
|
||||
double value = p->GetValue();
|
||||
createTuningParameter("P", &value, [=](auto v) { m->SetP(v); });
|
||||
}
|
||||
if (auto i = m->GetIData()) {
|
||||
double value = i->GetValue();
|
||||
createTuningParameter("I", &value, [=](auto v) { m->SetI(v); });
|
||||
}
|
||||
if (auto d = m->GetDData()) {
|
||||
double value = d->GetValue();
|
||||
createTuningParameter("D", &value, [=](auto v) { m->SetD(v); });
|
||||
}
|
||||
if (auto s = m->GetGoalData()) {
|
||||
double value = s->GetValue();
|
||||
createTuningParameter("Goal", &value, [=](auto v) { m->SetGoal(v); });
|
||||
}
|
||||
if (auto s = m->GetIZoneData()) {
|
||||
double value = s->GetValue();
|
||||
createTuningParameterNoFilter("IZone", &value,
|
||||
[=](auto v) { m->SetIZone(v); });
|
||||
}
|
||||
} else {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(96, 96, 96, 255));
|
||||
ImGui::Text("Unknown PID Controller");
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user