Skip to content

Commit

Permalink
Formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jan 4, 2024
1 parent a652a04 commit f4066fd
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 57 deletions.
3 changes: 1 addition & 2 deletions sysid/src/main/native/cpp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ void Application(std::string_view saveDir) {
gDataSelectorWindow =
gWindowManager->AddWindow("Data Selector", std::move(dataSelector));

gAnalyzerWindow = gWindowManager->AddWindow(
"Analyzer", std::move(analyzer));
gAnalyzerWindow = gWindowManager->AddWindow("Analyzer", std::move(analyzer));

gProgramLogWindow = gWindowManager->AddWindow(
"Program Log", std::make_unique<glass::LogView>(&gLog));
Expand Down
40 changes: 18 additions & 22 deletions sysid/src/main/native/cpp/analysis/AnalysisManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

#include <fmt/format.h>
#include <units/angle.h>
#include <wpi/MathExtras.h>
#include <wpi/MemoryBuffer.h>
#include <wpi/StringExtras.h>
#include <wpi/StringMap.h>

#include "sysid/analysis/FilteringUtils.h"
#include "wpi/MathExtras.h"

using namespace sysid;

Expand Down Expand Up @@ -66,9 +66,10 @@ static std::vector<PreparedData> ConvertToPrepared(const MotorData& data) {

auto currentVelocity = Lerp(currentVoltage.time, run.velocity);

prepared.emplace_back(PreparedData{
currentVoltage.time, currentVoltage.measurement.value(), currentPosition,
currentVelocity, nextVoltage.time - currentVoltage.time});
prepared.emplace_back(PreparedData{currentVoltage.time,
currentVoltage.measurement.value(),
currentPosition, currentVelocity,
nextVoltage.time - currentVoltage.time});
}

return prepared;
Expand Down Expand Up @@ -128,7 +129,6 @@ void AnalysisManager::PrepareGeneralData() {
WPI_INFO(m_logger, "SAMPLES {}", preparedData[key].size());
}


// Store the original datasets
m_originalDataset =
CombineDatasets(preparedData["original-raw-quasistatic-forward"],
Expand All @@ -149,16 +149,15 @@ void AnalysisManager::PrepareGeneralData() {

WPI_INFO(m_logger, "{}", "Storing datasets.");
// Store the raw datasets
m_rawDataset =
CombineDatasets(
preparedData["raw-quasistatic-forward"], preparedData["raw-quasistatic-reverse"],
preparedData["raw-dynamic-forward"], preparedData["raw-dynamic-reverse"]);
m_rawDataset = CombineDatasets(preparedData["raw-quasistatic-forward"],
preparedData["raw-quasistatic-reverse"],
preparedData["raw-dynamic-forward"],
preparedData["raw-dynamic-reverse"]);

// Store the filtered datasets
m_filteredDataset =
CombineDatasets(
preparedData["quasistatic-forward"], preparedData["quasistatic-reverse"],
preparedData["dynamic-forward"], preparedData["dynamic-reverse"]);
m_filteredDataset = CombineDatasets(
preparedData["quasistatic-forward"], preparedData["quasistatic-reverse"],
preparedData["dynamic-forward"], preparedData["dynamic-reverse"]);

m_startTimes = {preparedData["raw-quasistatic-forward"][0].timestamp,
preparedData["raw-quasistatic-reverse"][0].timestamp,
Expand All @@ -167,20 +166,18 @@ void AnalysisManager::PrepareGeneralData() {
}

AnalysisManager::AnalysisManager(Settings& settings, wpi::Logger& logger)
: m_logger{logger},
m_settings{settings} {}
: m_logger{logger}, m_settings{settings} {}

AnalysisManager::AnalysisManager(TestData data, Settings& settings,
wpi::Logger& logger)
: m_data{std::move(data)}, m_logger{logger}, m_settings{settings} {

// Reset settings for Dynamic Test Limits
m_settings.stepTestDuration = units::second_t{0.0};
m_settings.motionThreshold = std::numeric_limits<double>::infinity();
}

void AnalysisManager::PrepareData() {
// WPI_INFO(m_logger, "Preparing {} data", m_data.mechanismType.name);
// WPI_INFO(m_logger, "Preparing {} data", m_data.mechanismType.name);

PrepareGeneralData();

Expand All @@ -195,8 +192,9 @@ AnalysisManager::FeedforwardGains AnalysisManager::CalculateFeedforward() {

WPI_INFO(m_logger, "{}", "Calculating Gains");
// Calculate feedforward gains from the data.
const auto& ff = sysid::CalculateFeedforwardGains(GetFilteredData(), m_data.mechanismType, false);
FeedforwardGains ffGains = {ff };
const auto& ff = sysid::CalculateFeedforwardGains(
GetFilteredData(), m_data.mechanismType, false);
FeedforwardGains ffGains = {ff};

const auto& Ks = ff.coeffs[0];
const auto& Kv = ff.coeffs[1];
Expand Down Expand Up @@ -238,6 +236,4 @@ void AnalysisManager::OverrideUnits(std::string_view unit) {
m_data.distanceUnit = unit;
}

void AnalysisManager::ResetUnitsFromJSON() {

}
void AnalysisManager::ResetUnitsFromJSON() {}
11 changes: 5 additions & 6 deletions sysid/src/main/native/cpp/analysis/FilteringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,17 @@ sysid::TrimStepVoltageData(std::vector<PreparedData>* data,
minStepTime = std::min(data->at(0).timestamp - firstTimestamp, minStepTime);

// Find maximum speed reached
const auto maxSpeed = GetMaxSpeed(
*data, [](auto&& pt) { return pt.velocity; });
const auto maxSpeed =
GetMaxSpeed(*data, [](auto&& pt) { return pt.velocity; });
// Find place where 90% of maximum speed exceeded
auto endIt = std::find_if(
data->begin(), data->end(), [&](const PreparedData& entry) {
auto endIt =
std::find_if(data->begin(), data->end(), [&](const PreparedData& entry) {
return std::abs(entry.velocity) > maxSpeed * 0.9;
});

if (endIt != data->end()) {
settings->stepTestDuration = std::min(
endIt->timestamp - data->front().timestamp + minStepTime,
maxStepTime);
endIt->timestamp - data->front().timestamp + minStepTime, maxStepTime);
}

// Find first entry greater than the step test duration
Expand Down
3 changes: 1 addition & 2 deletions sysid/src/main/native/cpp/view/Analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,7 @@ void Analyzer::DisplayGraphs() {
}

void Analyzer::AnalyzeData() {
m_manager =
std::make_unique<AnalysisManager>(m_data, m_settings, m_logger);
m_manager = std::make_unique<AnalysisManager>(m_data, m_settings, m_logger);
PrepareData();
m_dataset = 0;
ConfigParamsOnFileSelect();
Expand Down
4 changes: 2 additions & 2 deletions sysid/src/main/native/cpp/view/DataSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

#include "sysid/view/DataSelector.h"

#include <glass/support/DataLogReaderThread.h>
#include <fmt/format.h>
#include <glass/support/DataLogReaderThread.h>
#include <imgui.h>
#include <wpi/DataLogReader.h>
#include <wpi/Logger.h>
#include <wpi/StringExtras.h>

#include "sysid/Util.h"
#include "sysid/analysis/AnalysisType.h"
#include "sysid/analysis/Storage.h"
#include "wpi/DataLogReader.h"

using namespace sysid;

Expand Down
28 changes: 10 additions & 18 deletions sysid/src/main/native/include/sysid/analysis/AnalysisManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

#include <units/time.h>
#include <wpi/Logger.h>
#include <wpi/StringMap.h>
#include <wpi/json.h>

#include "sysid/analysis/AnalysisType.h"
#include "sysid/analysis/FeedbackAnalysis.h"
#include "sysid/analysis/FeedbackControllerPreset.h"
#include "sysid/analysis/FeedforwardAnalysis.h"
#include "sysid/analysis/Storage.h"
#include "wpi/StringMap.h"

namespace sysid {

Expand All @@ -34,8 +34,8 @@ namespace sysid {
*/
class AnalysisManager {
public:
// This contains data for each test (e.g. quasistatic-forward, quasistatic-backward, etc)
// indexed by test name
// This contains data for each test (e.g. quasistatic-forward,
// quasistatic-backward, etc) indexed by test name
TestData m_data;
/**
* Represents settings for an instance of the analysis manager. This contains
Expand Down Expand Up @@ -129,7 +129,8 @@ class AnalysisManager {
* The keys (which contain sysid data) that are in the JSON to analyze.
*/
static constexpr const char* kJsonDataKeys[] = {
"quasistatic-forward", "quasistatic-reverse", "dynamic-forward", "dynamic-reverse"};
"quasistatic-forward", "quasistatic-reverse", "dynamic-forward",
"dynamic-reverse"};

/**
* Concatenates a list of vectors. The contents of the source vectors are
Expand Down Expand Up @@ -170,8 +171,7 @@ class AnalysisManager {
* @param settings The settings for this instance of the analysis manager.
* @param logger The logger instance to use for log data.
*/
AnalysisManager(TestData data, Settings& settings,
wpi::Logger& logger);
AnalysisManager(TestData data, Settings& settings, wpi::Logger& logger);

/**
* Prepares data from the JSON and stores the output in Storage member
Expand Down Expand Up @@ -228,9 +228,7 @@ class AnalysisManager {
*
* @return A reference to the raw internal data.
*/
Storage& GetRawData() {
return m_rawDataset;
}
Storage& GetRawData() { return m_rawDataset; }

/**
* Returns a reference to the iterator of the currently selected filtered
Expand All @@ -239,18 +237,14 @@ class AnalysisManager {
*
* @return A reference to the filtered internal data.
*/
Storage& GetFilteredData() {
return m_filteredDataset;
}
Storage& GetFilteredData() { return m_filteredDataset; }

/**
* Returns the original dataset.
*
* @return The original (untouched) dataset
*/
Storage& GetOriginalData() {
return m_originalDataset;
}
Storage& GetOriginalData() { return m_originalDataset; }

/**
* Returns the minimum duration of the Step Voltage Test of the currently
Expand Down Expand Up @@ -301,9 +295,7 @@ class AnalysisManager {
return m_startTimes;
}

bool HasData() const {
return !m_originalDataset.empty();
}
bool HasData() const { return !m_originalDataset.empty(); }

private:
wpi::Logger& m_logger;
Expand Down
5 changes: 2 additions & 3 deletions sysid/src/main/native/include/sysid/analysis/FilteringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ double GetNoiseFloor(
const std::vector<PreparedData>& data, int window,
std::function<double(const PreparedData&)> accessorFunction);

double GetMaxSpeed(
const std::vector<PreparedData>& data,
std::function<double(const PreparedData&)> accessorFunction);
double GetMaxSpeed(const std::vector<PreparedData>& data,
std::function<double(const PreparedData&)> accessorFunction);

/**
* Reduces noise in velocity data by applying a median filter.
Expand Down
2 changes: 1 addition & 1 deletion sysid/src/main/native/include/sysid/view/Analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class Analyzer : public glass::View {
* Analyzes the selected data.
*/
void AnalyzeData();
private:

private:
/**
* Kills the data preparation thread
*/
Expand Down
2 changes: 1 addition & 1 deletion sysid/src/main/native/include/sysid/view/DataSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DataSelector : public glass::View {
* @param logger The program logger
*/
explicit DataSelector(glass::Storage& storage, wpi::Logger& logger)
/*: m_logger{logger}*/ {}
/*: m_logger{logger}*/ {}

/**
* Displays the log loader window.
Expand Down

0 comments on commit f4066fd

Please sign in to comment.