From 28239470ef81224cfc97e48094bc55ea1537abb4 Mon Sep 17 00:00:00 2001 From: Abhinav Goyal Date: Sat, 9 Nov 2024 11:46:11 -0800 Subject: [PATCH] Make TunePID throw an error if starting angle is not found --- src/TunePID.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/TunePID.cpp b/src/TunePID.cpp index 3ab79024..671bcbe7 100644 --- a/src/TunePID.cpp +++ b/src/TunePID.cpp @@ -138,19 +138,18 @@ int main(int argc, char** argv) { double period = 8.0; time_point start = steady_clock::now(); - int timeout = 300; // in milliseconds + constexpr int timeout = 300ms; DataPoint starting_angle_data_point = can::motor::getMotorPosition(serial); while (!starting_angle_data_point.isValid() && steady_clock::now() - start < milliseconds(timeout)) { starting_angle_data_point = can::motor::getMotorPosition(serial); } - int32_t starting_angle; - if (starting_angle_data_point.isValid()) { - starting_angle = starting_angle_data_point.getData(); - } else { + if (!starting_angle_data_point.isValid()) { LOG_F(WARNING, "STARTING ANGLE DATA NOT FOUND"); } + // throws bad_datapoint_access if the data point is not valid + int32_t starting_angle = starting_angle_data_point.getData(); int32_t angle_target = starting_angle; double acc_error = 0.0;