Repository navigation
Add command queue to servo to account for latency - #2594
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2594 +/- ##
==========================================
+ Coverage 50.31% 50.48% +0.18%
==========================================
Files 386 386
Lines 32151 32228 +77
==========================================
+ Hits 16172 16266 +94
+ Misses 15979 15962 -17 ☔ View full report in Codecov by Sentry. |
AndyZe
left a comment
There was a problem hiding this comment.
I think you could get rid of the complexity of the rolling window and simply always keep 2 waypoints in committed_commands_. I bet the majority of the performance gain comes from the latency parameter and the stop command point.
The latency parameter is identical to #886 but the stop command point is a good idea.
|
Adding that |
17ebf29 to
f75ea3b
Compare
The one problem I see with using the One option is to actually call
Another option is to not explicitly account for this case because the low-level controller will likely have a stopping mechanism. But I think it's safer to have it just in case. @AndyZe Do you have a suggestion to handle the edge case of extreme latency? |
|
I guess the halt point is fine. |
| // keep track of previously generated joint commands for constructing trajectory messages | ||
| std::deque<KinematicState> committed_commands_; |
There was a problem hiding this comment.
| // keep track of previously generated joint commands for constructing trajectory messages | |
| std::deque<KinematicState> committed_commands_; | |
| // rolling window of joint commands | |
| std::deque<KinematicState> joint_cmd_rolling_window_; |
There was a problem hiding this comment.
Not a fan of the "committed" terminology. I think people normally think of this as a rolling window.
There was a problem hiding this comment.
I changed all references of "committed" to "joint_cmd_rolling_window"
|
Between @sea-bass comments about making the change more functional, e.g. passing the rolling window in, and @AndyZe concerns about performance, I think it is best to factor out the command queueing logic and have the calling code maintain it. I'll move the logic into the |
|
Well, props for figuring out this long-standing issue! |
12f1039 to
797d8f5
Compare
Fix wording Co-authored-by: Sebastian Castro <[email protected]>
Co-authored-by: Sebastian Castro <[email protected]>
Co-authored-by: Sebastian Castro <[email protected]>
Signed-off-by: Paul Gesel <[email protected]>
|
True. Well, it's an optional plugin. Hopefully Ruckig will come along and solve all of our issues. Happy to help make that happen |
e72cdb9 to
0544301
Compare
…ce the time stamp is set in the updateSlidingWindow function now. Signed-off-by: Paul Gesel <[email protected]>
0544301 to
72d4f92
Compare
Signed-off-by: Paul Gesel <[email protected]>
459a5b0 to
37e590f
Compare
@AndyZe Okay great. I removed the acceleration-based limits from this PR. I will follow up with an |
Signed-off-by: Paul Gesel <[email protected]>
a596a0d to
3aace07
Compare
…s current state if no command generated 4) fix smooth hault: stop command was not generated if smoothing disabled 5) call resetSmoothing when there are no commands Signed-off-by: Paul Gesel <[email protected]>
3aace07 to
1acf7e4
Compare
|
@pac48 Can you address the conflicts? Then we should merge this, nice work! |
|
This pull request is in conflict. Could you fix it @pac48? |
I just addressed them, they were simple and from my recent PR, so let's do this! |
* add command queue to servo to account for latency * run pre-commit * fix unsigned compare * Update moveit_ros/moveit_servo/config/servo_parameters.yaml Fix wording Co-authored-by: Sebastian Castro <[email protected]> * Update moveit_ros/moveit_servo/src/servo.cpp Co-authored-by: Sebastian Castro <[email protected]> * Update moveit_ros/moveit_servo/src/servo.cpp Co-authored-by: Sebastian Castro <[email protected]> * add comments and change variable names * add checks to determine what state information should be published Signed-off-by: Paul Gesel <[email protected]> * change latency parameter name Signed-off-by: Paul Gesel <[email protected]> * factor command queue out of servo instance Signed-off-by: Paul Gesel <[email protected]> * update demos Signed-off-by: Paul Gesel <[email protected]> * needs clean up but working well * deal with duplicate timestamps for sim * add acceleration limiting smoothing * add timeout check in filter Signed-off-by: Paul Gesel <[email protected]> * factor out robot state from servo call Signed-off-by: Paul Gesel <[email protected]> * update comments in smoothing pluin Signed-off-by: Paul Gesel <[email protected]> * fix tests Signed-off-by: Paul Gesel <[email protected]> * change velocity calculation to make interpolation not overshoot Signed-off-by: Paul Gesel <[email protected]> * Update moveit_ros/moveit_servo/config/panda_simulated_config.yaml Co-authored-by: Sebastian Castro <[email protected]> * Update moveit_ros/moveit_servo/config/servo_parameters.yaml Co-authored-by: Sebastian Castro <[email protected]> * Update moveit_ros/moveit_servo/demos/cpp_interface/demo_joint_jog.cpp Co-authored-by: Sebastian Castro <[email protected]> * fix time calculation Signed-off-by: Paul Gesel <[email protected]> * add check to ensure time interval is positive Signed-off-by: Paul Gesel <[email protected]> * simplify demos Signed-off-by: Paul Gesel <[email protected]> * wait for first robot state before starting servo loop Signed-off-by: Paul Gesel <[email protected]> * add comments to acceleration filter Signed-off-by: Paul Gesel <[email protected]> * fix wait time units * fix logic bug in smoothHalt and remove stopping point from trajectory message. Still some overshoot. Signed-off-by: Paul Gesel <[email protected]> * add acceleration limit to servo Signed-off-by: Paul Gesel <[email protected]> * remove acceleration filter Signed-off-by: Paul Gesel <[email protected]> * remove other filter files from moveit_core Signed-off-by: Paul Gesel <[email protected]> * add doc string and basic clean up * refactor getRobotState to utils and add a test Signed-off-by: Paul Gesel <[email protected]> * make some things const and fix comments Signed-off-by: Paul Gesel <[email protected]> * use joint_limts params to get robot acceleration limits Signed-off-by: Paul Gesel <[email protected]> * update demo config and set velocities in demos Signed-off-by: Paul Gesel <[email protected]> * fix acceleration calculation Signed-off-by: Paul Gesel <[email protected]> * apply collision_velocity_scale_ in smooth hault, add comments, and rename variables Signed-off-by: Paul Gesel <[email protected]> * use bounds on scaling factors in [0... 1] Signed-off-by: Paul Gesel <[email protected]> * remove joint_acceleration parameter Signed-off-by: Paul Gesel <[email protected]> * add test for jointLimitAccelerationScaling Signed-off-by: Paul Gesel <[email protected]> * refactor velocity and acceleration scaling into common function Signed-off-by: Paul Gesel <[email protected]> * general clean up, add comments, fix parameters, set timestamp in updateSlidingWindow, etc. Signed-off-by: Paul Gesel <[email protected]> * Update moveit_ros/moveit_servo/config/panda_simulated_config.yaml Co-authored-by: AndyZe <[email protected]> * Update moveit_ros/moveit_servo/src/servo.cpp Co-authored-by: AndyZe <[email protected]> * remove override_acceleration_scaling_factor Signed-off-by: Paul Gesel <[email protected]> * fix variable name Signed-off-by: Paul Gesel <[email protected]> * enable use_smoothing in demos Signed-off-by: Paul Gesel <[email protected]> * Update moveit_ros/moveit_servo/config/panda_simulated_config.yaml Co-authored-by: AndyZe <[email protected]> * add current state to command queue if it is empty. This is needed since the time stamp is set in the updateSlidingWindow function now. Signed-off-by: Paul Gesel <[email protected]> * remove acceleration smoothing Signed-off-by: Paul Gesel <[email protected]> * revert jointLimitVelocityScalingFactor refactor Signed-off-by: Paul Gesel <[email protected]> * 1) fix spelling 2) add comments 3) make sure rolling_window always has current state if no command generated 4) fix smooth hault: stop command was not generated if smoothing disabled 5) call resetSmoothing when there are no commands Signed-off-by: Paul Gesel <[email protected]> --------- Signed-off-by: Paul Gesel <[email protected]> Co-authored-by: Sebastian Castro <[email protected]> Co-authored-by: AndyZe <[email protected]>
* add command queue to servo to account for latency * run pre-commit * fix unsigned compare * Update moveit_ros/moveit_servo/config/servo_parameters.yaml Fix wording Co-authored-by: Sebastian Castro <[email protected]> * Update moveit_ros/moveit_servo/src/servo.cpp Co-authored-by: Sebastian Castro <[email protected]> * Update moveit_ros/moveit_servo/src/servo.cpp Co-authored-by: Sebastian Castro <[email protected]> * add comments and change variable names * add checks to determine what state information should be published Signed-off-by: Paul Gesel <[email protected]> * change latency parameter name Signed-off-by: Paul Gesel <[email protected]> * factor command queue out of servo instance Signed-off-by: Paul Gesel <[email protected]> * update demos Signed-off-by: Paul Gesel <[email protected]> * needs clean up but working well * deal with duplicate timestamps for sim * add acceleration limiting smoothing * add timeout check in filter Signed-off-by: Paul Gesel <[email protected]> * factor out robot state from servo call Signed-off-by: Paul Gesel <[email protected]> * update comments in smoothing pluin Signed-off-by: Paul Gesel <[email protected]> * fix tests Signed-off-by: Paul Gesel <[email protected]> * change velocity calculation to make interpolation not overshoot Signed-off-by: Paul Gesel <[email protected]> * Update moveit_ros/moveit_servo/config/panda_simulated_config.yaml Co-authored-by: Sebastian Castro <[email protected]> * Update moveit_ros/moveit_servo/config/servo_parameters.yaml Co-authored-by: Sebastian Castro <[email protected]> * Update moveit_ros/moveit_servo/demos/cpp_interface/demo_joint_jog.cpp Co-authored-by: Sebastian Castro <[email protected]> * fix time calculation Signed-off-by: Paul Gesel <[email protected]> * add check to ensure time interval is positive Signed-off-by: Paul Gesel <[email protected]> * simplify demos Signed-off-by: Paul Gesel <[email protected]> * wait for first robot state before starting servo loop Signed-off-by: Paul Gesel <[email protected]> * add comments to acceleration filter Signed-off-by: Paul Gesel <[email protected]> * fix wait time units * fix logic bug in smoothHalt and remove stopping point from trajectory message. Still some overshoot. Signed-off-by: Paul Gesel <[email protected]> * add acceleration limit to servo Signed-off-by: Paul Gesel <[email protected]> * remove acceleration filter Signed-off-by: Paul Gesel <[email protected]> * remove other filter files from moveit_core Signed-off-by: Paul Gesel <[email protected]> * add doc string and basic clean up * refactor getRobotState to utils and add a test Signed-off-by: Paul Gesel <[email protected]> * make some things const and fix comments Signed-off-by: Paul Gesel <[email protected]> * use joint_limts params to get robot acceleration limits Signed-off-by: Paul Gesel <[email protected]> * update demo config and set velocities in demos Signed-off-by: Paul Gesel <[email protected]> * fix acceleration calculation Signed-off-by: Paul Gesel <[email protected]> * apply collision_velocity_scale_ in smooth hault, add comments, and rename variables Signed-off-by: Paul Gesel <[email protected]> * use bounds on scaling factors in [0... 1] Signed-off-by: Paul Gesel <[email protected]> * remove joint_acceleration parameter Signed-off-by: Paul Gesel <[email protected]> * add test for jointLimitAccelerationScaling Signed-off-by: Paul Gesel <[email protected]> * refactor velocity and acceleration scaling into common function Signed-off-by: Paul Gesel <[email protected]> * general clean up, add comments, fix parameters, set timestamp in updateSlidingWindow, etc. Signed-off-by: Paul Gesel <[email protected]> * Update moveit_ros/moveit_servo/config/panda_simulated_config.yaml Co-authored-by: AndyZe <[email protected]> * Update moveit_ros/moveit_servo/src/servo.cpp Co-authored-by: AndyZe <[email protected]> * remove override_acceleration_scaling_factor Signed-off-by: Paul Gesel <[email protected]> * fix variable name Signed-off-by: Paul Gesel <[email protected]> * enable use_smoothing in demos Signed-off-by: Paul Gesel <[email protected]> * Update moveit_ros/moveit_servo/config/panda_simulated_config.yaml Co-authored-by: AndyZe <[email protected]> * add current state to command queue if it is empty. This is needed since the time stamp is set in the updateSlidingWindow function now. Signed-off-by: Paul Gesel <[email protected]> * remove acceleration smoothing Signed-off-by: Paul Gesel <[email protected]> * revert jointLimitVelocityScalingFactor refactor Signed-off-by: Paul Gesel <[email protected]> * 1) fix spelling 2) add comments 3) make sure rolling_window always has current state if no command generated 4) fix smooth hault: stop command was not generated if smoothing disabled 5) call resetSmoothing when there are no commands Signed-off-by: Paul Gesel <[email protected]> --------- Signed-off-by: Paul Gesel <[email protected]> Co-authored-by: Sebastian Castro <[email protected]> Co-authored-by: AndyZe <[email protected]>

There is an issue where some robots experience non-smooth and noisy servo performance #2275. Currently, servo sends trajectory messages to the ros2_control JTC one waypoint at a time. However, This causes issues because when the JTC receives a new message, it replaces the old one entirely. My proposal to solve this issue is to send more than one waypoint at a time and make sure everything is time-synchronized. Below is an example diagram.
When messages are sent from servo to the JTC, there is an inherent noisy delay that should be accounted for. One strategy is to use a buffer that contains all generated servo commands from the current time to the current time plus the maximum expected latency. This range is shown in red. Any commands that are put in the buffer are considered "committed", meaning they will be executed by the JTC. For any time after the red region, there is still an opportunity to change commands. This is illustrated with the green trajectory.
I recorded and plotted the commands received by the JTC with the current servo implementation (left) vs. this PR (right) using the 'demo_pose.cpp' example in the servo package.