# How to control a Robot?

Hello Everyone!

How to control a Robot?

I creat this robot and not know how to move this

A lot of thanks!!

edit retag close merge delete

Sort by » oldest newest most voted

you have a few tutorials on older versions. the underscores used to set text to italic are making a few typos, make sure to notice them

1-this tutorial shows how to set the model velocities. http://gazebosim.org/wiki/Tutorials/1.3/intermediate/control_model for the above tutorial you might also find this usefull.

// *** QUATERNION / POSE DATA ******

  static double qw,qx,qy,qz, Rrad, Prad, Yrad;
math::Vector3 p = model->GetWorldPose().pos;
math::Quaternion r = model->GetWorldPose().rot;
//from quaternion to Roll Pitch Yaw, in radians
qw=r.w;   qx=r.x;     qy=r.y;     qz=r.z;


// ***************

        //set velocities

float velx,vely;
this->model->SetLinearVel(math::Vector3(velx, vely, 0));
this->model->SetAngularVel(math::Vector3(0, 0, Vang));


// ***************

2- or you can control the model using aplying joint forces, but this needs a robot with joints as wheels http://gazebosim.org/wiki/Tutorials/1.3/controlrobot/mobilebase

hope this helps.

more

Hey, I have a question related to controlling the robot from the keyboard. I made a rosenabled plugin to control the robot using the following method in this answer, by subscribing the twist type of msgs. http://answers.gazebosim.org/question/1991/what-is-the-best-way-to0-learn-gazebo-in-ros-for/ I am using groovy, and gazebo 1.9.1 with gazebo _rospckgs is there a way to use the keyboard-teleop to control the robot (turtlebot) from the keyboard manually instead. thanks in advance!

( 2013-09-24 12:38:00 -0500 )edit

the idea should be the same, the robot should have the topics for the vel comands, you just need to edit whatever controller (or the plugin) your using to publish the velocity commands to those topics. you can also change the plugin to match the controllers topics, whatever u see fit, they just need to match. in the same link at the end i sugest the use of one keyboard controller and to edit the controller to publish to the respective topics.

( 2013-09-24 21:35:12 -0500 )edit

for example, if you have a controller publishing twist messages to "robot2/cmdvel" topic then you can change the plugin from "gz/cmdvel" to the same topic by changing the string name1 of the plugin from "gz" to "robot2". in case of a single robot it usualy does not have prefix so if you change the string name1 to "" (empty string) you will get the topic "/cmdvel". hope i was clear enough :S

( 2013-09-24 21:40:16 -0500 )edit

for example, if you have a controller publishing twist messages to "robot2/cmdvel" topic then you can change the plugin from "gz/cmdvel" to the same topic by changing the string name1 of the plugin from "gz" to "robot2". in case of a single robot it usualy does not have prefix so if you change the string name1 to "" (empty string) you will get the topic "/cmdvel". hope i was clear enough :S

( 2013-09-24 21:40:26 -0500 )edit

get a error:

Error [Plugin.hh:127] Failed to load plugin mypluginwithsensor.so: mypluginwithsensor.so: cannot open shared object file: No such file or directory

( 2013-09-28 14:50:40 -0500 )edit

GAugusto, thanks for replying! I followed your instructions but still I cannot control the robot with keyboard manually, thats what I have done:

a description for the published topics of turtlebot , one of them is turtlebottelopkeyboard/cmd_vel (<<msglink2(geometry_msgs twist)&gt;&gt;)="" <="" p="">

I changed the string name in my plugin :

from: std::string name = "gz";

to : std::string name = "turtlebotteleopkeyboard";

subscriber :

  this->sub = this->node->subscribe<geometry_msgs::Twist>("cmd_vel",10, boost::bind(&ROSMotorControllerPlugin::ROSCallback, this , _1));


Then, I started gazebo from roslunch since I am using gazeborospckgs

roslaunch package_name file.launch

I checked the rostopic list and this what I found /gazebo/cmd_vel I managed to control it with this line command but not manually :

rostopic pub -1 /gazebo/cmdvel geometrymsgs/Twist '{linear: { x: -0.040}}'

then I tried to change the topic name from "cmdvel" to “turtlebotteleopkeyboard/cmdvel “ and keeping the string name as it is “gz” , in rostopic list I got

/gazebo/turtlebotteleopkeyboard/cmd_vel

also, it didnt work with keyboard.

Note: I did all the above again when launching gazebo as “gazebo file.world” and also no change. So can you plz tell me what I am missing here?

Thanks a lot!

more

hmm, launch only the turtle bot controller, then type rostopic list and put here the topics it creates pls

