0
$\begingroup$

Rosanswers logo

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


Originally posted by arzhed on ROS Answers with karma: 143 on 2012-10-12

Post score: 2


Original comments

Comment by arzhed on 2012-10-12:
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/

Comment by arzhed on 2012-10-14:
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?

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by arzhed with karma: 143 on 2012-11-07

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by monidiaz on 2012-11-12:
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.

Comment by arzhed on 2012-11-13:
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

Comment by monidiaz on 2012-11-13:
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, :/

Comment by arzhed on 2012-11-13:
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

Comment by arzhed on 2012-11-13:
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.

Comment by arzhed on 2012-11-13:
Or you may create your own gazebo plugin if you need to.

Comment by samarth.robo on 2020-12-21:
@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.

$\endgroup$

Your Answer

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