ROS下使用roslaunch命令时使用gdb/pdb调试

最近在使用OpenPTrack来进行人的跟踪测试,可是运行程序的时候总是崩溃。
OpenPTrack是通过roslaunch命令来运行程序的。
网上搜索了一下,可以找到对应的launch文件,在其中的node节点中增加如下语句即可

launch-prefix="xterm -e gdb -ex run --args "

我们以

$ roslaunch tracking detection_and_tracking_kinect2.launch

这条命令为例,detection_and_tracking_kinect2.launch文件的原始内容如下:

<launch>
  <arg name="camera_name"             default="kinect2_head" />

  <!-- Start the Kinect -->
  <include file="$(find kinect2_bridge)/launch/kinect2_bridge_ir.launch"/> 

   <!-- Launch ground based people detection node -->
   <node pkg="detection" type="ground_based_people_detector" name="ground_based_people_detector" output="screen" required="true">
    <rosparam command="load" file="$(find detection)/conf/ground_based_people_detector_kinect2.yaml" /> 
    <param name="classifier_file" value="$(find detection)/data/HogSvmPCL.yaml"/>
    <!--param name="camera_info_topic" value="/$(arg camera_name)/depth_lowres/camera_info"/-->
    <param name="camera_info_topic" value="/$(arg camera_name)/ir_rect/camera_info"/>
    <param name="output_topic" value="/detector/detections"/>
    <!--param name="pointcloud_topic" value="/$(arg camera_name)/depth_lowres/points"/-->
    <param name="pointcloud_topic" value="/$(arg camera_name)/depth_ir/points"/>
    <param name="rate" value="60.0"/>  
  </node>

</launch>

增加调试命令之后的样子如下:

<launch>
  <arg name="camera_name"             default="kinect2_head" />

  <!-- Start the Kinect -->
  <include file="$(find kinect2_bridge)/launch/kinect2_bridge_ir.launch"/> 

   <!-- Launch ground based people detection node -->
   <node pkg="detection" type="ground_based_people_detector" name="ground_based_people_detector" output="screen" required="true" launch-prefix="xterm -e gdb -ex run --args ">
    <rosparam command="load" file="$(find detection)/conf/ground_based_people_detector_kinect2.yaml" /> 
    <param name="classifier_file" value="$(find detection)/data/HogSvmPCL.yaml"/>
    <!--param name="camera_info_topic" value="/$(arg camera_name)/depth_lowres/camera_info"/-->
    <param name="camera_info_topic" value="/$(arg camera_name)/ir_rect/camera_info"/>
    <param name="output_topic" value="/detector/detections"/>
    <!--param name="pointcloud_topic" value="/$(arg camera_name)/depth_lowres/points"/-->
    <param name="pointcloud_topic" value="/$(arg camera_name)/depth_ir/points"/>
    <param name="rate" value="60.0"/>  
  </node>

</launch>

(注意代码添加位置)这样在执行原来例子的时候,就会先打开一个新的Shell界面,被调试的程序就在这个Shell中被执行了。

如果被调式的是Python脚本,则需要修改调试器为pdb,如下:

launch-prefix="xterm -e python -m pdb "

参考链接


发布者

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注