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

This post is a wiki. Anyone with karma >75 is welcome to improve it.

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 close merge delete