ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to publish /gazebo/set_model_states for 100 vehicles in just one time?

asked 2022-05-05 04:46:58 -0500

tony9811 gravatar image

Sorry to bother you, but I got some questions in ros publish. I want to set the pose of 100 vehicles in gazebo, but if I publish the msg for 100 times, just 10 of them can refresh smoothly in the gazebo, most of the others will be slower. I guess it might be the restriction of queue_size, so I try to get 100 "gazebo/set_model_states" msg together so that the msg number will be only one instead of 100. But I do not know how to achieve it. Thank you for your help! Here are my current codes.

num=100 t=60*18

if __name__=="__main__":

settings = termios.tcgetattr(sys.stdin)

rospy.init_node('turtlebot3_replay1')

pub= rospy.Publisher('gazebo/set_model_state', ModelState, queue_size=10)
pose_msg = ModelState()


print('Replay')

x=[]
y=[]
angle=[]

with open('x.txt','r') as path_data:
    for line in path_data:
        x.append(line.split())

with open('y.txt','r') as path_data:
    for line in path_data:
        y.append(line.split())

with open('angle.txt','r') as path_data:
    for line in path_data:
        angle.append(line.split())

flag=1

while(flag):
    for i in range(t):
        for j in range(num):
            pose_msg.model_name = 'turtlebot3_'+str(j)

            pose_msg.pose.position.x=eval(x[j][i])
            pose_msg.pose.position.y=eval(y[j][i])
            pose_msg.pose.position.z=0.100854
            pub.publish(pose_msg)                 
        time.sleep(0.1)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-07-12 04:22:12 -0500

Hi tony9811, could you finally find the issue? I am experiencing the same.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-05-05 04:44:55 -0500

Seen: 238 times

Last updated: May 05 '22