Repository navigation
Change servo parameters to use ros2 interfaces for parameters - #799
Conversation
Codecov Report
@@ Coverage Diff @@
## main #799 +/- ##
==========================================
+ Coverage 55.58% 55.74% +0.16%
==========================================
Files 198 200 +2
Lines 21420 21616 +196
==========================================
+ Hits 11904 12047 +143
- Misses 9516 9569 +53
Continue to review full report at Codecov.
|
9b01d52 to
a2ffde8
Compare
tylerjw
left a comment
There was a problem hiding this comment.
I left a few comments, let me know if you have questions.
|
In my first time testing this, it fails due to an undeclared parameter. It's nice that it failed and printed a useful error message but the error message could be formatted better: Can you please update this with a bit of a description of Or incorporate it all in one line. That would be even better.
|
AndyZe
left a comment
There was a problem hiding this comment.
@tylerjw and @stephanie-eng can you please add to the PR description -- why should we use parameter_descriptor_builder? I guess it has to do with setting parameters dynamically.
Without a better PR description, it kind of looks like 500 lines of code have been added without much change in functionality.
| ParameterDescriptorBuilder& description(std::string description); | ||
|
|
||
| /** | ||
| * @brief Set the additional constraints string |
There was a problem hiding this comment.
What the heck are additional constraints? Maybe it's a MoveIt2 thing I'm not familiar with. Could use a better description.
9e57b6e to
44b0362
Compare
This was due to me having a typo with some of the parameters. The parameter name causing this issue is hard-coded, so now that it's been corrected, is it still worth to have a specific error message? |
|
@AndyZe I'll respond to the parameter descriptor builder questions. Long term I hope to put something like this in a much more general place than in servo. It has to do with adding descriptions and types to the parameter declarations. ROS2 has this object (ParameterDescriptor) that it can take in the declare_parameter functions in order to provide a description and other details about the parameter that the ros2 system can use to help the user when interacting with the node. Unfortunately, because this object is a ROS2 message the code is much longer and uglier if you don't have the ParameterDescriptorBuilder here. An example of it in ROS2 is here: https://github.com/ros2/rclcpp/blob/1037822a63330495dcf0de5e8f20544375a5f116/rclcpp/include/rclcpp/detail/qos_parameters.hpp#L163 The ParameterDescriptorBuilder makes this much nicer when you have to create a bunch of these (because you have a bunch of parameters). One large advantage of doing this is a user will be able to run This is also needed to support dynamic reconfiguring in the future. As to the features of ParameterDescriptor, additional constraints as I understand it is a string where you can describe things like how the values set in that parameter affect other parameters. You might put something like "must be a valid ros topic name" or "only considered if is true" or something like that. Here is a ros answers question I asked about this a while ago that has a helpful response: https://answers.ros.org/question/378427/how-is-the-name-field-of-parameterdescriptor-used-by-declare_parameter/ |
No worries, I know this is still a draft. What I'm wondering is, can you somehow print the missing parameter name in the same line as the rest of the error message? In a general way, no matter what parameter it is. If not, it's not a huge deal. Like this:
|
There was a problem hiding this comment.
First off, I think this is a really good improvement as this approach provides much more consistency. I'd really appreciate if we could remove automatically_declare_parameters_from_overrides in all nodes. I don't have much to add to this PR as this is a step into the right direction.
However, I have plenty of feedback and questions that address the new helper API and this use case is a good opportunity to continue the design discussions we started half a year ago (again, this is not meant to block this PR, we should even get this merged imo):
- There still is way too much boilerplate code and unnecessary duplication, inviting for user errors and frustrating debugging sessions (overstated, but still this this should be a lot simpler and shorter)
- The descriptor constraints are somewhat useless if they don't provide the implementation for the
validatefunction,additional_constraintsare even more useless in this context - The application code is responsible for handling parameter callbacks while the config itself is not being updated
- Intermixed runtime dependencies on rclcpp, this doesn't seem to go well with mock tests
- No support for parameter namespaces, let alone group parameter constraints which are de facto implemented in the validate function.
I'd really like to move towards an API that meets all of these requirements. While I agree with @tylerjw that we shouldn't abstract completely from rclcpp, it's unlikely that rclcpp will provide these any time soon, unless we implement something that works for us first and try to bring it upstream. The goal should really be something that is just as easy to use as rosparam_shortcuts while allowing us to work on the actually challenging problems like:
- Support for config profiles and generic parameter types (=parameter groups)
- Synchronization of parameter groups (e.g. transforms, profiles, robot model etc)
- Validating, versioning and generating of (yaml) config files
With that, I think it makes sense to continue the discussion in #790, https://github.com/PickNikRobotics/parameter_tools, or even https://github.com/PickNikRobotics/ros2_params. I'll put in more time to rework some of the interfaces and make suggestions on how to simplify things without abstracting too much with a hard-to-maintain implementation.
Does this work with namespaces? That's an absolute must. We have a dual-arm robot project starting up right now. |
It does, but you have to stitch them together like |
| // POSSIBILITY OF SUCH DAMAGE. | ||
|
|
||
| /* Author : Tyler Weaver | ||
| Desc : Creates a parameter descriptor message used to describe parameters |
There was a problem hiding this comment.
@AndyZe here is the description of this. I will think of a nicer place to put this than in servo. I think having builders for some commonly used message types in moveit would be fine and so I can create a package for these.
tylerjw
left a comment
There was a problem hiding this comment.
A couple of small style things, but otherwise this looks really good. I'll test this later today to verify it doesn't change the behavior.
Have you tried running the tutorial after these changes?
I've been running the joystick and pose tracking examples from the launch folder as a sanity check. I don't have a joystick handy, so I can't move the arm for the teleop demo, but otherwise seems to work. |
| declareOrGetParam<std::string>(parameters->status_topic, ns + ".status_topic", node, logger); | ||
| // ROS Parameters | ||
| node_parameters->declare_parameter( | ||
| ns + ".use_gazebo", ParameterValue(parameters.use_gazebo), |
There was a problem hiding this comment.
I'm sorry to be nit-picky about this but we should use brace initialization by default.
| ns + ".use_gazebo", ParameterValue(parameters.use_gazebo), | |
| ns + ".use_gazebo", ParameterValue{parameters.use_gazebo}, |
| // ROS Parameters | ||
| node_parameters->declare_parameter( | ||
| ns + ".use_gazebo", ParameterValue(parameters.use_gazebo), | ||
| ParameterDescriptorBuilder() |
There was a problem hiding this comment.
| ParameterDescriptorBuilder() | |
| ParameterDescriptorBuilder{} |
| bool use_gazebo = false; | ||
| std::string status_topic = "~/status"; | ||
| // Properties of incoming commands | ||
| std::string cartesian_command_in_topic; | ||
| std::string joint_command_in_topic; | ||
| std::string robot_link_command_frame; | ||
| std::string command_in_type; | ||
| double linear_scale; | ||
| double rotational_scale; | ||
| double joint_scale; | ||
| std::string cartesian_command_in_topic = "~/delta_twist_cmds"; | ||
| std::string joint_command_in_topic = "~/delta_joint_cmds"; | ||
| std::string robot_link_command_frame = "panda_link0"; | ||
| std::string command_in_type = "unitless"; | ||
| double linear_scale = 0.4; | ||
| double rotational_scale = 0.8; | ||
| double joint_scale = 0.5; | ||
| // Properties of outgoing commands | ||
| std::string command_out_topic; | ||
| double publish_period; | ||
| std::string command_out_type; | ||
| bool publish_joint_positions; | ||
| bool publish_joint_velocities; | ||
| bool publish_joint_accelerations; | ||
| std::string command_out_topic = "/panda_arm_controller/joint_trajectory"; | ||
| double publish_period = 0.034; | ||
| std::string command_out_type = "trajectory_msgs/JointTrajectory"; | ||
| bool publish_joint_positions = true; | ||
| bool publish_joint_velocities = true; | ||
| bool publish_joint_accelerations = false; |
There was a problem hiding this comment.
Do you mind using uniform initialization for these too?
| set_parameter_callbacks_[name].push_back(callback); | ||
| if (callback_handler_) | ||
| { | ||
| const std::lock_guard<std::mutex> guard(callback_handler_->mutex_); |
There was a problem hiding this comment.
| const std::lock_guard<std::mutex> guard(callback_handler_->mutex_); | |
| const std::lock_guard<std::mutex> guard{callback_handler_->mutex_}; |
| ServoParameters ServoParameters::get(const std::string& ns, | ||
| const rclcpp::node_interfaces::NodeParametersInterface::SharedPtr& node_parameters) | ||
| { | ||
| auto parameters = ServoParameters(); |
There was a problem hiding this comment.
| auto parameters = ServoParameters(); | |
| auto parameters = ServoParameters{}; |
@stephanie-eng the tutorial has a way to test with a keyboard. (https://github.com/ros-planning/moveit2_tutorials/blob/main/doc/realtime_servo/realtime_servo_tutorial.rst) |
|
Thanks, Andy. |
tylerjw
left a comment
There was a problem hiding this comment.
Only a couple of tiny things I found. Otherwise this looks good. I tested this locally and it doesn't break anything as far as I can tell.
|
Just as an FYI: because this changes the function signature of makeServoParameters, a minor update to the tutorial is required for it to build. I've created a PR to make the tutorials build again for after this PR is merged. |
Thank you for doing that. :) |
|
moveit_ros/moveit_servo/include/moveit_servo/parameter_descriptor_builder.hpp could still use a description at the top of the file. Something like: |
b7fb634 to
b2b7419
Compare
b2b7419 to
c97745d
Compare
Description
Update servoParameters to use a new declare and get function that uses NodeParametersInterface to declare and get parameters. See #790
This PR does the following:
TODO:
Checklist