The spawn_urdf_model
service just creates a model in Gazebo. It won't create any of the nodes you need to control it, as that is functionality outside of Gazebo. You will need to launch the nodes that control the simulated robot as well if you want to control it like a real robot.
If your goal is just to make the quadrotor move around and behave as an obstacle for your robot, then you can use the set_model_state
and related services to make models move around.
If your goal is to have a simulated quadrotor that you can control from ROS, then you will need to do something more complex. One option is to use make a system command call to start roslaunch
with a launch file that either creates the quadrotor and related nodes, or stops a running launch. This would work but I think it would be messy and hard to manage - you would need to keep track of PIDs and watch the roslaunch output to look for errors. If you were using Python this would be relatively easy using the subprocess
package. I think that Poco provides something similar for C++ but I've never used it.
Another option is a package called rosspawn, which is intended to provide a ROS API for launching ROS nodes. It hasn't been updated since Electric, though, so it probably would require some work to make it usable.
Finally, you could try editing the nodes that control the quadcopters to support dynamic_reconfigure, have the controller nodes always running, and dynamically reconfigure them to point them at new Gazebo models when you spawn them.
Edit: Having just seen one of your many other questions, I've found out that the Hector quadrotor can use Gazebo controllers in simulation, which should provide the topics you need. So if you use the spawn_sdf
model service and load the Gazebo simulation file, not just the URDF, then it should load all the control plugins for you as well.
Another edit:
I spent some time working with the hector_* packages, and I've managed to get a handle on how the simulation part is set up.
All the controllers that you want are implemented as ros_control controllers. This means that they work with the Gazebo ros_control support. The great thing about this for you is that you can call the spawn_sdf_model
service and pass the contents of the quadrotor.gazebo
file (which you need to generate by passing hector_quadrotor_description/urdf/quadrotor.gazebo
to xacro) to spawn a new instance of the quadrotor model, ready to go. To start the controllers, all you need to do then is call the controller_manager/load_controller
service. The name of the controller that subscribes to the /cmd_vel
topic is controller/twist
. From the command line, this looks like:
rosservice call /controller_manager/load_controller controller/twist
Do something similar from C++ by making a service client for that service and calling it with controller/twist
as the name of the controller to ... (more)