Visible to the public Select a different initial poseConflict Detection Enabled

The goal of this tutorial is to modify the initial pose of the catvehicle on startup of the simulation.

Identify parameters

Pose information is provided to gazebo when the simulation is launched. There are several launchfiles we utilize in different simulations, let's start with catvehicle_neighborhood.launch as the example. Look in that file (found in catvehicle_ws/src/catvehicle/launch) for the following section:

<group ns="catvehicle">
<param name="robot_description"
         command="$(find xacro)/xacro.py '$(find catvehicle)/urdf/catvehicle.xacro' roboname:='catvehicle' front_laser_points:='$(arg front_laser_points)' velodyne_points:='$(arg velodyne_points)' camera_right:='$(arg camera_right)' camera_left:='$(arg camera_left)'" />
<include file="$(find catvehicle)/launch/catvehicle.launch">
    <arg name="robot_name" value="catvehicle"/>
    <arg name="init_pose" value="-x 0 -y 0 -z 0"/>
    <arg name="config_file" value="catvehicle_control.yaml"/>
</include>
</group>

The arg "init_pose" has (x,y,z) = (0,0,0). If we start up this simulation, we will be able to note the car's position (see the below screenshot).

Copy and edit launchfile into your package

If you haven't created a custom package yet to control the catvehicle, create one (for example) as below. You should not modify files directly from the catvehicle package, as it will make your setup more difficult to debug if something goes wrong!

cd catvehicle_ws/src
catkin_create_pkg custom_initial_location

Now in that package:

cd custom_initial_location
mkdir launch
cd launch
cp catvehicle_ws/src/catvehicle/launch/catvehicle_neighborhood.launch .
cd ~/catvehicle_ws
catkin_make
source devel/setup.bash

This gives you an exact replica of the neighborhood launchfile, for you to modify in your own package. You can change the initial position to something else, let's pick (x,y,z) = (0,-5,0)

<group ns="catvehicle">
<param name="robot_description"
         command="$(find xacro)/xacro.py '$(find catvehicle)/urdf/catvehicle.xacro' roboname:='catvehicle' front_laser_points:='$(arg front_laser_points)' velodyne_points:='$(arg velodyne_points)' camera_right:='$(arg camera_right)' camera_left:='$(arg camera_left)'" />
<include file="$(find catvehicle)/launch/catvehicle.launch">
    <arg name="robot_name" value="catvehicle"/>
    <arg name="init_pose" value="-x 0 -y -5 -z 0"/>
    <arg name="config_file" value="catvehicle_control.yaml"/>
</include>
</group>

Note that we haven't changed the orientation of the car, just the position along the y axis. 

Launch new position from your new package's launchfile

Let's start our simulation, noting that now we need to adjust the package name to reflect the package within which you are working from the command line. All the other package information inside the launchfile will still work, since you have that package in your path.

roslaunch custom_initial_location catvehicle_neighborhood.launch

The vehicle is now clearly in different location.

Updating roll, pitch and yaw

The values prefixed by -x -y -z control position, the values for roll, pitch, and yaw are entered by (case-sensitive): -R, -P, -Y. For example, to set the vehicle to be turned 90 degrees:

<!-- turn 90 degrees (pi/2) -->
<arg name="init_pose" value="-x 0 -y -5 -z 0 -R 0 -P 0 -Y 1.57"/>

Give it a try: which way did you expect it to turn, and did it turn the way you expected?