Ask Your Question

how to get states (position and velocity) from the simple box robot ?

asked 2011-12-09 01:31:05 -0500

maruchi gravatar image

Hi, I have simple box robot model which is controlled by keyboard teleop in the gazebo environment. The next step I want to do is putting a simple feedback controller. The first thing I need to do is to get robot model states (position and velocity of center of gravity of the simple box robot model). And the next step I think is that the keyboard teleop should subscribe the states.

Are these procedures are right? If then, could you let me know how to get the robot model states ? Should I have put robot state publisher into robot urdf ? If there is appropriate link or tutorial, please let me know.

And if there is other way for me to do a feedback control for the simple box robot, please let me know.

edit retag flag offensive close merge delete


What is the goal of the feedback? Are you trying to give the robot a position and have it move there? Or are you trying to obtain a certain speed?
DimitriProsser gravatar image DimitriProsser  ( 2011-12-09 01:53:08 -0500 )edit
Dimitri, the current goal is a tracking for given trajectory. I have one more question for subscribing in the teleop. What should I do to subscribe the states (position and velocity) in the teleop cpp file which has currently just publisher. I have just limited knowledge of C++ but keeping learning.
maruchi gravatar image maruchi  ( 2011-12-09 02:53:56 -0500 )edit
I've edited my answer to include this information.
DimitriProsser gravatar image DimitriProsser  ( 2011-12-09 03:43:24 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2011-12-09 01:57:06 -0500

DimitriProsser gravatar image

updated 2011-12-09 03:42:54 -0500

If you want to get the position of the robot, the easiest way to do that is with the position_3d controller. Add the following to your urdf file:

  <controller:gazebo_ros_p3d name="p3d_base_controller" plugin="">
    <xyzOffsets>0 0 0</xyzOffsets> 
    <rpyOffsets>0 0 0</rpyOffsets>
    <interface:position name="p3d_base_position"/>

Change "base_link" to the link you'd like to know the position of, and change "base_pose_ground_truth" to the topic that you wish to publish to. Then, if you subscribe to that topic in your teleop node, you can see the link's absolute position relative to the Gazebo world (0,0,0) coordinate. This message is nav_msgs/Odometry. It will give you position and velocity.

To subscribe to this topic, you can use something like the following in teleop.cpp:

ros::Subscriber base_pose_sub_ = node_.subscribe<nav_msgs::Odometry> ("base_pose_ground_truth", 100, &Teleop::GroundTruthCallback, this);

You can find more on subscribers here. You can find a description of the nav_msgs::Odometry message here.

edit flag offensive delete link more


DimitriProsser, I really appreciate you for the help. I will get back as soon as I implement your directions.
maruchi gravatar image maruchi  ( 2011-12-09 02:22:19 -0500 )edit
Dimitri, the current robot model is simple sliding box and forces applied to the model through teleop. What I am trying to do is to subscribe the robot states and to make a simple trajectory following controller in the keboard.cpp in the teleop. Do I still need to use nav_msgs/Odeometry ?
maruchi gravatar image maruchi  ( 2011-12-09 03:42:49 -0500 )edit
If you want to track the position and velocity of your robot, you can use either geometry_msgs/Pose or nav_msgs/Odometry as the easiest. The reason that Odometry is good is because this Gazebo controller is already written for you. You cannot change the message type without re-writing the controller
DimitriProsser gravatar image DimitriProsser  ( 2011-12-09 03:46:06 -0500 )edit
Thanks Dimitri. I still have a difficulty in inserting a subscriber in the keyboard.cpp of teleop due to my limited knowledge of C++. Could you give me some comment on the below code ?
maruchi gravatar image maruchi  ( 2011-12-11 07:55:32 -0500 )edit

I don't know if this is old syntax or what, but to get this to work I had to use this syntax: <plugin name="p3d_base_controller" filename=""> instead of <controller:gazebo_ros_p3d...

Neil Traft gravatar image Neil Traft  ( 2015-08-16 18:12:15 -0500 )edit

Hi guys, I have a similar problem. I am also using a Husky A200 and in the urdf I added the controller like Dimitri said above. Now how should my GroundTruthCallback() look like so that I can read the current robot position and vel information from gazebo ? Please help.

ktiwari9 gravatar image ktiwari9  ( 2015-08-25 02:03:01 -0500 )edit

This syntax is deprecated and no longer supported in Gazebo 1.9.x and ROS Hydro. Does anybody know of a more recent version of doing this ?

ktiwari9 gravatar image ktiwari9  ( 2015-08-25 02:28:48 -0500 )edit

The message is of type nav_msgs/Odometry so it should look like any ROS callback, except replace the message pointer type with nav_msgs::Odometry::ConstPtr. The URDF syntax worked for me in Hydro/Gazebo 1.9, but you might need to also comment out this line that begins: <interface:position...

Neil Traft gravatar image Neil Traft  ( 2015-08-25 03:44:57 -0500 )edit

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: 2011-12-09 01:31:05 -0500

Seen: 2,563 times

Last updated: Dec 11 '11