[JTC] Fix time sources and wrong checks in tests#686
[JTC] Fix time sources and wrong checks in tests#686destogl merged 5 commits intoros-controls:jtc-featuresfrom
Conversation
| EXPECT_NEAR(4.0, joint_pos_[0], COMMON_THRESHOLD); | ||
| EXPECT_NEAR(5.0, joint_pos_[1], COMMON_THRESHOLD); | ||
| EXPECT_NEAR(6.0, joint_pos_[2], COMMON_THRESHOLD); |
There was a problem hiding this comment.
It would be great to use variables instead of the numbers.
There was a problem hiding this comment.
you are right. with the next PR ;)
* Fix time sources and wrong checks in tests * Use time from update-method instead of node clock * Readd test of last command in test_goal_tolerances_fail --------- Co-authored-by: Bence Magyar <bence.magyar.robotics@gmail.com>
|
Hi @christophfroehlich I was not sure where to ask something regarding the feature branch, but since it is related to timing, and I should work from the feature branch I ask here while writing a test for joint_limiter in JTC, I would like to use the method instead of computing the period = time delta between 2 calls of update, the time period just gets bigger and reaches wait_time finally. auto previous_time = start_time;
while (clock.now() < end_time)
{
auto now = clock.now();
traj_controller_->update(now, now - previous_time);
previous_time = now;
}more generally I was not totally convinced if it is required to use a real clock for such loops. What we want for those update loop is to test steps and how the controller / hardware state updates, not really do it in real wall clock. There is only one place in the jtc code where a node clock is used to get the "now" for validating the trajectory msg otherwise I suppose it relies on external caller of update to pass the current time and dt. However, I suppose when using an integrated publisher and subscriber scheme in the test with the controller, for which they include wall clock timeouts (like wait_for_trajectory based on chrono) everything else might require to really loop in real wall time. Maybe in most other cases a loop to fake multiple update calls with faked time delta, just to get the simulated hardware to reach a certain state is sufficient and would be way faster than doing all tests with wall clock. |
you are completely right here, never asked myself about that.
Before this PR there was one clock call more inside the update loop, but I changed it to the time argument of the method. For the timeouts inside the update method we compare it with the time sent via the trajectory messages. If the time sources don't match, you get an c++ exception.
I think we could change that for most of the tests (being careful of the clock source of update+trajectory), but you'll get clear errors about that). Feel free to add a PR against jtc-features branch! |
|
I am working on it, I am currently testing my idea to see if one wins anytime |
|
It does not look good. Fixing the period computation is fine, but trying to fake the period (for instance 1 or 10 ms) and then call update as fast as possible with faking this time progression leads to tests segfaulting (not exceptions, crash due to access out of bounds of a string vector)
[EDIT] Well the segfault came from some Conclusion, we have to let time pass, with |
|
It is true to use |
|
Currently a set of tests rely on the state_msg to read final or intermediate states of the controller. They will fail if the state_msg does not go through properly after an too fast update. Maybe other means of looking at the state (rather than through a publisher) would be better, then one could discard clocks in those updateController. I will first provide a PR for the delta time. |
* Fix time sources and wrong checks in tests * Use time from update-method instead of node clock * Readd test of last command in test_goal_tolerances_fail --------- Co-authored-by: Bence Magyar <bence.magyar.robotics@gmail.com>
* Fix time sources and wrong checks in tests * Use time from update-method instead of node clock * Readd test of last command in test_goal_tolerances_fail --------- Co-authored-by: Bence Magyar <bence.magyar.robotics@gmail.com>
* Fix time sources and wrong checks in tests * Use time from update-method instead of node clock * Readd test of last command in test_goal_tolerances_fail --------- Co-authored-by: Bence Magyar <bence.magyar.robotics@gmail.com> (cherry picked from commit 7e13d1d) # Conflicts: # joint_trajectory_controller/test/test_trajectory_actions.cpp
* Fix time sources and wrong checks in tests * Use time from update-method instead of node clock * Readd test of last command in test_goal_tolerances_fail --------- Co-authored-by: Bence Magyar <bence.magyar.robotics@gmail.com> (cherry picked from commit 7e13d1d) # Conflicts: # joint_trajectory_controller/test/test_trajectory_actions.cpp
I found some weird time differences when running the tests:
So I tried
RCL_STEADY_TIMEfor all clocks and new failures popped up.JointTrajectoryController::update: Why would we use the node's clock instead of the time argument of the method?test_goal_tolerances_fail-> It won't hold the initial position but the last one from the goal.test_ignore_old_trajectory-> The new message isn't accepted, so the old message keeps being processed and it will reach its last point instead of the points from the discarded message.