在 rclcpp中
motor_node = std::make_shared();
motor_node->declare_parameter("wheels.radius");
motor_node->declare_parameter("wheels.separation");
motor_node->declare_parameter("chasiss_sv.max_linear");
motor_node->declare_parameter("chasiss_sv.min_linear");
motor_node->declare_parameter("chasiss_sv.max_angular");
motor_node->declare_parameter("chasiss_sv.min_angular");
motor_node->declare_parameter("chasiss_sensors.inc_compass");
motor_node->declare_parameter("chasiss_sensors.inc_beep");
motor_node->declare_parameter("chasiss_sensors.inc_fall");
motor_node->declare_parameter("chasiss_sensors.inc_bumper");
def_chassis_config.wheel_radius = motor_node->get_parameter("wheels.radius").as_double();
def_chassis_config.wheel_separation = motor_node->get_parameter("wheels.separation").as_double();
def_chassis_config.max_linear_velocity = motor_node->get_parameter("chasiss_sv.max_linear").as_double();
def_chassis_config.min_linear_velocity = motor_node->get_parameter("chasiss_sv.min_linear").as_double();
def_chassis_config.max_angular_velcity = motor_node->get_parameter("chasiss_sv.max_angular").as_double();
def_chassis_config.min_angular_velcity = motor_node->get_parameter("chasiss_sv.min_angular").as_double();
def_chassis_config.inc_compass = motor_node->get_parameter("chasiss_sensors.inc_compass").as_bool();
def_chassis_config.inc_beep = motor_node->get_parameter("chasiss_sensors.inc_beep").as_bool();
def_chassis_config.inc_fall = motor_node->get_parameter("chasiss_sensors.inc_fall").as_int();
=======================================================================================================
=============================== 范例 =========================================================
=======================================================================================================
motor_node: -->要和 launch 文件的 node 的name 相同.
ros__parameters:
wheels:
radius: 0.0750
separation: 0.360
chasiss_sv:
max_linear: 0.78540
min_linear: -0.78540
max_angular: 2.8435
min_angular: -2.8435
chasiss_sensors:
inc_compass: true
inc_fall: 0
inc_bumper: 0
inc_beep : true
============= launch 文件中 =============================
def generate_launch_description():
# 从 ROS2_ENV获取当前机器人的型号.
BIGROBOT_MODEL = os.environ['BIGROBOT_MODEL']
#找到配置文件的路径
big_param_dir = LaunchConfiguration(
'big_param_dir',
default=os.path.join(
get_package_share_directory('big_bringup'),
'param',
BIGROBOT_MODEL + '_size.yaml'))
return LaunchDescription([
DeclareLaunchArgument(
'big_param_dir',
default_value=big_param_dir,
description='Full path to bigrobot size parameter file to load'),
Node(
package='big_bringup',
name='motor_node', ---> 对应 yaml 的 定义头.
executable='hw_motor_node',
parameters=[big_param_dir],
output='screen'),
])
直接执行. 能够取到对应的参数.
ros2 launch big_bringup motor.launch.py
或者
ros2 run big_bringup hw_motor_node --ros-args -r __ns:=/ --params-file /work/ROS2/rolling_ridley/install/big_bringup/share/big_bringup/param/ant_robot_size.yaml
阅读(3211) | 评论(0) | 转发(0) |