jrl-umi3218 / mc_rtc

mc_rtc is an interface for simulated and real robotic systems suitable for real-time control
BSD 2-Clause "Simplified" License
122 stars 37 forks source link

execution cycle logging #216

Closed fkanehiro closed 2 years ago

fkanehiro commented 2 years ago

Is there a way to log execution cycle of controller?

gergondet commented 2 years ago

Hi @fkanehiro

Do you mean the time between two calls to MCGlobalController::run()?

If so, I usually do it at the outer level, i.e. instead of:

while(true)
{
  updateSensors();
  gc.run();
  updateCommand();
}

You can have:

using clock = std::chrono::high_resolution_clock;
auto prev_start_t = clock::now()
std::chrono::duration<double, std::milli> loop_dt{0};
gc.controller().addLogEntry("perf_LoopDt", [&]() { return loop_dt.count(); });
while(true)
{
  auto start_t = clock::now();
  loop_dt = start_t - prev_start_t;
  prev_start_t = start_t;
  updateSensors();
  gc.run();
  updateCommand();
}
fkanehiro commented 2 years ago

Thank you @gergondet !

Do you think it is okay to implement it in mc_openrtm permanently?

gergondet commented 2 years ago

Yes, I'll close this in favor of the discussion in jrl-umi3218/mc_openrtm#16