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

Subscriber Callback not being triggered when JointState message is passed

asked 2019-01-28 06:33:38 -0600

cr055 gravatar image

updated 2019-01-28 12:05:53 -0600

Dear all,

I have come across a strange problem; maybe it's just something simple, but I am not really good at ROS programming.

Explaining the problem: I am using the rosserial package on Arduino Mega to log data and apply control inputs to a set of servos.

In order to do that, I created a subscriber as follows:

void controlCallback(const sensor_msgs::JointState& servo_des_states);
ros::Subscriber<sensor_msgs::JointState> control_sub("controlInput", controlCallback);

void setup(){

void controlCallback(const sensor_msgs::JointState& servo_des_states){

    servoRadians = servo_des_states.position;
    sendControlInput(RadToPWM(servoRadians), controlSpeed);
    digitalWrite(13, HIGH-digitalRead(13));

when invoking the it lists that the subscriber is active and listening on the right topic:

cr055@cr055:~/catkin_ws$ rosrun rosserial_python /dev/ttyACM0 _baud:=115200
[INFO] [1548676899.466166]: ROS Serial Python Node
[INFO] [1548676899.471357]: Connecting to /dev/ttyACM0 at 115200 baud
[INFO] [1548676901.575863]: Requesting topics...
[INFO] [1548676904.505507]: Note: publish buffer size is 512 bytes
[INFO] [1548676904.505995]: Setup publisher on /tf [tf/tfMessage]
[INFO] [1548676904.509778]: Note: subscribe buffer size is 1024 bytes
[INFO] [1548676904.510289]: Setup subscriber on controlInput [sensor_msgs/JointState]

Although it seems everything correctly set up, the callback does not get triggered when I publish the mentioned messages.

If I try to send another kind of message (redefining the subscriber type and callback), for instance Float32, it works flawlessly.

It seems that the problem comes out when I use more complex kinds of messages (like sensor_msgs or MultiArray).

I hope someone has any clue about what's wrong here.

TL;DR: the callback function in the subscriber does not get invoked if the message type is multidimensional like JointState or Float32MultiArray. If I use simple floats I get the callback working.

UPDATE which might help: if I publish only a vector of two elements e.g. {position:[0,0]} the callback works. Am I missing something in the declaration of the published message?

UPDATE #2: I think that the arduino serial cannot handle packages as big as JointState if I publish 18 servos all together. Still, a workaround / alternative to publish 18 float values is welcome.



edit retag flag offensive close merge delete


I think that the arduino serial cannot handle packages as big as JointState if I publish 18 servos all together.

have you looked at increasing the buffer size on the Arduino side? By default it's only 512 bytes IIRC.

Search for posts with similar topics. It should be clear from those.

gvdhoorn gravatar image gvdhoorn  ( 2019-01-28 12:07:51 -0600 )edit

Hi, I'm experiences exactly the same problem. Increasing the buffer does not make a difference. Has anyone been able to solve this?

Bifi gravatar image Bifi  ( 2020-01-20 06:27:27 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-01-28 07:50:59 -0600

curi_ROS gravatar image

To access the data from the message, you need to use:

servoRadians = servo_des_states->position;
edit flag offensive delete link more


Thanks!The modification you suggested gives me the following error:

base operand of '->' has non-pointer type 'const sensor_msgs::JointState'

As you can see from the code I toggle a led if I enter the callback. The led never goes on even if the RX serial pin flashes. The problem is somewhere else

cr055 gravatar image cr055  ( 2019-01-28 10:05:55 -0600 )edit

servo_des_states is not a pointer here so the dot operator must be used, original code is correct.

VictorLamoine gravatar image VictorLamoine  ( 2019-01-28 16:37:57 -0600 )edit

Question Tools



Asked: 2019-01-28 06:33:38 -0600

Seen: 587 times

Last updated: Jan 28 '19