Ask Your Question

Void callback subscriber does not work [closed]

asked 2015-05-11 05:21:21 -0500

Alvaro Salcedo gravatar image

updated 2015-05-11 05:22:23 -0500

Hi Ros users

i would like to send odometry (just linear and angular velocity) to another IP via socket udp.

But I have a problem. The problem is that void velsubcallback is not executed and I do not why.. (The catkin_make is ok)

This is my .cpp and my int main (but i think we have to focus on while):

 void velsubcallback(const nav_msgs::Odometry& msg)
         ROS_INFO("variable %f",lectura_ros.linear);        

int main(int argc, char **argv)

int va_send_to;
int long_dir_cli;
int socket_ros; 
struct sockaddr_in dir_serv_socket,dir_cli_socket;
  ros::init(argc, argv, "lanzando_vel");
  ros::NodeHandle n;
    while (ros::ok())

      ros::Subscriber odom_sub = n.subscribe("p3dx/odom", 1000, velsubcallback);

    va_send_to = sendto(socket_ros,(char *)&lectura_ros,sizeof(dato_ros),0,(struct sockaddr *)&dir_cli_socket,sizeof(dir_cli_socket));

Any idea??

Thank you so much!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alvaro Salcedo
close date 2015-05-12 05:29:02.206099


Have you checked, that data gets published on this topic?

BennyRe gravatar image BennyRe  ( 2015-05-11 05:42:33 -0500 )edit

First of all, thanks!

Yes, I have. Data is publishing on this topic but the problem is that void velsub callback is not executed

Alvaro Salcedo gravatar image Alvaro Salcedo  ( 2015-05-11 06:01:24 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-05-11 07:08:07 -0500

Wolf gravatar image

Move your

  ros::Subscriber odom_sub = n.subscribe("p3dx/odom", 1000, velsubcallback);

outside the while loop. the subscriber only needs to be created once! And be sure to call ros::spinOnce() in your loop. This is the point code code where your callback are actually called!

edit flag offensive delete link more


Thank you so much. That is work!!

Alvaro Salcedo gravatar image Alvaro Salcedo  ( 2015-05-12 05:27:59 -0500 )edit

Question Tools

1 follower


Asked: 2015-05-11 05:21:21 -0500

Seen: 471 times

Last updated: May 11 '15