Robotics StackExchange | Archived questions

GAZEBO usage of set_model_state (to set obejct positions)

Dear community,

COARSE PROBLEM DEFINITION: I want to use the system 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 setmodelstate 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 setmodelstate() 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 

    self.pause_physics()

    state  = ModelState()
    state.pose = self.object_coordinates.pose
    state.model_name = "camera"
    try:
        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

    self.unpause_physics()

    # 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.

OTHER TRIALS:

Asked by mikeda on 2019-05-07 06:34:24 UTC

Comments

set_model_state is a publisher, did you try publishing ?

Maybe an example https://github.com/neobotix/neo_simulation/blob/indigo/scripts/spawn_obstacles_track2.py

Also, I guess it does not have anything to do with the Gazebo running simulations in the background.

Asked by pmuthu2s on 2019-05-07 07:23:03 UTC

Answers