0
$\begingroup$

Rosanswers logo

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.


Originally posted by maruchi on ROS Answers with karma: 157 on 2011-12-09

Post score: 1


Original comments

Comment by DimitriProsser on 2011-12-09:
I've edited my answer to include this information.

Comment by maruchi on 2011-12-09:
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.

Comment by DimitriProsser on 2011-12-09:
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?

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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:

<gazebo>
  <controller:gazebo_ros_p3d name="p3d_base_controller" plugin="libgazebo_ros_p3d.so">
    <alwaysOn>true</alwaysOn>
    <updateRate>100.0</updateRate>
    <bodyName>base_link</bodyName>
    <topicName>base_pose_ground_truth</topicName>
    <gaussianNoise>0</gaussianNoise>
    <frameName>map</frameName>
    <xyzOffsets>0 0 0</xyzOffsets> 
    <rpyOffsets>0 0 0</rpyOffsets>
    <interface:position name="p3d_base_position"/>
  </controller:gazebo_ros_p3d>
</gazebo>

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](http://www.ros.org/wiki/ROS/Tutorials/WritingPublisherSubscriber(c%2B%2B). You can find a description of the nav_msgs::Odometry message here.


Originally posted by DimitriProsser with karma: 11163 on 2011-12-09

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by maruchi on 2011-12-11:
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 ? http://answers.ros.org/question/3274/how-to-add-a-subscriber-in-keyboard-teleop

Comment by DimitriProsser on 2011-12-09:
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

Comment by maruchi on 2011-12-09:
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 ?

Comment by maruchi on 2011-12-09:
DimitriProsser, I really appreciate you for the help. I will get back as soon as I implement your directions.

Comment by Neil Traft on 2015-08-16:
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="libgazebo_ros_p3d.so"> instead of <controller:gazebo_ros_p3d...

Comment by ktiwari9 on 2015-08-25:
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.

Comment by ktiwari9 on 2015-08-25:
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 ?

Comment by Neil Traft on 2015-08-25:
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...

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.