Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sysid] Remove unused "gains to encoder counts" checkbox #6234

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions sysid/src/main/native/cpp/analysis/AnalysisManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,11 @@ sysid::FeedbackGains AnalysisManager::CalculateFeedback(
const auto& Ka = ff[2];
FeedbackGains fb;
if (m_settings.type == FeedbackControllerLoopType::kPosition) {
fb = sysid::CalculatePositionFeedbackGains(
m_settings.preset, m_settings.lqr, Kv, Ka,
m_settings.convertGainsToEncTicks ? m_settings.gearing * m_settings.cpr
: 1);
fb = sysid::CalculatePositionFeedbackGains(m_settings.preset,
m_settings.lqr, Kv, Ka);
} else {
fb = sysid::CalculateVelocityFeedbackGains(
m_settings.preset, m_settings.lqr, Kv, Ka,
m_settings.convertGainsToEncTicks ? m_settings.gearing * m_settings.cpr
: 1);
fb = sysid::CalculateVelocityFeedbackGains(m_settings.preset,
m_settings.lqr, Kv, Ka);
}

return fb;
Expand Down
9 changes: 4 additions & 5 deletions sysid/src/main/native/cpp/analysis/FeedbackAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using Ka_t = decltype(1_V / 1_mps_sq);

FeedbackGains sysid::CalculatePositionFeedbackGains(
const FeedbackControllerPreset& preset, const LQRParameters& params,
double Kv, double Ka, double encFactor) {
double Kv, double Ka) {
// If acceleration requires no effort, velocity becomes an input for position
// control. We choose an appropriate model in this case to avoid numerical
// instabilities in the LQR.
Expand All @@ -34,9 +34,9 @@ FeedbackGains sysid::CalculatePositionFeedbackGains(
// Compensate for any latency from sensor measurements, filtering, etc.
controller.LatencyCompensate(system, preset.period, 0.0_s);

return {controller.K(0, 0) * preset.outputConversionFactor / encFactor,
return {controller.K(0, 0) * preset.outputConversionFactor,
controller.K(0, 1) * preset.outputConversionFactor /
(encFactor * (preset.normalized ? 1 : preset.period.value()))};
(preset.normalized ? 1 : preset.period.value())};
}

// This is our special model to avoid instabilities in the LQR.
Expand All @@ -49,8 +49,7 @@ FeedbackGains sysid::CalculatePositionFeedbackGains(
// Compensate for any latency from sensor measurements, filtering, etc.
controller.LatencyCompensate(system, preset.period, 0.0_s);

return {Kv * controller.K(0, 0) * preset.outputConversionFactor / encFactor,
0.0};
return {Kv * controller.K(0, 0) * preset.outputConversionFactor, 0.0};
}

FeedbackGains sysid::CalculateVelocityFeedbackGains(
Expand Down
54 changes: 0 additions & 54 deletions sysid/src/main/native/cpp/view/Analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,6 @@ void Analyzer::DisplayFeedbackGains() {
m_settings.type = FeedbackControllerLoopType::kVelocity;
m_selectedLoopType =
static_cast<int>(FeedbackControllerLoopType::kVelocity);
m_settings.convertGainsToEncTicks = m_selectedPreset > 2;
UpdateFeedbackGains();
}
ImGui::SameLine();
Expand Down Expand Up @@ -646,59 +645,6 @@ void Analyzer::DisplayFeedbackGains() {
"accurate if the characteristic timescale of the mechanism "
"is small.");

// Add CPR and Gearing for converting Feedback Gains
ImGui::Separator();
ImGui::Spacing();

if (ImGui::Checkbox("Convert Gains to Encoder Counts",
&m_settings.convertGainsToEncTicks)) {
UpdateFeedbackGains();
}
sysid::CreateTooltip(
"Whether the feedback gains should be in terms of encoder counts or "
"output units. Because smart motor controllers usually don't have "
"direct access to the output units (i.e. m/s for a drivetrain), they "
"perform feedback on the encoder counts directly. If you are using a "
"PID Controller on the RoboRIO, you are probably performing feedback "
"on the output units directly.\n\nNote that if you have properly set "
"up position and velocity conversion factors with the SPARK MAX, you "
"can leave this box unchecked. The motor controller will perform "
"feedback on the output directly.");

if (m_settings.convertGainsToEncTicks) {
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 5);
if (ImGui::InputDouble("##Numerator", &m_gearingNumerator, 0.0, 0.0, "%.4f",
ImGuiInputTextFlags_EnterReturnsTrue) &&
m_gearingNumerator > 0) {
m_settings.gearing = m_gearingNumerator / m_gearingDenominator;
UpdateFeedbackGains();
}
ImGui::SameLine();
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 5);
if (ImGui::InputDouble("##Denominator", &m_gearingDenominator, 0.0, 0.0,
"%.4f", ImGuiInputTextFlags_EnterReturnsTrue) &&
m_gearingDenominator > 0) {
m_settings.gearing = m_gearingNumerator / m_gearingDenominator;
UpdateFeedbackGains();
}
sysid::CreateTooltip(
"The gearing between the encoder and the motor shaft (# of encoder "
"turns / # of motor shaft turns).");

ImGui::SetNextItemWidth(ImGui::GetFontSize() * 5);
if (ImGui::InputInt("CPR", &m_settings.cpr, 0, 0,
ImGuiInputTextFlags_EnterReturnsTrue) &&
m_settings.cpr > 0) {
UpdateFeedbackGains();
}
sysid::CreateTooltip(
"The counts per rotation of your encoder. This is the number of counts "
"reported in user code when the encoder is rotated exactly once. Some "
"common values for various motors/encoders are:\n\n"
"Falcon 500: 2048\nNEO: 1\nCTRE Mag Encoder / CANCoder: 4096\nREV "
"Through Bore Encoder: 8192\n");
}

ImGui::Separator();
ImGui::Spacing();

Expand Down
16 changes: 0 additions & 16 deletions sysid/src/main/native/include/sysid/analysis/AnalysisManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,6 @@ class AnalysisManager {
* zero indicates it needs to be set to the default.
*/
units::second_t stepTestDuration = 0_s;

/**
* The conversion factor of counts per revolution.
*/
int cpr = 1440;

/**
* The conversion factor of gearing.
*/
double gearing = 1;

/**
* Whether or not the gains should be in the encoder's units (mainly for use
* in a smart motor controller).
*/
bool convertGainsToEncTicks = false;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,14 @@ struct FeedbackGains {
* Calculates position feedback gains for the given controller preset, LQR
* controller gain parameters and feedforward gains.
*
* @param preset The feedback controller preset.
* @param params The parameters for calculating optimal feedback
* gains.
* @param Kv Velocity feedforward gain.
* @param Ka Acceleration feedforward gain.
* @param encFactor The factor to convert the gains from output units to
* encoder units. This is usually encoder EPR * gearing
* * units per rotation.
* @param preset The feedback controller preset.
* @param params The parameters for calculating optimal feedback gains.
* @param Kv Velocity feedforward gain.
* @param Ka Acceleration feedforward gain.
*/
FeedbackGains CalculatePositionFeedbackGains(
const FeedbackControllerPreset& preset, const LQRParameters& params,
double Kv, double Ka, double encFactor = 1.0);
double Kv, double Ka);

/**
* Calculates velocity feedback gains for the given controller preset, LQR
Expand Down
3 changes: 0 additions & 3 deletions sysid/src/main/native/include/sysid/view/Analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@ class Analyzer : public glass::View {
double m_threshold = 0.2;
float m_stepTestDuration = 0;

double m_gearingNumerator = 1.0;
double m_gearingDenominator = 1.0;

bool combinedGraphFit = false;

// Logger
Expand Down