Robotics StackExchange | Archived questions

Set orientation in a .world file

Hi! Using tum_simulator for indigo I'm trying to create my own world. I can import my meshes and lights using the sdf syntax, but when I try to change orientation of a spot light (pitch in particular), nothing happens in Gazebo (orientation is setted on [0 0 0]). This is my .world file:

<?xml version="1.0" ?>
<sdf version='1.4'>
  <world name='default'>
    <light name='sun' type='directional'>
      <cast_shadows>1</cast_shadows>
      <pose>0 0 10 0 -0 0</pose>
      <diffuse>0.8 0.8 0.8 1</diffuse>
      <specular>0.2 0.2 0.2 1</specular>
      <attenuation>
        <range>1000</range>
        <constant>0.9</constant>
        <linear>0.01</linear>
        <quadratic>0.001</quadratic>
      </attenuation>
      <direction>-0.5 0.1 -0.9</direction>
    </light>
    <light name='spot1' type='spot'>
      <cast_shadows>1</cast_shadows>
      <pose>2.5 7.9 4.0 0 -0.5 0</pose>
      <diffuse>0.8 0.8 0.8 1</diffuse>
      <specular>0.2 0.2 0.2 1</specular>
      <attenuation>
        <range>20</range>
        <constant>0.5</constant>
        <linear>0.01</linear>
        <quadratic>0.001</quadratic>
      </attenuation>
    </light>
    <model name='ground_plane'>
      <static>1</static>
      <link name='link'>
        <collision name='collision'>
          <geometry>
            <plane>
              <normal>0 0 1</normal>
              <size>100 100</size>
            </plane>
          </geometry>
          <surface>
            <friction>
              <ode>
                <mu>100</mu>
                <mu2>50</mu2>
              </ode>
            </friction>
            <bounce/>
            <contact>
              <ode/>
            </contact>
          </surface>
          <max_contacts>10</max_contacts>
        </collision>
        <visual name='visual'>
          <cast_shadows>0</cast_shadows>
          <geometry>
            <plane>
              <normal>0 0 1</normal>
              <size>100 100</size>
            </plane>
          </geometry>
          <material>
            <script>
              <uri>file://media/materials/scripts/gazebo.material</uri>
              <name>Gazebo/Grey</name>
            </script>
          </material>
        </visual>
        <velocity_decay>
          <linear>0</linear>
          <angular>0</angular>
        </velocity_decay>
        <self_collide>0</self_collide>
        <kinematic>0</kinematic>
        <gravity>1</gravity>
      </link>
    </model>
    <physics type='ode'>
      <max_step_size>0.001</max_step_size>
      <real_time_factor>1</real_time_factor>
      <real_time_update_rate>1000</real_time_update_rate>
      <gravity>0 0 -9.8</gravity>
    </physics>
    <scene>
      <ambient>0.4 0.4 0.4 1</ambient>
      <background>0.7 0.7 0.7 1</background>
      <shadows>1</shadows>
    </scene>
    <model name='Museum'>
      <static>1</static>
      <link name='link'>
        <collision name='collision'>
          <geometry>
            <mesh>
              <uri>model://museum/meshes/museum.dae</uri>
            </mesh>
          </geometry>
          <max_contacts>10</max_contacts>
          <surface>
            <bounce/>
            <friction>
              <ode/>
            </friction>
            <contact>
              <ode/>
            </contact>
          </surface>
        </collision>
        <visual name='visual'>
          <geometry>
            <mesh>
              <uri>model://museum/meshes/museum.dae</uri>
            </mesh>
          </geometry>
        </visual>
        <velocity_decay>
          <linear>0</linear>
          <angular>0</angular>
        </velocity_decay>
        <self_collide>0</self_collide>
        <kinematic>0</kinematic>
        <gravity>1</gravity>
      </link>
      <pose>0 0 0 0 -0 0</pose>
    </model>    
    <gui fullscreen='0'>
      <camera name='user_camera'>
        <pose>1.49016 -3.72367 3.62379 -2.88294e-17 0.273797 1.4042</pose>
        <view_controller>orbit</view_controller>
      </camera>
    </gui>
  </world>
</sdf>

and the light named "spot1" is created into Gazebo with orientation 0 0 0. Can someone help me? Thank you ;)

EDIT:

Once updated Gazebo (on version 7), I have issue on spawning a model of a robot. This is the launch file that creates problem: <?xml version="1.0"?>

 <launch>
   <arg name="model" default="$(find cvg_sim_gazebo)/urdf/quadrotor.urdf.xacro"/>
   <arg name="x" default="0"/>
   <arg name="y" default="0"/>
   <arg name="z" default="0.5"/>
   <arg name="R" default="0"/>
   <arg name="P" default="0"/>
   <arg name="Y" default="0"/>
   <!-- send the robot XML to param server -->
   <param name="robot_description" command="$(find xacro)/xacro.py '$(arg model)'" />

   <!-- push robot_description to factory and spawn robot in gazebo -->
   <node name="spawn_robot" pkg="gazebo_ros" type="spawn_model"
   args="-param robot_description
   -urdf
   -x '$(arg x)'
   -y '$(arg y)'
   -z '$(arg z)'
   -R '$(arg R)'
   -P '$(arg P)'
   -Y '$(arg Y)'
   -model quadrotor"
     respawn="false" output="screen"/>

   <!-- start robot state publisher -->
   <node pkg="robot_state_publisher" type="state_publisher" name="robot_state_publisher" output="screen" >
     <param name="publish_frequency" type="double" value="50.0" />
     <param name="tf_prefix" type="string" value="" />
   </node>

   <node name="ground_truth_to_tf" pkg="message_to_tf" type="message_to_tf" output="screen">
     <param name="odometry_topic" value="ground_truth/state" />
     <param name="frame_id" value="nav" />
   </node>
   <!-- node name="hector_pose_estimation" pkg="hector_pose_estimation" type="hector_pose_estimation_node" output="screen"/-->

 </launch>

On the terminal, appears:

spawn_model script started
[INFO] [WallTime: 1490808509.677239] [0.000000] Loading model xml from ros parameter
[INFO] [WallTime: 1490808509.679894] [0.000000] Waiting for service /gazebo/spawn_urdf_model

and once Gazebo is closed (forced):

[ground_truth_to_tf-5] killing on exit
[robot_state_publisher-4] killing on exit
[spawn_robot-3] killing on exit
[gazebo_gui-2] killing on exit
[gazebo-1] killing on exit
Traceback (most recent call last):
  File "/home/jony/catkin_ws/src/gazebo_ros_pkgs/gazebo_ros/scripts/spawn_model", line 301, in <module>
    sm.callSpawnService()
  File "/home/jony/catkin_ws/src/gazebo_ros_pkgs/gazebo_ros/scripts/spawn_model", line 267, in callSpawnService
    initial_pose, self.reference_frame, self.gazebo_namespace)
  File "/home/jony/catkin_ws/src/gazebo_ros_pkgs/gazebo_ros/src/gazebo_ros/gazebo_interface.py", line 28, in spawn_urdf_model_client
    rospy.wait_for_service(gazebo_namespace+'/spawn_urdf_model')
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 159, in wait_for_service
    raise ROSInterruptException("rospy shutdown")
rospy.exceptions.ROSInterruptException: rospy shutdown

Asked by jony on 2017-03-28 04:57:35 UTC

Comments

Answers

I suppose you're using an old version of Gazebo (probably Gazebo 2.2?). You can check the version running:

gazebo --version

I loaded your world on Gazebo 7.6 and the spotlight has a non-zero orientation. I suggest you upgrade your Gazebo version, because the oldest supported version right now is Gazebo 7.

Here's a handy tutorial on how to use a different version of Gazebo with ROS:

http://gazebosim.org/tutorials?tut=ros_wrapper_versions&cat=connect_ros#UsingaspecificGazeboversionwithROS

Asked by chapulina on 2017-03-28 12:09:06 UTC

Comments

Duh, I just saw you tagged the question with gazebo_2, so my supposition was correct :)

Asked by chapulina on 2017-03-28 12:12:52 UTC

@chapulina thanks for the answer. Yes, I use Gazebo 2.2.6. And I use the package tum_simulator, too. Installing a different version of Gazebo can produce compatibility problems?

Asked by jony on 2017-03-29 10:34:08 UTC

@chapulina effectively with Gazebo7 spot light are well oriented. But using tum_simulator, ardrone model are not spawning.

Asked by jony on 2017-03-29 11:44:13 UTC

I'm not familiar with the tum_simulator. You could get in touch with the maintainers to get it upgraded to ROS Kinetic and Gazebo 7.

Asked by chapulina on 2017-03-29 12:38:17 UTC

@chapulina I edited the answer with the spawning launch file that creates problems.

Asked by jony on 2017-03-29 12:45:35 UTC

@jony, I'm afraid that migration from Gazebo 2 to Gazebo 7 could require a lot of changes to the package you're using.

Asked by chapulina on 2017-03-29 12:56:54 UTC

@chapulina ok, so I return to my original unresolved question: there is a way to modify spot light orientation using tum_simulator and Gazebo 2.2.6?

Asked by jony on 2017-03-29 16:15:16 UTC

I think the only way would be to publish a Gazebo message to change the light pose after the world has been loaded.

Asked by chapulina on 2017-03-29 18:47:04 UTC