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

How to make a realtime controller get information

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

arzhed gravatar image

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

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)
{
    lWEffort=msg->pose[1].position.x;
    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);

  ros::spin();

  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.

UP

edit retag flag offensive close merge delete

Comments

Ok sorry, since I wrote this question, the website suggested me that answer : http://answers.ros.org/question/9423/which-ways-of-communicating-with-a-controller-are-real-time-safe/

arzhed gravatar image arzhed  ( 2012-10-12 00:29:06 -0600 )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 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
0

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

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

Comments

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 -0600 )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 : http://www.ros.org/wiki/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29

arzhed gravatar image arzhed  ( 2012-11-13 03:02:05 -0600 )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 -0600 )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 -0600 )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 -0600 )edit

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

arzhed gravatar image arzhed  ( 2012-11-13 03:53:40 -0600 )edit

@arzhed sorry to bring up this old question, but it seems like Subscriber callbacks will happen, just not inside the realtime thread (the answer you linked in your comment below the question also indicates that). Another example is the force_example_controller from the franka_ros/franka_example_controllers package, which uses a dynamic_reconfigure callback to get some parameters.

samarth.robo gravatar image samarth.robo  ( 2020-12-21 15:30:19 -0600 )edit
0

answered 2022-06-26 11:37:37 -0600

hmccarty gravatar image

Ignore the old answers published in this thread. The realtime_tools package provides everything you need to do this. If you want to subscribe to a rostopic from your controller, you can use a RealtimeBuffer. An example of this can be found in the ackermann steering controller.

edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 1,878 times

Last updated: Nov 07 '12