Allow updating robot gravity#1606
Conversation
urfeex
left a comment
There was a problem hiding this comment.
This all seems fair and well implemented. ros-industrial/ur_msgs#39 (comment) might influence this PR, however.
6391efc to
b24dc5c
Compare
urfeex
left a comment
There was a problem hiding this comment.
I might have found the source of "fishyness". For all data processed by the control box, base is the correct one, not base_link.
On another topic: We would like to split up the gpio controller in the future, as it kind of became the dump place for all robot-specific functionalities. Would you mind moving this to a separate controller?
Ah yes, thanks! Specifically, the urcl call is expecting the "up" (away from Earth) vector in the Unfortunately, this confusion existed in the URCL merge too, just in the comments here. I can go update that if you want, or you can probably just drop that specific commit |
I can give this a shot. Do you mean a gravity-specific controller, or moving some of the e.g. |
Oh, yes! I missed that while reviewing. If you could update that, that would be great, then I can review it.
I've been thinking about this as well last evening. I think, there are arguments for both, one UR-specific functionality controller and one controller per functionality. Name wise, what would you think of "gravity update controller"? |
|
I'll split it off into a "gravity update controller". I don't know what you will do in the future, but exposing that and others (eg It sounds like I will leave the gravity direction as is for now? The urscript docs for both the |
|
Yes, I can understand that. That's why I think, we should add a more consecutive example to the controller's documentation. If you want, I can contribute that. And yes, I think we can leave the vector as it is now.
However, as I said, I think the scope of this PR is very well established and we can focus on that. |
|
@AdamPettinger just to be sure: I'm currently waiting for you to finish splitting this into its own controller. Or are you waiting for any input from the maintainers? |
Ah sorry, I have had a busy few weeks, I will get to this soon! Not waiting on other input |
Signed-off-by: AdamPettinger <adam.l.pettinger@gmail.com>
Signed-off-by: AdamPettinger <adam.l.pettinger@gmail.com>
Signed-off-by: AdamPettinger <adam.l.pettinger@gmail.com>
Signed-off-by: AdamPettinger <adam.l.pettinger@gmail.com>
…uest Signed-off-by: AdamPettinger <adam.l.pettinger@gmail.com>
Signed-off-by: AdamPettinger <adam.l.pettinger@gmail.com>
Signed-off-by: AdamPettinger <adam.l.pettinger@gmail.com>
Signed-off-by: AdamPettinger <adam.l.pettinger@gmail.com>
Signed-off-by: AdamPettinger <adam.l.pettinger@gmail.com>
Signed-off-by: AdamPettinger <adam.l.pettinger@gmail.com>
Signed-off-by: AdamPettinger <adam.l.pettinger@gmail.com>
Signed-off-by: AdamPettinger <adam.l.pettinger@gmail.com>
232626e to
bb8bdc5
Compare
|
Ok, broke it out into its own controller and tested with our hardware. This doesn't touch the GPIO controller at all now. I did go ahead and add the |
Signed-off-by: AdamPettinger <adam.l.pettinger@gmail.com>
Signed-off-by: AdamPettinger <adam.l.pettinger@gmail.com>
urfeex
left a comment
There was a problem hiding this comment.
This is looking good now, thanks for iterating.
I'll need some time to test this and I'll merge the service first.
|
Tested and verified using a robot. |
| resp->status = "Gravity has been set successfully"; | ||
| } else { | ||
| resp->status = "Could not set the gravity"; | ||
| } |
There was a problem hiding this comment.
Timeout reports gravity set success
High Severity
When waitForAsyncCommand times out while the async status is still ASYNC_WAITING (2.0), setGravity sets resp->success via static_cast<bool>(success.value()). In C++, any non-zero double is true, so a pending or unverified update can return success and the “Gravity has been set successfully” status.
Reviewed by Cursor Bugbot for commit dd00fb0. Configure here.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
Reviewed by Cursor Bugbot for commit 406f2cb. Configure here.
|
|
||
| // Reset gravity vector, so we only change it on the service call | ||
| cmd_gravity_box_.set(std::nullopt); | ||
| } |
There was a problem hiding this comment.
Pending gravity command cleared
High Severity
In update, after reading a gravity vector from cmd_gravity_box_, the code always writes std::nullopt back. If another set_gravity request stores a new vector between that read and the clear, that pending command is dropped and never sent to the hardware.
Reviewed by Cursor Bugbot for commit 406f2cb. Configure here.
In ROS 2 service callbacks are usually void.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1606 +/- ##
========================================
+ Coverage 3.59% 4.73% +1.14%
========================================
Files 13 35 +22
Lines 947 4495 +3548
Branches 152 530 +378
========================================
+ Hits 34 213 +179
- Misses 843 4277 +3434
+ Partials 70 5 -65
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|


I have a UR20 mounted on another robot that can change its orientation enough to cause problems for the arm's mounting installation.
There has been some discussion on how to update the mounting orientation/gravity live (here and here), but these did not end up happening.
These changes expose the
set_gravityURScript functionality through the ROS driver, allowing a user to update the gravity vector of the robot during live operation via a service. This is obviously risky if you calculate the gravity vector incorrectly.There are corresponding changes in
I just rebased these commits on
maintoday, although we have been running these changes forked from thejazzybranch for a few months now.Note
High Risk
Incorrect gravity vectors directly affect the controller’s dynamic model and can cause unsafe motion or falls; the feature is enabled by default on launch.
Overview
Adds live gravity / mounting orientation updates for UR arms by wiring URScript
set_gravitythrough ros2_control, aimed at mobile or reorienting bases where the arm’s assumed gravity must change during operation.A new
GravityUpdateControllerexposes~/set_gravity(ur_msgs/srv/SetGravity). The service accepts a gravity direction in an arbitrary TF frame, negates it to match the client library’s anti-gravity convention, rotates it into the robot base frame, and pushes it to hardware via a thread-safe box. The realtimeupdate()loop writes x/y/z andgravity_async_successcommand interfaces and polls completion (same async pattern as payload/friction GPIO controllers).The hardware interface gains a
gravityGPIO in URDF/xacro, exports matching command interfaces, resets commands ininitAsyncIO, and incheckAsyncIOcallsur_driver_->setGravity()when a new vector is present.Launch and config register the plugin, add controller-manager entries, spawn
gravity_update_controlleractive with other always-on controllers, and include it inconsistent_controllersfor the controller stopper.Reviewed by Cursor Bugbot for commit 366559d. Bugbot is set up for automated code reviews on this repo. Configure here.