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

drive robot in gazebo ros with Clearpath Husky A200 or other robots

asked 2013-07-22 14:01:36 -0500

Marcus Barnet gravatar image

updated 2014-01-28 17:17:22 -0500

ngrennan gravatar image

Hi to all,

I'm using ROS groovy in my Ubuntu 12.04 and I've installed gazebo under ROS in order to use Husky A200 robot in the virtual environment.

Everything is working good, but I'm not able to understand if I can run my C++ code in my virtual A200 robot under Gazebo without having to physically connect the robot to my USB port.

For example, I have a C++ code which is able to drive the robot along a particular path (forward and backward): can I execute this code under Gazebo and move the virtual robot?

If yes, is there any tutorial I can read to understand how to load my code in gazebo? Can you help me, please? :)

Thank you a lot!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-07-22 21:18:55 -0500

ZdenekM gravatar image

You don't need to load any code into Gazebo. Your virtual robot (probably) offers exactly the same ROS topics / services as the real one (odom, cmd_vel etc). So, your ROS node can through this topics easily command virtual robot instead of the real one.

edit flag offensive delete link more


I posted an answer to better explain my problem by adding also a simple testing code. Do you think it is possible to run this code in Gazebo? What kind of modifications will I have to do?

Marcus Barnet gravatar image Marcus Barnet  ( 2013-07-22 21:47:38 -0500 )edit

answered 2013-07-22 21:46:27 -0500

Marcus Barnet gravatar image

Thank you ZdenekM for your answer and your help.

I would like to better understand how to run the code to drive my robot in Gazebo. At first, I have to launch Gazebo and then I have to add my robot model into the virtual worlds: but then? How I have to run my code from my shell?

Is there any possibility to easily and successfully run this code to virtually drive my robot under Gazebo? For example, I try to open USB port, but I do not think it will be possible if there is not real robot connect in my PC. Do I have to change something or Gazebo is able to emulate the USB port?

I have this simple testing code:

int main(int argc, char *argv[]) {
/* Configure the serial port */
const char* port = (argc == 2) ? argv[1] : "/dev/ttyUSB0";
clearpath::Transport::instance().configure(port, 3 /* max retries*/);

/* Get and print some system information */
clearpath::DataPlatformInfo *platform_info = clearpath::DataPlatformInfo::getUpdate();
cout << *platform_info << endl;
delete platform_info;
clearpath::DataPowerSystem  *power_info = clearpath::DataPowerSystem::getUpdate();
cout << *power_info << endl;
delete power_info;

cout << "Press enter to continue... ";

/* Subscribe to some interesting data */
clearpath::DataSystemStatus * cur_status = NULL;
clearpath::DataEncoders * cur_encoders = NULL;

/* Ramp speed to 0.6m/s over 6 seconds.
 * We use the 1Hz system status message for timing, so we want to begin by
 * waiting for the first message, which is sent shortly after the beginning
 * of the subscription */
cur_status = clearpath::DataSystemStatus::waitNext();
cout << *cur_status << endl; 
delete cur_status;

for(int i=1; i<=6; ++i) {
    // Set motor speed
    clearpath::SetVelocity(0.1*i, 0.0, 0.5).send();

    /* While waiting for the next system status message to arrive, print
     * all encoder messages as they are received */
    while( ! (cur_status = clearpath::DataSystemStatus::popNext()) ) {

        if( (cur_encoders = clearpath::DataEncoders::popNext()) ) {
            cout << *cur_encoders << endl;
            delete cur_encoders;
    cout << *cur_status << endl;
    delete cur_status;

/* Terminate subscriptions */

return 0;


edit flag offensive delete link more


Next time please, update original question ;) Well, common approach is to have some ROS robot driver (node) which allows you to command robot using topics / services. Then your application code in separated node so, it can be used to control either real or simulated robot.

ZdenekM gravatar image ZdenekM  ( 2013-07-23 07:51:22 -0500 )edit

Purpose of ROS API is to provide some level of abstraction... In your code, there is no abstraction ;)

ZdenekM gravatar image ZdenekM  ( 2013-07-23 07:52:48 -0500 )edit

I was used to develop with ARIA and MobileSim :( With MobileSim you can directly use your C++ code without using any abstraction. Since it appears to be a little bit difficult, is there any tutorial which explain me how to drive my robot in Gazebo and how to modify my code to let it work properly?

Marcus Barnet gravatar image Marcus Barnet  ( 2013-07-23 09:15:58 -0500 )edit

Question Tools

1 follower


Asked: 2013-07-22 14:01:36 -0500

Seen: 724 times

Last updated: Jul 22 '13