Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow different namespaces for custom parameters #172

Merged
merged 4 commits into from
Apr 9, 2024

Conversation

amalnanavati
Copy link
Contributor

Description

This PR builds off of #146 by allowing multiple namespaces of parameter overrides. Specifically, custom parameters now work as follows:

  • default parameters are (still) read-only.
  • There is a parameter, custom_namespaces (list of strings) that defines custom namespaces.
  • Within each namespace, you can override any tree_kwarg from default, e.g., MoveToMouth.tree_kwargs.plan_distance_from_mouth. (Note: this PR removes the need to list our all overridden parameters; if a parameter has a value, it treats it as an override.)
  • There is a parameter namespace_to_use (default: ”default”) that specifies which namespace to use.
  • namespace_to_use and all tree_kwargs are the only re-writeable parameters. If namespace_to_use is set to a namespace that does not currently exist, it will create it and declare all tree_kwarg parameters within it.

Testing

  • Testing in isolation:
    • Launch the code: python3 src/ada_feeding/start.py --sim mock
    • Check that the feeding screen launched without error.
    • ros2 param list | grep tree_kwargs, verify that the only namespace for tree_kwargs is default
    • Add a new namespace, ros2 service call /ada_feeding_action_servers/set_parameters rcl_interfaces/srv/SetParameters "{parameters: [{name: 'namespace_to_use', value: {type: 4, string_value: 'test_namespace'}}]}"
    • ros2 param list | grep tree_kwargs, verify the new namespace is there
    • In the share directory (within the install folder of the workspace) open ada_feeding_action_servers_custom.yaml , verify custom_namespaces is now there with the value of the new namespace, and the namespace has no parameters.
    • Get the value of a parameter in the new namespace and verify it is unset: ros2 service call /ada_feeding_action_servers/get_parameters rcl_interfaces/srv/GetParameters "{names: ['test_namespace.MoveAbovePlate.tree_kwargs.f_mag']}"
    • Get the corresponding value in the default namespace and verify it is set: ros2 service call /ada_feeding_action_servers/get_parameters rcl_interfaces/srv/GetParameters "{names: ['default.MoveAbovePlate.tree_kwargs.f_mag']}"
    • Attempt to change the default parameter, and verify it fails: ros2 service call /ada_feeding_action_servers/set_parameters rcl_interfaces/srv/SetParameters "{parameters: [{name: 'default.MoveAbovePlate.tree_kwargs.f_mag', value: {type: 3, double_value: 1.0}}]}"
    • Attempt to change the test_namespace parameter to an incorrect type, and verify that it failes: e.g., ros2 service call /ada_feeding_action_servers/set_parameters rcl_interfaces/srv/SetParameters "{parameters: [{name: 'test_namespace.MoveAbovePlate.tree_kwargs.f_mag', value: {type: 4, string_value: 'ASDFGHJKL'}}]}"
      • Verify that in the share directory (within the install folder of the workspace), ada_feeding_action_servers_custom.yaml is unchanged.
    • Attempt to change the test_namespace parameter to a correct type, and verify that it works: e.g., ros2 service call /ada_feeding_action_servers/set_parameters rcl_interfaces/srv/SetParameters "{parameters: [{name: 'test_namespace.MoveAbovePlate.tree_kwargs.f_mag', value: {type: 3, double_value: 1.0}}]}"
      • Verify that in the share directory (within the install folder of the workspace), ada_feeding_action_servers_custom.yaml has changed to reflect the overridden parameter.
      • Verify that in the output of the node, you see some info logs indicating that the MoveAbovePlate tree was re-created.
    • Get the value of the param in default and verify that it is unchanged (should be 4.0): e.g., ros2 service call /ada_feeding_action_servers/get_parameters rcl_interfaces/srv/GetParameters "{names: ['default.MoveAbovePlate.tree_kwargs.f_mag']}"
    • Get the test_namespace value of the param and verify it is set correctly (should be 1.0): e.g., ros2 service call /ada_feeding_action_servers/get_parameters rcl_interfaces/srv/GetParameters "{names: ['test_namespace.MoveAbovePlate.tree_kwargs.f_mag']}"
    • Try to set a parameter in a non-existant namespace verify it failes, ros2 service call /ada_feeding_action_servers/set_parameters rcl_interfaces/srv/SetParameters "{parameters: [{name: 'test2_namespace.MoveAbovePlate.tree_kwargs.f_mag', value: {type: 3, double_value: 1.0}}]}"
    • Add a second namespace: ros2 service call /ada_feeding_action_servers/set_parameters rcl_interfaces/srv/SetParameters "{parameters: [{name: 'namespace_to_use', value: {type: 4, string_value: 'test2_namespace'}}]}", verify that the YAML file updates as expected
    • Change the parameter, ros2 service call /ada_feeding_action_servers/set_parameters rcl_interfaces/srv/SetParameters "{parameters: [{name: 'test2_namespace.MoveAbovePlate.tree_kwargs.f_mag', value: {type: 3, double_value: 1.0}}]}", verify it is updated correctly in the yaml file.
    • Change the namespace back to default, verify it works and the yaml file updates as expected, and that logs indicate that all trees were re-created: ros2 service call /ada_feeding_action_servers/set_parameters rcl_interfaces/srv/SetParameters "{parameters: [{name: 'namespace_to_use', value: {type: 4, string_value: 'default'}}]}",
  • Testing with MoveIt:
    • Remove workspace walls as necessary in RVIZ to be able to see the robot arm.
    • Set the distance to mouth in test_namespace to 5cm: ros2 service call /ada_feeding_action_servers/set_parameters rcl_interfaces/srv/SetParameters "{parameters: [{name: 'test_namespace.MoveToMouth.tree_kwargs.plan_distance_from_mouth', value: {type: 8, double_array_value: [0.05, 0.0, -0.01]}}]}"
    • Set the distance to mouth in test1_namespace to 10cm: ros2 service call /ada_feeding_action_servers/set_parameters rcl_interfaces/srv/SetParameters "{parameters: [{name: 'test2_namespace.MoveToMouth.tree_kwargs.plan_distance_from_mouth', value: {type: 8, double_array_value: [0.1, 0.0, -0.01]}}]}"
    • Do MoveToStaging: ros2 action send_goal /MoveToStagingConfiguration ada_feeding_msgs/action/MoveTo "{}" --feedback
    • Do MoveToMouth, verify it is 2.5cm from the mouth: ros2 action send_goal /MoveToMouth ada_feeding_msgs/action/MoveToMouth "{}" --feedback
    • Change the namespace to test_namespace: ros2 service call /ada_feeding_action_servers/set_parameters rcl_interfaces/srv/SetParameters "{parameters: [{name: 'namespace_to_use', value: {type: 4, string_value: 'test_namespace'}}]}"
    • Do MoveFromMouth: ros2 action send_goal /MoveFromMouth ada_feeding_msgs/action/MoveTo "{}" --feedback
    • Do MoveToMouth, verify it is 5cm from the mouth
    • Terminate and then re-launch ada_feeding code
    • Do MoveFromMouth followed by MoveToMouth, verify it is 5cm from the mouth
    • Change the namespace to test2_namespace: ros2 service call /ada_feeding_action_servers/set_parameters rcl_interfaces/srv/SetParameters "{parameters: [{name: 'namespace_to_use', value: {type: 4, string_value: 'test2_namespace'}}]}"
    • Do MoveFromMouth followed by MoveToMouth, verify it is 10cm from the mouth
    • Set the distance to mouth in test2_namespace to 20cm: ros2 service call /ada_feeding_action_servers/set_parameters rcl_interfaces/srv/SetParameters "{parameters: [{name: 'test2_namespace.MoveToMouth.tree_kwargs.plan_distance_from_mouth', value: {type: 8, double_array_value: [0.2, 0.0, -0.01]}}]}"
    • Do MoveFromMouth followed by MoveToMouth, verify it is 20cm from the mouth
    • Change the namespace back to default: ros2 service call /ada_feeding_action_servers/set_parameters rcl_interfaces/srv/SetParameters "{parameters: [{name: 'namespace_to_use', value: {type: 4, string_value: 'default'}}]}"
    • Do MoveFromMouth followed by MoveToMouth, verify it is 2.5cm from the mouth

Before opening a pull request

  • Format your code using black formatter python3 -m black .
  • Run your code through pylint and address all warnings/errors. The only warnings that are acceptable to not address is TODOs that should be addressed in a future PR. From the top-level ada_feeding directory, run: pylint --recursive=y --rcfile=.pylintrc ..

Before Merging

  • Squash & Merge

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.

1 participant