Hi everyone
I would like to know if it is possible to get bt_navigator params values from a python node.
Thanks in advance
I’ve check it is possible to develop a cliente for the getParameters service. I don’t know if there is a better way.
Thanks again!
Hi @lfernandez ,
Have you tried ros2 param list
?
user:~$ ros2 param list
/amcl:
[removed for brevity]
/amcl_rclcpp_node:
use_sim_time
# -------------------------------------------------- #
/bt_navigator: # <--- Check here <--- #
default_bt_xml_filename #
enable_groot_monitoring #
global_frame #
groot_zmq_publisher_port #
groot_zmq_server_port #
odom_topic #
plugin_lib_names #
robot_base_frame #
transform_tolerance #
use_sim_time #
# -------------------------------------------------- #
Exception while calling service of node '/bt_navigator_rclcpp_node': None
/controller_server:
[removed for brevity]
/controller_server_rclcpp_node:
use_sim_time
/global_costmap/global_costmap:
[removed for brevity]
Exception while calling service of node '/global_costmap_client': None
/global_costmap/global_costmap_rclcpp_node:
use_sim_time
/lifecycle_manager_localization:
[removed for brevity]
Exception while calling service of node '/lifecycle_manager_localization_service_client': None
/lifecycle_manager_pathplanning:
[removed for brevity]
Exception while calling service of node '/lifecycle_manager_pathplanning_service_client': None
/local_costmap/local_costmap:
[removed for brevity]
Exception while calling service of node '/local_costmap_client': None
/local_costmap/local_costmap_rclcpp_node:
use_sim_time
/map_server:
[removed for brevity]
/planner_server:
[removed for brevity]
/planner_server_rclcpp_node:
use_sim_time
/recoveries_server:
[removed for brevity]
/recoveries_server_rclcpp_node:
use_sim_time
/ros_bridge:
use_sim_time
/rviz:
use_sim_time
user:~$
And to get a value of a parameter you can try:
user:~$ ros2 param get /bt_navigator # <--- press TAB twice here
--hide-type groot_zmq_publisher_port
--include-hidden-nodes groot_zmq_server_port
--no-daemon odom_topic
--spin-time plugin_lib_names
default_bt_xml_filename robot_base_frame
enable_groot_monitoring transform_tolerance
global_frame use_sim_time
user:~$ ros2 param get /bt_navigator global_frame
String value is: map
user:~$
Presently I am not sure how to get all the values of all the parameters at once.
Hope this helps.
Regards,
Girish
Hi @lfernandez ,
I think you are looking for something like this?: rclpy Params Tutorial - Get and Set ROS2 Params with Python - The Robotics Back-End
Hope this helped.
Regards,
Girish
Thanks @girishkumar.kannan but I need to access the parameters from another node.
I think I have to use the get_parameters service How to get ROS2 parameter hosted by another Node - ROS Answers: Open Source Q&A Forum
Hi @lfernandez ,
After doing some research with the terminal and documentation, I have the following results for you.
ros2 param list
gives you a list of all parameters associated with all the nodes that are currently active in ROS2.
ros2 param list /bt_navigator/
gives you a list of all parameters associated with the /bt_navigator
node. Note the /
at the end of /bt_navigator
. If you miss the /
you will also get results for the rclcpp_node
of /bt_navigator
.
Here is the output:
user:~$ ros2 param list /bt_navigator
default_bt_xml_filename
enable_groot_monitoring
global_frame
groot_zmq_publisher_port
groot_zmq_server_port
odom_topic
plugin_lib_names
robot_base_frame
transform_tolerance
use_sim_time
You can do the above same command with the service that is provided by the node, which in your case is /bt_navigator/
.
ros2 service list
would give you the following result.
user:~$ ros2 service list
. [previous entries removed for brevity]
/bt_navigator/change_state
/bt_navigator/describe_parameters
/bt_navigator/get_available_states
/bt_navigator/get_available_transitions
/bt_navigator/get_parameter_types
/bt_navigator/get_parameters
/bt_navigator/get_state
/bt_navigator/get_transition_graph
/bt_navigator/list_parameters
/bt_navigator/set_parameters
/bt_navigator/set_parameters_atomically
/bt_navigator_rclcpp_node/describe_parameters
/bt_navigator_rclcpp_node/get_parameter_types
/bt_navigator_rclcpp_node/get_parameters
/bt_navigator_rclcpp_node/list_parameters
/bt_navigator_rclcpp_node/set_parameters
/bt_navigator_rclcpp_node/set_parameters_atomically
. [later entries removed for brevity]
Now you can use the /bt_navigator/list_parameters
to get all the parameters associated with /bt_navigator/
.
Here is the output:
ros2 service call /bt_navigator/list_parameters rcl_interfaces/srv/ListParameters "{prefixes: [], depth: 0}"
requester: making request: rcl_interfaces.srv.ListParameters_Request(prefixes=[], depth=0)
response:
rcl_interfaces.srv.ListParameters_Response(result=rcl_interfaces.msg.ListParametersResult(names=['default_bt_xml_filename', 'enable_groot_monitoring', 'global_frame', 'groot_zmq_publisher_port', 'groot_zmq_server_port', 'odom_topic', 'plugin_lib_names', 'robot_base_frame', 'transform_tolerance', 'use_sim_time'], prefixes=[]))
Note 1: You must set prefixes as empty list and depth as 0 to get all the parameters.
Note 2: Comparing this with ros2 param list /bt_navigator/
, they are the same. The services method is much faster than doing ros2 param list /bt_navigator/
.
Refer: About parameters in ROS 2 — ROS 2 Documentation: Rolling documentation
Once you have obtained the list of all parameters, you can use the get_parameters
and/or set_parameters
to access or modify the values from another Python or C++ node.
To access one parameter:
user:~$ ros2 service call /bt_navigator/get_parameters rcl_interfaces/srv/GetParameters "{names: ["transform_tolerance"]}"
requester: making request: rcl_interfaces.srv.GetParameters_Request(names=['transform_tolerance'])
response:
rcl_interfaces.srv.GetParameters_Response(values=[rcl_interfaces.msg.ParameterValue(type=3, bool_value=False, integer_value=0, double_value=0.1, string_value='', byte_array_value=[], bool_array_value=[],integer_array_value=[], double_array_value=[], string_array_value=[])])
To access multiple parameters (just pass all the parameter names as list into the names
):
user:~$ ros2 service call /bt_navigator/get_parameters rcl_interfaces/srv/GetParameters "{names: ['default_bt_xml_filename', 'enable_groot_monitoring', 'global_frame', 'groot_zmq_publisher_port', 'groot_zmq_server_port', 'odom_topic', 'plugin_lib_names', 'robot_base_frame', 'transform_tolerance', 'use_sim_time']}"
requester: making request: rcl_interfaces.srv.GetParameters_Request(names=['default_bt_xml_filename', 'enable_groot_monitoring', 'global_frame', 'groot_zmq_publisher_port', 'groot_zmq_server_port', 'odom_topic', 'plugin_lib_names', 'robot_base_frame', 'transform_tolerance', 'use_sim_time'])
response:
rcl_interfaces.srv.GetParameters_Response(values=[rcl_interfaces.msg.ParameterValue(type=4, bool_value=False, integer_value=0, double_value=0.0, string_value='/home/user/ros2_ws/src/my_turtlebot_pathplanning/config/behavior.xml', byte_array_value=[], bool_array_value=[],integer_array_value=[], double_array_value=[], string_array_value=[]), rcl_interfaces.msg.ParameterValue(type=1, bool_value=True, integer_value=0, double_value=0.0, string_value='', byte_array_value=[], bool_array_value=[], integer_array_value=[], double_array_value=[], string_array_value=[]), rcl_interfaces.msg.ParameterValue(type=4, bool_value=False, integer_value=0, double_value=0.0, string_value='map', byte_array_value=[], bool_array_value=[], integer_array_value=[],double_array_value=[], string_array_value=[]), rcl_interfaces.msg.ParameterValue(type=2, bool_value=False, integer_value=1666, double_value=0.0, string_value='', byte_array_value=[], bool_array_value=[],integer_array_value=[], double_array_value=[], string_array_value=[]), rcl_interfaces.msg.ParameterValue(type=2, bool_value=False, integer_value=1667, double_value=0.0, string_value='', byte_array_value=[], bool_array_value=[], integer_array_value=[], double_array_value=[], string_array_value=[]), rcl_interfaces.msg.ParameterValue(type=4, bool_value=False, integer_value=0, double_value=0.0, string_value='/odom', byte_array_value=[], bool_array_value=[], integer_array_value=[], double_array_value=[], string_array_value=[]), rcl_interfaces.msg.ParameterValue(type=9, bool_value=False, integer_value=0, double_value=0.0, string_value='', byte_array_value=[], bool_array_value=[], integer_array_value=[], double_array_value=[], string_array_value=['nav2_compute_path_to_pose_action_bt_node', 'nav2_follow_path_action_bt_node', 'nav2_back_up_action_bt_node', 'nav2_spin_action_bt_node', 'nav2_wait_action_bt_node', 'nav2_clear_costmap_service_bt_node', 'nav2_is_stuck_condition_bt_node', 'nav2_goal_reached_condition_bt_node', 'nav2_goal_updated_condition_bt_node', 'nav2_initial_pose_received_condition_bt_node', 'nav2_reinitialize_global_localization_service_bt_node', 'nav2_rate_controller_bt_node', 'nav2_distance_controller_bt_node', 'nav2_speed_controller_bt_node', 'nav2_truncate_path_action_bt_node', 'nav2_goal_updater_node_bt_node', 'nav2_recovery_node_bt_node', 'nav2_pipeline_sequence_bt_node', 'nav2_round_robin_node_bt_node', 'nav2_transform_available_condition_bt_node', 'nav2_time_expired_condition_bt_node', 'nav2_distance_traveled_condition_bt_node']), rcl_interfaces.msg.ParameterValue(type=4, bool_value=False,integer_value=0, double_value=0.0, string_value='base_footprint', byte_array_value=[], bool_array_value=[], integer_array_value=[], double_array_value=[], string_array_value=[]), rcl_interfaces.msg.ParameterValue(type=3, bool_value=False, integer_value=0, double_value=0.1, string_value='', byte_array_value=[], bool_array_value=[], integer_array_value=[], double_array_value=[], string_array_value=[]), rcl_interfaces.msg.ParameterValue(type=1, bool_value=True, integer_value=0, double_value=0.0, string_value='', byte_array_value=[], bool_array_value=[], integer_array_value=[], double_array_value=[], string_array_value=[])])
You can use the /bt_navigator/set_parameters
to modify one or multiple parameter values.
Unfortunately, I cannot do that on the terminal with the services because of the structure of service request message. It can be done much easier with a Python or C++ code.
Summary:
You can make use of the following services to access or modify a ROS2 parameter of /bt_navigator/
(for example) from another Python or C++ node. But you will have to create a service client model on your program that needs to access or modify the parameters of another node.
/bt_navigator/describe_parameters
/bt_navigator/get_parameters
/bt_navigator/list_parameters
/bt_navigator/set_parameters
I hope this helps clarify your doubts.
Regards,
Girish
Hi @lfernandez ,
Please mark the appropriate post as “Solution” if your problem is fixed - so this issue can be closed.
Regards,
Girish
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.