Ask Your Question

Node is subscribed to a topic but not receiving the message

asked 2018-07-12 11:25:00 -0600

huang27c gravatar image

updated 2018-07-13 16:12:29 -0600

My hardware is Romi32U4. My serial node is a subscriber to cmd_vel topic and there's a method converts Twist to the left and right speeds. I can move the robot by manually publish Twist message.

Now, I want to use turtlebot3_teleop to publish Twist messages. I've followed e-manual tutorial to setup remote PC. According to rqt_graph, teleop is publishing to cmd_vel and serial node is subscribing to cmd_vel too. When I echo cmd_vel, I can get the values. However, serial node is not responding. The call back function is not called. I don't know why. The serial node should execute call back function when it gets a Twist message, which it is published by teleop.

This is the class:

#define USE_USBCON
#include <Romi32U4.h>
#include <ros.h>
#include <geometry_msgs/Twist.h>
#include <std_msgs/Float32.h>

Romi32U4Motors motors;

ros::NodeHandle_<ArduinoHardware, 6, 6, 150, 150> nh;
std_msgs::Float32 left_msg;
ros::Publisher left_vel_pub("chatter", &left_msg);

std_msgs::Float32 right_msg;
ros::Publisher right_vel_pub("chatter", &right_msg);

//call back
void msgTwist(const geometry_msgs::Twist& twist_msg){
  float wheel_dist = 13;

  float linear_vel = twist_msg.linear.x * 2000;
  float angle_vel = twist_msg.angular.z * 15; 

  float right_sp = (angle_vel*wheel_dist)/2 + linear_vel;
  float left_sp = linear_vel*2 - right_sp; = left_sp;
  left_vel_pub.publish( &left_msg ); = right_sp;
  right_vel_pub.publish( &right_msg );


  motors.setSpeeds(left_sp, right_sp)

ros::Subscriber<geometry_msgs::Twist> sub("cmd_vel", &msgTwist);

void setup() {

void loop() {
edit retag flag offensive close merge delete


To me this sounds like it might be a spinner issue. Have you looked into that?

Levi_Manring gravatar image Levi_Manring  ( 2018-07-12 12:07:36 -0600 )edit

Can you please explain more. Does that mean I need to modify spinOnce()?

huang27c gravatar image huang27c  ( 2018-07-12 12:15:33 -0600 )edit

Post the code that sets up the callback.

billy gravatar image billy  ( 2018-07-12 19:54:11 -0600 )edit

Hi @billy, just updated. please take a look.

huang27c gravatar image huang27c  ( 2018-07-13 08:39:08 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-07-13 09:05:05 -0600

huang27c gravatar image

I solved my own problem. The problem is the delay in the callback function. turtlebot3_teleop keeps sending messages. The delay slows down the speed of receiving the message and eventually crashed the serial node. Simply delete the delay will fix the problem.

edit flag offensive delete link more


I don't see any delays in your code.

jayess gravatar image jayess  ( 2018-07-13 14:13:22 -0600 )edit

Sorry I accidentally uploaded modified code. I've added the delay back. The delay in the call back is the problem.

huang27c gravatar image huang27c  ( 2018-07-13 16:13:05 -0600 )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


Asked: 2018-07-12 11:25:00 -0600

Seen: 694 times

Last updated: Jul 13 '18