Gazebo will segfault if any of the components (mechanism controller stack, dynamic plug-ins, etc) fail. To make PR2 simulator a useful tool, you will want to run it in debug mode sometimes. Assuming user is familiar with gdb, here are 3 ways to obtain a backtrace.

Launching GDB with roslaunch

  • Append the following line to your .bashrc:

    source `rospack find gazebo`/setup.bash
  • Add launch-prefix="gdb --args" and output="screen" to the gazebo node in the launch script. For example, modify the file gazebo_worlds/launch/empty_world.launch:

    <node pkg="gazebo" launch-prefix="gdb --args " type="gazebo" args="-n $(find gazebo_worlds)/worlds/empty.world" respawn="false" output="screen">
      <env name="LD_LIBRARY_PATH" value="$(find pr2_gazebo_plugins)/lib:$(find gazebo)/gazebo/lib:$(optenv LD_LIBRARY_PATH)" />
      <env name="GAZEBO_RESOURCE_PATH" value="$(find gazebo_worlds):$(find gazebo)/gazebo/share/gazebo" />
      <env name="OGRE_RESOURCE_PATH" value="$(find ogre)/ogre/lib/OGRE" />
    </node>

    In the terminal after roslaunching the modified empty_world.launch, you will have to type run and press enter at the (gdb)-prompt to start gazebo.

Manual

  • Terminal 1: Startup ROS core
    roscore
  • Terminal 2: Create a launch script, save as upload.launch:

    <launch>
      <param name="robot_description" command="$(find xacro)/xacro.py '$(find pr2_description)/robots/pr2.urdf.xacro'" />
    </launch>
    then send robot description XML to the parameter server,
    roslaunch upload.launch
  • Terminal 3: Start Gazebo with an empty world and run gdb on gazebo to catch segfaults:
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`rospack find pr2_gazebo_plugins`/lib:`rospack find gazebo`/gazebo/lib
    export GAZEBO_RESOURCE_PATH=$GAZEBO_RESOURCE_PATH:`rospack find pr2_ogre`:`rospack find pr2_defs`:`rospack find pr2_description`:`rospack find gazebo_worlds`:`rospack find gazebo`/gazebo/share/gazebo
    export OGRE_RESOURCE_PATH=$OGRE_RESOURCE_PATH:`rospack find ogre`/ogre/lib/OGRE
    gdb --args `rospack find gazebo`/gazebo/bin/gazebo `rospack find gazebo_worlds`/worlds/empty.world
  • Terminal 4: Spawn PR2 in the empty world
    rosrun gazebo spawn_model -urdf -param robot_description -model pr2
  • Terminal 5: Optional - load default set of controllers for PR2
    roslaunch `rospack find pr2_gazebo`/controllers/pr2_default_controllers.launch

Attach GDB to a Running Process

  • Bring up Gazebo normally, find the process id for gazebo, then attach gdb to the gazebo process. For example, if you know gazebo is running with process id 1234,
    localhost:~/ros/ros-pkg> gdb --pid 1234


Wiki: pr2_simulator/Tutorials/RunningSimulatorWithGDB/cturtle (last edited 2016-02-23 05:45:11 by AustinHendrix)