
In the launch file
Which launch file are you talking about ? You should include it in your question, or at least tell the node you are trying to launch.
I'm assuming that you want to launch a turtlebot simulation, so it's the node spawn_model from the package gazebo_ros that will handle the initial position. You should have something like this in your launch file :
<node pkg="gazebo_ros" type="spawn_model" name="spawn_urdf" args="-urdf -model turtlebot3_$(arg model) -x $(arg x_pos) -y $(arg y_pos) -z $(arg z_pos) -param robot_description" />
Now if you look at all the arguments of the script spawn_model here you will see this :
-x <x in meters> - optional: initial pose, use 0 if left out
-y <y in meters> - optional: initial pose, use 0 if left out
-z <z in meters> - optional: initial pose, use 0 if left out
-R <roll in radians> - optional: initial pose, use 0 if left out
-P <pitch in radians> - optional: initial pose, use 0 if left out
-Y <yaw in radians> - optional: initial pose, use 0 if left out
So you just have to add this in the args of the node spawn_model, after -z $(arg z_pos) for example : -R $(arg ROLL) , with ROLL being the argument name that you should define at the beginning of your launch file.
Edit :
You seem to have a little confusion with the arguments of a launch file, the name isn't relevant at all, it's like declaring a variable. The important part is the value you assign to it. You should have a look at the wiki for more explanations.
In your case you have this :
<node pkg="gazebo_ros" type="spawn_model" name="spawn_urdf" args="-urdf -model turtlebot3_$(arg model) -x $(arg x_pos) -y $(arg y_pos) -z $(arg z_pos) -param robot_description" />
You give to the node spawn_model a list of arguments, for example you specify the x value by adding -x VALUE where VALUE is set at the beginning of your launch file like this :
<arg name="x_pos" default="-1.0"/>
So if you want to set the roll, pitch or yaw you have to add in the list -R for the roll, -P for the pitch and -Y for the yaw. Like this :
<arg name="roll" default="0.0"/>
<arg name="pitch" default="0.0"/>
<arg name="yaw" default="0.0"/>
<node pkg="gazebo_ros" type="spawn_model" name="spawn_urdf" args="-urdf -model turtlebot3_$(arg model) -x $(arg x_pos) -y $(arg y_pos) -z $(arg z_pos) -R $(arg roll) -P $(arg pitch) -Y $(arg yaw) -param robot_description" />
(you can name the arguments whatever you want, you just need to use them properly)
Originally posted by Delb with karma: 3907 on 2021-07-05
This answer was ACCEPTED on the original site
Post score: 0
Original comments
Comment by Guapiii on 2021-07-07:
I am sorry for not being clear enough in my question. The launch file i am using is ros/melodic/share/turtlebot3_gazebo/turtlebot3_world.launch
I used your method to add: <arg name="YAW" default="1.5"/> after <arg name="z_pos" default="0.0"/>
But it doesn`t work
Comment by Guapiii on 2021-07-08:
It is true that I do not know enough about the parameters of the launch file.
I used your method successfully!
Thank you very much for your answer!