0
$\begingroup$

Rosanswers logo

Hi, I've followed succesfully all basic tutorials. Then I moved to stage to work on a robot simulation. I also installed the joystick_drivers stack to use a joystick to move my virtual robot in stage. Everything is working properly (I can see the messages, topics, node graph, etc).

Right now, I tried to modify the simple subscriber 'listener' of the basic tutorials to read the information of my joystick. The problem is that the example is made for a string message.

The callback function in the tutorial is something like this: void chatterCallback(const std_msgs::String::ConstPtr& msg){ ROS_INFO("I heard: [%s]", msg->data.c_str()); }

But in the joy topic I am reading Joy messages: float32[] axes int32[] buttons

How do I manage this 'complex' messages in a correct callback function?

Thnx alot for your help!


Originally posted by marcobecerrap on ROS Answers with karma: 107 on 2011-11-20

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Add the sensor_msgs package to your dependencies in your manifest.xml with <depend package="sensor_msgs"/>, then include the appropriate C++ message header file with #include <sensor_msgs/Joy.h>, and change the callback to

void myCallback (const sensor_msgs::Joy::ConstPtr& msg)
{
  for (unsigned i = 0; i < msg->axes.size(); ++i) {
    ROS_INFO("Axis %d is now at position %f", i, msg->axes[i]);
  }
}

Originally posted by roehling with karma: 1951 on 2011-11-20

This answer was ACCEPTED on the original site

Post score: 6


Original comments

Comment by marcobecerrap on 2011-11-21:
Hi Röhling, thank you very much for your help!!! Your answer was the explanation that I needed. Now everything is working just perfect!!! Thanks alot!

$\endgroup$

Your Answer

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