ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

Spawn objects in gazebo in certain frequency ROS2 Foxy

asked 2022-07-31 05:12:22 -0500

OguzKahraman gravatar image

Hello. I'm trying to spawn a box in a certain part of gazebo world. However, this process should continue many times in a certain frequency. In another words, I want to spawn a box in certain frequency in gazebo environment. How can I do this? Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-08-01 03:46:25 -0500

sampreets3 gravatar image

Hi,

You can wrap the necessary code for spawning one box inside a Gazebo world inside a service, which takes in maybe a trigger, and a location of the box. You can then add a call to this service in your Timer callback, and this should help you spawn the boxes with a certain frequency.

edit flag offensive delete link more

Comments

1

Hi,

Thank you for your answer. I have found a workaround mostly like you suggested. I will change it like you said using a timer.

My current code is similar:

for i in range(100):
        x = random.randint(18,27)
        y = random.randint(-3,7)
        yaw = np.random.randn()
        x = float(x)
        y = float(y)
        yaw = float(yaw)
        self.initial_pose.position.x = x
        self.initial_pose.position.y = y
        self.initial_pose.position.z = 0.0
        self.initial_pose.orientation.z = yaw
        model_name = "object_"+str(i)
        model_xml = random.choice(self.xml_files)
        self.call_spawn_model_server(model_name, model_xml, self.initial_pose)
        time.sleep(45.0)
OguzKahraman gravatar image OguzKahraman  ( 2022-08-07 07:11:37 -0500 )edit

Hi, thanks for posting your code snippet! I am sure that it will benefit other users of the forum

sampreets3 gravatar image sampreets3  ( 2022-08-07 08:39:11 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-07-31 05:12:22 -0500

Seen: 14 times

Last updated: Aug 01