Ask Your Question

How to make a realtime controller get information

asked 2012-10-12 00:22:16 -0500

arzhed gravatar image

updated 2013-06-05 03:15:52 -0500

130s gravatar image

Hi guys

So I have a robot simulated in Gazebo that I can control with the realtime controllers I made thanks to the tutorials. I also added a service and a PID controller as in the tutorials (which doesnt work good for every controller, but that's another topic!).

Since I want to have a "smart navigation" with the robot, I tried getting information from the ros topic published by gazebo : ModelStates. It gives you position, orientation, velocity... So I made my controller subscribe to that topic the following way (no need to give the whole code).

#include "leftwheelcontroller/leftwcontrol.h"
#include <pluginlib/class_list_macros.h>
#include <ros/ros.h>
#include <gazebo_msgs/ModelStates.h>
#include <boost/shared_ptr.hpp>

namespace controller_ns {

bool lwControllerClass::init(pr2_mechanism_model::RobotState *robot,  ros::NodeHandle &n)

void lwControllerClass::starting()

void lwControllerClass::update()
   ROS_INFO("lefwcontrol : lWEffort= %f",  lWEffort);

void lwControllerClass::stopping()

/// Service call to set effort applied on the wheel
bool lwControllerClass::setEffort(leftwheelcontroller::SetEffort::Request& req,leftwheelcontroller::SetEffort::Response& resp)

void lwControllerClass::chatterCallback(const gazebo_msgs::ModelStates::ConstPtr& msg)
    ROS_INFO("lwController heard this effort set: %f", lWEffort);

} // namespace

int main(int argc, char **argv)
  ros::init(argc, argv, "lwController");
  ros::NodeHandle n;

  lw_controller_ns::lwControllerClass *p= new lw_controller_ns::lwControllerClass;
  ros::Subscriber sub = n.subscribe("gazebo/model_states", (uint)1000, &lw_controller_ns::lwControllerClass::chatterCallback,p);


  return 0;

So the callback output gives me the position of the robot (as it is supposed to do), but the update function loop give me "-0.0". I just guess that such subscription can not be done in real time...?

In a way or another, I'd like to get navigation information. I looked at a few things :

  • Navigation stack / Odometry which I don't know if it works in realtime
  • realtime_tools that seems to enable a controller to publish topics, but not to subscribe...
  • GazeboRosIMU plugin and the following answer, but I tried and it seems it just publishes a topic.
  • It seems there is "getModelState" service from Gazebo that may give information such as the "modelstate" topic, but i dont know how to get it, nor how to send it to my RT controller.

Any answer to these questions, or any suggestion is very welcome!

Update : I may build a non real time controller, but in this case (if RT is a dead-end), what tools should I use? pr2_controller_manager or pr2_mechanism_model are realtime specific, and a solution involving topics subscribed by gazebo might be a bit low-level.


edit retag flag offensive close merge delete


Ok sorry, since I wrote this question, the website suggested me that answer :

arzhed gravatar image arzhed  ( 2012-10-12 00:29:06 -0500 )edit

I reopened this question because suggestions might actually be very welcome! Also, I'm not sure of the meaning of "realtime safe" : does it only means that it is not to use in hard RT process, or that you can NOT get ANY information from non realtime thread?

arzhed gravatar image arzhed  ( 2012-10-14 23:19:54 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2012-11-07 02:25:38 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I tried everything and it seems that the only way is to advertise a service. It seems a realtime controller can neither subscribe to a topic nor send a request to another service. It can publish a topic thanks to the realtime_tools package though.

For instance : to get information from gazebo, I made an intermediate node that subscribes to topics published by gazebo and sends service requests to the controller. That's the only I found.

edit flag offensive delete link more


Hi, Arthur S. i was trying to do a node that communicate me topics that published by node creating in arduino.. can u tell me how u did the node that u're talkin about? thnks.

monidiaz gravatar image monidiaz  ( 2012-11-12 22:55:54 -0500 )edit

I dont understand what you exactly want to do, just know that I use gazebo and I've never used ROS on Arduino so I'll probably wont be very useful to u. So what is your question exactly? Maybe u should try this tutorial :

arzhed gravatar image arzhed  ( 2012-11-13 03:02:05 -0500 )edit

the thing that i want finally is move something in gazebo ,reading a value for a sensor that i'm reading since Arduino, arduino can publish these values on a topic , and now i want that gazebo can read or receive that value, i look the tutorial but doesn't very helpful, :/

monidiaz gravatar image monidiaz  ( 2012-11-13 03:10:09 -0500 )edit

did you take a look at Gazebo wiki? There is the list of all services, topics and most plugins available with gazebo in ros, especially the /apply_joint_effort service. But as far as I know, you can not apply speed or position directly in gazebo (except in gazebo gui) since its a physics simulator

arzhed gravatar image arzhed  ( 2012-11-13 03:25:03 -0500 )edit

I would recommend a more "high level" solution, such as the pr2_controller_manager if needed, or at list a non-realtime controller node that might apply forces in a right way, but i guess it is what you wanna do with your arduino board.

arzhed gravatar image arzhed  ( 2012-11-13 03:28:00 -0500 )edit

Or you may create your own gazebo plugin if you need to.

arzhed gravatar image arzhed  ( 2012-11-13 03:53:40 -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

1 follower


Asked: 2012-10-12 00:22:16 -0500

Seen: 1,286 times

Last updated: Nov 07 '12