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

Robocup bug fix of Thunderloop clock #3317

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Changes from 4 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
19 changes: 12 additions & 7 deletions src/software/embedded/thunderloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void Thunderloop::runLoop()
struct timespec current_time;
struct timespec last_chipper_fired;
struct timespec last_kicker_fired;
struct timespec prev_iter_start_time;

// Input buffer
TbotsProto::PrimitiveSet new_primitive_set;
Expand All @@ -165,11 +166,17 @@ void Thunderloop::runLoop()
clock_gettime(CLOCK_MONOTONIC, &last_world_received_time);
clock_gettime(CLOCK_MONOTONIC, &last_chipper_fired);
clock_gettime(CLOCK_MONOTONIC, &last_kicker_fired);
clock_gettime(CLOCK_MONOTONIC, &prev_iter_start_time);

double loop_duration_seconds = 0.0;

for (;;)
{
struct timespec time_since_prev_iter;
clock_gettime(CLOCK_MONOTONIC, &current_time);
ScopedTimespecTimer::timespecDiff(&current_time, &prev_iter_start_time,
&time_since_prev_iter);
prev_iter_start_time = current_time;
{
// Wait until next shot
//
Expand Down Expand Up @@ -321,9 +328,11 @@ void Thunderloop::runLoop()
ScopedTimespecTimer timer(&poll_time);

ZoneNamedN(_tracy_motor_service, "Thunderloop: Poll MotorService", true);
double time_since_prev_iter_sec =
getMilliseconds(time_since_prev_iter) * SECONDS_PER_MILLISECOND;

motor_status_ = motor_service_->poll(direct_control_.motor_control(),
loop_duration_seconds);
time_since_prev_iter_sec);
}
thunderloop_status_.set_motor_service_poll_time_ms(
getMilliseconds(poll_time));
Expand Down Expand Up @@ -364,12 +373,8 @@ void Thunderloop::runLoop()
thunderloop_status_.set_iteration_time_ms(loop_duration_ns /
NANOSECONDS_PER_MILLISECOND);

// Make sure the iteration can fit inside the period of the loop
loop_duration_seconds =
static_cast<double>(loop_duration_ns) * SECONDS_PER_NANOSECOND;

// Calculate next shot taking into account how long this iteration took
next_shot.tv_nsec += interval - static_cast<long int>(loop_duration_ns);
// Calculate next shot (which is an absolute time)
next_shot.tv_nsec += interval;
timespecNorm(next_shot);

FrameMarkEnd(TracyConstants::THUNDERLOOP_FRAME_MARKER);
Expand Down
Loading