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

Spawned hector quadrotor cannot move

asked 2017-04-23 01:14:49 -0500 gravatar image

Hi everyone

Currently, I am learning how to dynamically spawn a hector quadrotor duirng the simulation in C++. But I found a problem with it. I can call spawn_urdf_model service to generate a new UAV. But when I check topic list, I did not found the cmd_vel topic under the namespace of spawnd robot.

When I go back to check the spawn_quadrotor.launch, which is a basic launch file for generating a robot, except for the model, it still create some nodes for other stuff (tf, controller and so). Therefore, even I successfully spawn a new hector quadrotor in the c++ file, it does not have nesscessary topic for me to control it. Does anyone meet with the similar situations? Or does anyone know how to add topic to a robot in c++ file or in urdf file? I only need cmd_vel for controlling the movement and ground_truth_to_tf/pose for sensing the position.

Thank you very much

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-04-23 20:51:03 -0500

Geoff gravatar image

updated 2017-04-24 02:37:34 -0500

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_sdfmodel 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)

edit flag offensive delete link more


Hi Geoff

It sounds like the last suggestion is really promising for me. But I am not sure whether I am right or not. Originally, quadrotor is descripted by a .xacro file. And in .launch file, except for the model, some control node also spawned. I think this is why I cannot call cmd_vel. gravatar image  ( 2017-04-24 00:00:17 -0500 )edit

But, as you suggested, I can transfer a .launch file to a sdf file so that every control node will be included in the spawned model. Am I right about it? Because, I must use c++ to spawn a robot and the spawned robot should have exactly the same capability as initial launched robot. gravatar image  ( 2017-04-24 00:02:07 -0500 )edit

So I am wondering whether there are some ways to launch a .launch file in c++. Do you have some ideas towards this? I am grateful for any reply from you. gravatar image  ( 2017-04-24 00:02:47 -0500 )edit

Or, do you know some ways to run multiple (maybe hundreds) simulations together? Because the aim for respawning robots is for reseting the experiments so that in on simulation actually I can run multiple simulation subsequently. Do you know some ways to realize this? Thank you very much gravatar image  ( 2017-04-24 00:05:01 -0500 )edit

You cannot copy nodes from a launch file to an sdf file. Gazebo SDF has nothing to do with ROS nodes. Gazebo does support controller plugins, but these are separate from ROS nodes which may provide other controllers.

Geoff gravatar image Geoff  ( 2017-04-24 00:42:52 -0500 )edit

I think .urdf can do the similar thing. My urdf file is parsed from a .xacro file. I remember in that urdf file I see some plugin tags. But in my launch file, except for the model, it also include nodes for control stuff, such as ground_to_truth. gravatar image  ( 2017-04-24 01:41:48 -0500 )edit

Excuse me sir, now I have .xacro file for descripting the hector_quadrotor and .launch file for spawning a hector quadrotor with all necessary control plugins. Do you know how to only use c++ code to spawn a real hector quadrotor robot that can be controlled. This is very important to me.

Thanks gravatar image  ( 2017-04-24 01:43:54 -0500 )edit

Technically, URDF cannot do a similar thing, but it can contain the information used by Gazebo because most tools that use URDF will ignore the tags they don't understand. This makes it easy to put things like Gazebo plugins in the URDF and use a single file, which is convenient.

Geoff gravatar image Geoff  ( 2017-04-24 02:38:39 -0500 )edit

Question Tools

1 follower


Asked: 2017-04-23 01:14:49 -0500

Seen: 710 times

Last updated: Apr 24 '17