Skip to content

Commit

Permalink
Add scaling for position and velocity
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Jan 4, 2024
1 parent e33d4b6 commit a652a04
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
19 changes: 11 additions & 8 deletions sysid/src/main/native/cpp/view/DataSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

using namespace sysid;

static constexpr const char* kAnalysisTypes[] = { "Elevator",
"Arm", "Simple"};
static constexpr const char* kAnalysisTypes[] = {"Elevator", "Arm", "Simple"};

static bool EmitEntryTarget(const char* name, bool isString,
const glass::DataLogReaderEntry** entry) {
Expand Down Expand Up @@ -126,6 +125,9 @@ void DataSelector::Display() {
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 7);
ImGui::Combo("Units", &m_selectedUnit, kUnits, IM_ARRAYSIZE(kUnits));

ImGui::InputDouble("Velocity scaling", &m_velocityScale);
ImGui::InputDouble("Position scaling", &m_positionScale);

if (/*!m_selectedTest.empty() &&*/ m_velocityEntry && m_positionEntry &&
m_voltageEntry) {
if (ImGui::Button("Load")) {
Expand Down Expand Up @@ -195,18 +197,19 @@ DataSelector::Tests DataSelector::LoadTests(

template <typename T>
static void AddSample(std::vector<MotorData::Run::Sample<T>>& samples,
const wpi::log::DataLogRecord& record, bool isDouble) {
const wpi::log::DataLogRecord& record, bool isDouble,
double scale) {
if (isDouble) {
double val;
if (record.GetDouble(&val)) {
samples.emplace_back(units::second_t{record.GetTimestamp() * 1.0e-6},
T{val});
T{val * scale});
}
} else {
float val;
if (record.GetFloat(&val)) {
samples.emplace_back(units::second_t{record.GetTimestamp() * 1.0e-6},
T{static_cast<double>(val)});
T{static_cast<double>(val * scale)});
}
}
}
Expand All @@ -226,11 +229,11 @@ TestData DataSelector::BuildTestData() {
auto& run = motorData.runs.emplace_back();
for (auto&& record : range) {
if (record.GetEntry() == m_voltageEntry->entry) {
AddSample(run.voltage, record, voltageDouble);
AddSample(run.voltage, record, voltageDouble, 1.0);
} else if (record.GetEntry() == m_positionEntry->entry) {
AddSample(run.position, record, positionDouble);
AddSample(run.position, record, positionDouble, m_positionScale);
} else if (record.GetEntry() == m_velocityEntry->entry) {
AddSample(run.velocity, record, velocityDouble);
AddSample(run.velocity, record, velocityDouble, m_velocityScale);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions sysid/src/main/native/include/sysid/view/DataSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class DataSelector : public glass::View {
const glass::DataLogReaderEntry* m_velocityEntry = nullptr;
const glass::DataLogReaderEntry* m_positionEntry = nullptr;
const glass::DataLogReaderEntry* m_voltageEntry = nullptr;
double m_velocityScale = 1.0;
double m_positionScale = 1.0;
int m_selectedUnit = 0;
int m_selectedAnalysis = 0;
std::future<TestData> m_testdataFuture;
Expand Down
2 changes: 1 addition & 1 deletion sysid/src/main/native/include/sysid/view/UILayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ inline constexpr Vector2d kLeftColSize{

// Left column contents
inline constexpr Vector2d kLogLoaderWindowPos = kLeftColPos;
inline constexpr Vector2d kLogLoaderWindowSize{kLeftColSize.x, 500};
inline constexpr Vector2d kLogLoaderWindowSize{kLeftColSize.x, 450};
inline constexpr Vector2d kDataSelectorWindowPos =
kLogLoaderWindowPos + Vector2d{0, kLogLoaderWindowSize.y + kWindowGap};
inline constexpr Vector2d kDataSelectorWindowSize{
Expand Down

0 comments on commit a652a04

Please sign in to comment.