Adding modelState to gazebo simulator using python node

asked 2016-06-06 08:06:28 -0500

RSA_kustar gravatar image


I would like to add a model to gazebo simulator not in the world file but while executing a node. Therefore, I created the following node:

#!/usr/bin/env python
import rospy  
import roslib
from std_msgs.msg import String
from gazebo_msgs.msg import ModelState

def setObject():

    pub = rospy.Publisher('setObjectTopic', ModelState, queue_size=10)
    rospy.init_node('setObject', anonymous=True)
    rate = rospy.Rate(10) # 10hz
    while not rospy.is_shutdown():
    msg = ModelState() 
    msg.pose.position.x = 1.0 
    msg.pose.position.y = 1.0 
    msg.model_name = "grey_wall"
        print  "here"

if __name__ == '__main__':
    except rospy.ROSInterruptException:

I didnt git any syntax error but I could not see the object on the gazebo. So, what should I do to make this thing works?

edit retag flag offensive close merge delete


F.Brosseau gravatar image F.Brosseau  ( 2016-06-06 08:23:54 -0500 )edit

I am getting this issue as well. Are you saying that the Gazebo model cannot be moved like this because there is a gazebo service that is charged to do this? If that is the case, how can we move the model? Also, I think that it should be: pub = rospy.Publisher('/gazebo/set_model_state'.....

huckl3b3rry87 gravatar image huckl3b3rry87  ( 2017-07-17 01:02:35 -0500 )edit