当程序有许多参数传入时,通常会通过rosparm进行传递,
传递形式为在roslaunch文件中的node中,使用rosparm,比如
<node pkg="tvio" type="image_processor_node" name="image_processor" output="screen" >
<rosparam command="load" file="$(arg calibration_file)"/>
<param name="grid_row" value="4"/>
<param name="grid_col" value="5"/>
<remap from="~imu" to="/xsens_imu_data"/>
<remap from="~cam0_image" to="/camera/left/image_raw"/>
<remap from="~cam1_image" to="/camera/right/image_raw"/>
</node>
其中,calibration_file为指定的rosparam格式的yaml文件。
可以通过launch文件启动调试,但是不是很习惯,还是喜欢用Clion的可视化调试。
方法:
1)在终端中手动加载rosparam参数:
python /opt/ros/kinetic/bin/rosparam load /xxxx/camchain.yaml
参数一旦加载后,会保持在本机上的参数服务器中(是不是和roscore相关),程序运行就能读取到。
2)remap中的参数项通过程序的命令行参数形式传入:
image_processor ~imu:=/xsens_imu_data ~cam0_image:=/camera/left/image_raw ~cam1_image:=/camera/right/image_raw
param中的参数还不知道如何传入。
代码中从参数服务器获取参数的方式:
传递形式为在roslaunch文件中的node中,使用rosparm,比如
<node pkg="tvio" type="image_processor_node" name="image_processor" output="screen" >
<rosparam command="load" file="$(arg calibration_file)"/>
<param name="grid_row" value="4"/>
<param name="grid_col" value="5"/>
<remap from="~imu" to="/xsens_imu_data"/>
<remap from="~cam0_image" to="/camera/left/image_raw"/>
<remap from="~cam1_image" to="/camera/right/image_raw"/>
</node>
其中,calibration_file为指定的rosparam格式的yaml文件。
可以通过launch文件启动调试,但是不是很习惯,还是喜欢用Clion的可视化调试。
方法:
1)在终端中手动加载rosparam参数:
python /opt/ros/kinetic/bin/rosparam load /xxxx/camchain.yaml
参数一旦加载后,会保持在本机上的参数服务器中(是不是和roscore相关),程序运行就能读取到。
2)remap中的参数项通过程序的命令行参数形式传入:
image_processor ~imu:=/xsens_imu_data ~cam0_image:=/camera/left/image_raw ~cam1_image:=/camera/right/image_raw
param中的参数还不知道如何传入。
代码中从参数服务器获取参数的方式:
nh_.param<std::string>("/cam0/distortion_model",cam0_distortion_model, std::string("radtan"));
nh_.getParam("/cam0/resolution",cam0_resolution_temp);
对于内置类型,比如int、string等,以上两种都是可以的。
但经常需要从参数中传入矩阵或者向量,比如矩阵的内参外参等,这时候都要用第二种形式:
std::vector<float> cam0_distortion_temp; nh_.getParam("/cam0/distortion_coeffs",cam0_distortion_temp); cam0_distortion_coeffs = cv::Vec4d(cam0_distortion_temp[0],cam0_distortion_temp[1], cam0_distortion_temp[2],cam0_distortion_temp[3]);注意,第二种参数传递形式中,是没有默认值的。因此,必须保证程序执行时参数服务器中已有该参数。不然后后面使用到变量cam0_distortion_temp的地方就会报错。
Comments
Post a Comment