Ask Your Question

spawn model with ROS2 gazebo

asked 2019-02-04 03:42:55 -0600

poonam1120 gravatar image


I followed this link and able to spawn the sdf model in gazebo.

But instead of sending sdf model code from command line, can we send just sdf/urdf file ? I tried that but it failed.

When i send complete sdf modem from cmnd lien with spawn_entity, it launched in gazebo. I am trying it on crystal.

Please let me know if anybody is having any clue.


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2019-02-04 11:30:17 -0600

tfoote gravatar image

updated 2019-03-13 15:50:06 -0600

The examples are using generic command line tools. If you want to send from a file you can probably set it up to pipe the arguments into the rosservice call using xargs. But more likely I'd recommend writing the few line rclpy script to load the file and call the service call. If you'd like to contribute a generic version of that helper script to the gazebo_ros_pkgs that would be even better.

edit flag offensive delete link more

answered 2019-03-13 13:21:02 -0600

clyde gravatar image

Following tfoote's advice, here is an example:

import sys
import rclpy
from gazebo_msgs.srv import SpawnEntity

def request_spawn(xml: str):
    node = rclpy.create_node('spawn_entity')
    client = node.create_client(SpawnEntity, 'spawn_entity')
    if not client.service_is_ready():
    request = SpawnEntity.Request()
    request.xml = xml
    future = client.call_async(request)
    rclpy.spin_until_future_complete(node, future)
    if future.result() is not None:
        print('response: %r' % future.result())
        raise RuntimeError('exception while calling service: %r' % future.exception())

if len(sys.argv) < 2:
    print('usage: ros2 run my_package -- example.urdf')

f = open(sys.argv[1], 'r')
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools



Asked: 2019-02-04 03:42:55 -0600

Seen: 273 times

Last updated: Mar 13