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

Revision history [back]

click to hide/show revision 1
initial version

Your code can't compile as it is. You define cmd_vel_pub within the main function and then use it in the callback. That's not the same scope so that can't compile.

You need to define it as a global variable to use your code like this or use the publisher in a while (ros::ok()) loop in your main function and store the data in the callback with a global variable.

Anyway all the informations you gave are the result of a previous executable, since your code can't compile all your informations are related to another code that has previously been compiled. Try correcting this issue and then update all the rostopic/rosnode info with your new code (the rostopic list could be a good help too).

Your code can't compile as it is. You define cmd_vel_pub within the main function and then use it in the callback. That's not the same scope so that can't compile.

You need to define it as a global variable to use your code like this or use the publisher in a while (ros::ok()) loop in your main function and store the data in the callback with a global variable.

Anyway all the informations you gave are the result of a previous executable, since your code can't compile all your informations are related to another code that has previously been compiled. Try correcting this issue and then update all the rostopic/rosnode info with your new code (the rostopic list could be a good help too).


Edit : Glad it works for you but I would make some remarks to help you improve your code :

    ros::NodeHandle p;
    ros::NodeHandle n;
    ros::NodeHandle vel_sub;
  • You don't need different NodeHandle for each subscriber and/or publisher, you can use the same for all of them. See #q68182 for a more extensive answer/description

    ros::Subscriber sub = n.subscribe<geometry_msgs::Twist>("tele_cmd_vel", 0, negotiatorCallback);
    
  • Your subscriber as a queue size of 0, meaning it will never throw messages even if they arrive faster than the callback execution that could lead you to some troubles

    ros::Subscriber tele_cmd_vel_sub = vel_sub.subscribe<geometry_msgs::Twist>("move_base_cmd_vel", 1000, negotiatorCallback);
    
  • Is it intended to have the same callback for two subscribers ? This behavior looks like you can use a velocity multiplexer (see the wiki)

  • Instead of ros::spin() you should use this :

    while (ros::ok())
    {
        ros::spinOnce();
    }
    

This allows you do things in your loop instead of being blocked by ros::spin(). Like that you can publish data wihtin this loop instead of the callback.