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

Void callback subscriber does not work [closed]

asked 2015-05-11 05:21:21 -0600

Alvaro Salcedo gravatar image

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

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)
   {  
    variable1=msg.twist.twist.linear.x;
    variable2=msg.twist.twist.angular.z;
 lectura_ros.linear=variable1;
 lectura_ros.angular=variable2;
         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

Comments

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

BennyRe gravatar image BennyRe  ( 2015-05-11 05:42:33 -0600 )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 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

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

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

Comments

Thank you so much. That is work!!

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

Question Tools

1 follower

Stats

Asked: 2015-05-11 05:21:21 -0600

Seen: 640 times

Last updated: May 11 '15