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

Change 300ms time delay to a while loop #341

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
19 changes: 16 additions & 3 deletions src/TunePID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,21 @@ int main(int argc, char** argv) {

double period = 8.0;

std::this_thread::sleep_for(300ms); // wait for encoder position data to arrive
int32_t starting_angle = can::motor::getMotorPosition(serial);
time_point<steady_clock> start = steady_clock::now();
int timeout = 300; // in milliseconds
abnv-goyal marked this conversation as resolved.
Show resolved Hide resolved
DataPoint<int32_t> 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();
abnv-goyal marked this conversation as resolved.
Show resolved Hide resolved
} else {
LOG_F(WARNING, "STARTING ANGLE DATA NOT FOUND");
abnv-goyal marked this conversation as resolved.
Show resolved Hide resolved
abnv-goyal marked this conversation as resolved.
Show resolved Hide resolved
}

int32_t angle_target = starting_angle;
double acc_error = 0.0;
int total_steps = 0;
Expand All @@ -159,7 +172,7 @@ int main(int argc, char** argv) {
if (mode == targetmode_t::step) {
prescaled_target = round(prescaled_target);
}
angle_target = (int32_t) round(amplitude * prescaled_target) + starting_angle;
angle_target = (int32_t)round(amplitude * prescaled_target) + starting_angle;

can::motor::setMotorPIDTarget(serial, angle_target);

Expand Down