Skip to content

Change servo parameters to use ros2 interfaces for parameters - #799

Merged
tylerjw merged 2 commits into
moveit:mainfrom
stephanie-eng:servo-param-update
Nov 23, 2021
Merged

tylerjw merged 2 commits into
moveit:mainfrom
stephanie-eng:servo-param-update

Conversation

@stephanie-eng

@stephanie-eng stephanie-eng commented Nov 12, 2021 •

Copy link
Copy Markdown
Contributor

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:

  • Sets default values for servo parameters based off of panda_simulated_config.yaml
  • Replaces the getOrDeclareParam function with individual get and set functions
    • These
  • Adds parameter_descriptor_builder, which is used to create the messages used in setting up the descriptions for parameters

TODO:

  • When running the joystick servo example, declare will throw an error saying that the parameters are already declared. Not sure why this is happening yet, still working on this.
  • Build error with the set parameters callback

Checklist

@codecov

codecov Bot commented Nov 12, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #799 (9edaa22) into main (2d0dfd8) will increase coverage by 0.16%.
The diff coverage is 75.17%.

❗ Current head 9edaa22 differs from pull request most recent head c97745d. Consider uploading reports for the commit c97745d to get more accurate results
Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
moveit_ros/moveit_servo/src/servo_node_main.cpp 100.00% <ø> (ø)
.../moveit_servo/src/parameter_descriptor_builder.cpp 22.23% <22.23%> (ø)
moveit_ros/moveit_servo/src/pose_tracking.cpp 77.00% <60.00%> (-0.89%) ⬇️
moveit_ros/moveit_servo/src/servo_calcs.cpp 67.65% <80.00%> (-1.21%) ⬇️
moveit_ros/moveit_servo/src/servo_parameters.cpp 79.85% <80.33%> (+9.75%) ⬆️
...lude/moveit_servo/parameter_descriptor_builder.hpp 100.00% <100.00%> (ø)
...veit_servo/include/moveit_servo/servo_parameters.h 100.00% <100.00%> (+25.00%) ⬆️
moveit_ros/moveit_servo/src/servo_node.cpp 69.39% <100.00%> (ø)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2d0dfd8...c97745d. Read the comment docs.

@stephanie-eng
stephanie-eng force-pushed the servo-param-update branch 2 times, most recently from 9b01d52 to a2ffde8 Compare November 15, 2021 23:52

@tylerjw tylerjw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments, let me know if you have questions.

@AndyZe

AndyZe commented Nov 17, 2021 •

Copy link
Copy Markdown
Member

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:

[servo_node_main-3] terminate called after throwing an instance of 'rclcpp::exceptions::ParameterNotDeclaredException'
[servo_node_main-3]   what():  moveit_servocommand_out_topic

Can you please update this with a bit of a description of moveit_servocommand_out_topic? Otherwise it is easy to miss.

[servo_node_main-3] terminate called after throwing an instance of 'rclcpp::exceptions::ParameterNotDeclaredException'
[servo_node_main-3]   Parameter name:  moveit_servocommand_out_topic

Or incorporate it all in one line. That would be even better.

[servo_node_main-3] terminate called after throwing an instance of 'rclcpp::exceptions::ParameterNotDeclaredException'. Parameter name: moveit_servocommand_out_topic

@AndyZe AndyZe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the heck are additional constraints? Maybe it's a MoveIt2 thing I'm not familiar with. Could use a better description.

@stephanie-eng
stephanie-eng force-pushed the servo-param-update branch 3 times, most recently from 9e57b6e to 44b0362 Compare November 17, 2021 21:49
@stephanie-eng

Copy link
Copy Markdown
Contributor Author

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:

[servo_node_main-3] terminate called after throwing an instance of 'rclcpp::exceptions::ParameterNotDeclaredException'
[servo_node_main-3]   what():  moveit_servocommand_out_topic

Can you please update this with a bit of a description of moveit_servocommand_out_topic? Otherwise it is easy to miss.

[servo_node_main-3] terminate called after throwing an instance of 'rclcpp::exceptions::ParameterNotDeclaredException'
[servo_node_main-3]   Parameter name:  moveit_servocommand_out_topic

Or incorporate it all in one line. That would be even better.

[servo_node_main-3] terminate called after throwing an instance of 'rclcpp::exceptions::ParameterNotDeclaredException'. Parameter name: moveit_servocommand_out_topic

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?

@stephanie-eng stephanie-eng changed the title Added parameter_descriptor_builder and first pass at creating get and… Change servo parameters to use ros2 interfaces for parameters Nov 17, 2021
@tylerjw

tylerjw commented Nov 17, 2021 •

Copy link
Copy Markdown
Member

@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 ros2 param dump <servo_node_name> and it will output a yaml file of the parameters. Another thing you can run is ros2 param list <servo_node_name> and it will output a list of the parameters and their descriptions.

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/

@AndyZe

AndyZe commented Nov 18, 2021

Copy link
Copy Markdown
Member

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?

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:

[servo_node_main-3] terminate called after throwing an instance of 'rclcpp::exceptions::ParameterNotDeclaredException'. Parameter name: whatever_my_parameter_name_is

@henningkayser henningkayser left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 validate function, additional_constraints are 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.

@AndyZe

AndyZe commented Nov 18, 2021

Copy link
Copy Markdown
Member
* No support for parameter namespaces

Does this work with namespaces? That's an absolute must. We have a dual-arm robot project starting up right now.

@henningkayser

Copy link
Copy Markdown
Member
* No support for parameter namespaces

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 ns + ".parameter"

// POSSIBILITY OF SUCH DAMAGE.

/* Author : Tyler Weaver
Desc : Creates a parameter descriptor message used to describe parameters

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@stephanie-eng
stephanie-eng marked this pull request as ready for review November 18, 2021 19:00

@tylerjw tylerjw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@stephanie-eng

stephanie-eng commented Nov 19, 2021 •

Copy link
Copy Markdown
Contributor Author

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),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry to be nit-picky about this but we should use brace initialization by default.

Suggested change
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()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ParameterDescriptorBuilder()
ParameterDescriptorBuilder{}

Comment on lines +63 to +79
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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto parameters = ServoParameters();
auto parameters = ServoParameters{};

@AndyZe

AndyZe commented Nov 19, 2021 •

Copy link
Copy Markdown
Member

I don't have a joystick handy

@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)

ros2 launch moveit_servo servo_example.launch.py
ros2 service call /servo_node/start_servo std_srvs/srv/Trigger {}
ros2 run moveit2_tutorials servo_keyboard_input

@stephanie-eng

Copy link
Copy Markdown
Contributor Author

Thanks, Andy.
I've incorporated Tyler's suggestions and was able to run the demo without problem.

@tylerjw tylerjw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@stephanie-eng

Copy link
Copy Markdown
Contributor Author

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.

@tylerjw

tylerjw commented Nov 22, 2021

Copy link
Copy Markdown
Member

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. :)

@AndyZe

AndyZe commented Nov 23, 2021 •

Copy link
Copy Markdown
Member

moveit_ros/moveit_servo/include/moveit_servo/parameter_descriptor_builder.hpp could still use a description at the top of the file. Something like:

//  ...
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

/* Author: Stephanie Eng
   Description: blah blah blah
 */

@tylerjw
tylerjw merged commit 98efff4 into moveit:main Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants