GAZEBO usage of set_model_state (to set object position)

asked 2019-05-07 06:28:24 -0600

mikeda gravatar image

updated 2019-05-07 06:30:59 -0600

Dear community,

COARSE PROBLEM DEFINITION: I want to use the system (ROS+GAZEBO) as simulation environment for image based machine learning. Therefore I tried both having a camera on a robot and having a robot independent camera that I want to manipulate in the scene in order to create relevant images from which I want to learn. My problem is that the camera in Gazebo doesn't move (or at least doesn't appear to move) if I use the set_model_state command. Apparently the original camera position is restored right after unpausing physics. How can I avoid that ? Can you help me with an explanation on how the set_model_state() command is used correctly ? Does it have something todo with Gazebo running simulations in the background?

I try do the following :

    self.model_coordinates = rospy.ServiceProxy( '/gazebo/get_model_state', GetModelState)
    self.object_coordinates = self.model_coordinates("camera", "world")
    # example movement -> move camera up 0.1m
    self.object_coordinates.pose.position.z = self.object_coordinates.pose.position.z + 0.1 


    state  = ModelState()
    state.pose = self.object_coordinates.pose
    state.model_name = "camera"
        ret = self.set_mstate(state)
        print ret
    except Exception, e:
        rospy.logerr('Error on calling service set_mstate: %s',str(e))

   # the camera position is successfully changed -> I see that from the movement of a attached geometry in GAZEBO


    # right after unpausing physics -> which is required to update the rendered camera image the camera (or the attached geometry) is moved to its original position -> if not commented out or triggered seperately it's so fast that it doesn't even appear to move.

SETUP_DESCRIPTION: I'm running ROS Kinetic on Xenial ("Ubuntu 16.04.5 LTS") with Gazebo 7.0.0.


  • I also tried it with Kinetic on Xenial running Gazebo 9.
  • I tried it from the console with according rosservice calls
  • I tried with a camera on a robot which joint configuration -> same effect after unpausing physics set by the same command
edit retag flag offensive close merge delete