( 2013-09-25 10:37:26 -0500 )edit

The topics :

with string name as std::string name = "turtlebotteleopkeyboard"; I started gazebo as : roslaunch package_name file.launch

( 2013-09-25 10:51:23 -0500 )edit

change the "gz" to "turtlebottelopkeyboard" this is needed. to create the correct cmd vel topic.

i was using verison 1.5 and ROS fuerte, maybe on new versions the prefix "gazebo is always added. try also to change the published topic on the teleop controller by adding "gazebo" before "turtlebottelopkeyboard/cmdvel" to get "gazebo/turtlebottelopkeyboard/cmdvel" from the controller.

( 2013-09-25 10:54:36 -0500 )edit

the topics once more are here since they are hard to read in the comment!

The topics :

/clock

/gazebo/cmd_vel

/gazebo/model_states

/gazebo/parameter_descriptions

/gazebo/setmodelstate

/rosout

/rosout_agg

with string name as std::string name = "turtlebotteleopkeyboard";

I started gazebo as : roslaunch package_name file.launch

more

those seam to be gazebo topics, did you use the "rostopic list" command or "gztopic list"?

( 2013-09-25 11:01:19 -0500 )edit

I used rostopic list

( 2013-09-25 11:14:53 -0500 )edit

I used rostopic list

( 2013-09-25 11:15:08 -0500 )edit

ok, then try looking abit into the turtle bot controller for "turtlebottelopkeyboard/cmdvel" and change it to "gazebo/cmdvel". then try again.

( 2013-09-25 11:27:43 -0500 )edit

Hello, from the turtlebot stack there is turltebotteleop src files https://github.com/turtlebot/turtlebotapps/blob/groovy/turtlebotteleop/src/turtlebotkey.cpp

I changed the turtlebotkey.cpp file, line 75 from: velpub_ = nh.advertise<geometrymsgs::Twist>("cmdvel", 1); to: velpub_ = nh.advertise<geometrymsgs::Twist>("/gazebo/cmd_vel", 1);

still not working, Any other ideas? many thanks

( 2013-09-26 05:32:16 -0500 )edit

i dont really see what to do, the objective should be to match the topics names. i suspect that somewhere both gazebo and turtlebot are adding prefixs by default, and thats where it needs changing :/ sorry i cant be of much more help.

( 2013-09-26 08:52:33 -0500 )edit

btw something i remembered, i think you can change the name of topics with launch files, could be good to give it a look just to be safe. or just rosrun the turtlebot_key.cpp manualy and see what topics u get.

( 2013-09-26 08:54:48 -0500 )edit

or just rosrun the turtlebot_key.cpp manualy and see what topics u get.

( 2013-09-26 08:57:54 -0500 )edit

you can also try using http://wiki.ros.org/teleoptwistkeyboard , change the cmgvel to gazebo/cmdvel and see what topics you get

( 2013-09-26 09:00:48 -0500 )edit

Changing the string names or the topic names didn’t work with me at all, but I managed to work around this prob by writing my own C++ program which is based on this tutorial and it worked just fine http://wiki.ros.org/pr2controllers/Tutorials/Using%20the%20robot%20base%20controllers%20to%20drive%20the%20robot#CA-1426c28b03091e68ce47656633f2c51ad6982d6867

( 2013-10-02 02:51:21 -0500 )edit

3 ways to do that: - develop a "Gazebo plugin", which is a C++ calling Gazebo API (answer from iche033). The robot models do not need to be modified. - use ROS and gazeborospkgs, in this case the URDF or SDF model should be adapted, w. <gazebo> tags and so on, as described in the gazebo-ROS tutorial - player and do not know how the model should be modified

I may help with solution 2.

more

Great!, Could you help me with Gazebo API?

A lot of thanks!

( 2013-09-28 17:47:33 -0500 )edit

I suggest to start with the rrbot tutorial and post your questions. This tuto contained anything that I needed. You may need several hours to master all the concepts if you start from scratch.

( 2013-09-29 10:18:06 -0500 )edit

Can you please tell how to control the model without ROS or plugin. I want to control using API only. Thank you.

( 2015-05-11 02:21:14 -0500 )edit

When to used:

http://gazebosim.org/wiki/Tutorials/1.3/controlrobot/mobilebase

Or

http://gazebosim.org/wiki/Tutorials/1.3/controlrobot/mobilebase_laser

Get a similar error:

Error [Plugin.hh:127] Failed to load plugin libmypluginwithsensor.so: mypluginwithsensor.so: cannot open shared object file: No such file or directory

more