0
$\begingroup$

Rosanswers logo

Hi,

I've written a node with publishes (Successfully) and subscribes to cmd_vel messages. Problem I'm getting is that the call back is never being called. C++ code is very simple, as per tutorial - abridged version below:

#include <ros/ros.h>
#include <sensor_msgs/JointState.h>
#include <sensor_msgs/Range.h>
#include <sensor_msgs/LaserScan.h>
#include <diagnostic_updater/diagnostic_updater.h>
#include <std_msgs/Bool.h>
#include <diagnostic_updater/publisher.h>
#include <geometry_msgs/Twist.h>

// For moving the robot on the map
#include <tf/transform_broadcaster.h>
#include <nav_msgs/Odometry.h>

#include "Consts.h" 
#include "RobotInterface.h"
#include "NetworkInterface.h"

void cmd_vel_callback(const geometry_msgs::Twist& vel_cmd)
{ 
ROS_INFO("I heard: [%s]", vel_cmd.linear.y);
cout << "Twist Received " << endl;
}

int main( int argc, char* argv[] )
{
ros::init(argc, argv, "toeminator_publisher" );

ros::NodeHandle n_("~");
ros::NodeHandle n("");
ros::NodeHandle lSubscriber("");
ros::NodeHandle nIR("");
ros::NodeHandle nLaser("");
ros::Rate loop_rate(10);
    ros::Subscriber sub = lSubscriber.subscribe("/cmd_vel", 1000, cmd_vel_callback);

ros::Time current_time, last_time;
current_time = ros::Time::now();
last_time = ros::Time::now();

RobotData lRobotData;

while( n.ok() ) 
{
    ros::spin();
}

return 1;
}

The python publisher is basically the turtlebot's keyboard publisher and running rtq_graph shows the message link between the publisher and subscriber as expected (below) and "rostopic echo /cmd_vel" shows the message flowing

image description

Not sure where I've gone wrong here. Would welcome any pointers.

Kind Regards

Mark

EDIT: Updated with full code. Also I neglected to mention (apologies) that the roscore and the C++ processes are running on a different machine to where the teleop keyboard process is running. That said publishing from the roscore machine to rviz etc on the telop machine is working with out issue (ROS_IP is set to the IP addresses of the respective machines - as mentioned in the networking setup tutorials)


Originally posted by MarkyMark2012 on ROS Answers with karma: 1834 on 2014-02-15

Post score: 0


Original comments

Comment by Pedro_85 on 2014-02-15:
Can you please copy the rest of the code? That can help

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Based on the fact that when you run rostopic echo /cmd_vel you are able to get the information, I created a basic version of your code and it seems to be working for me:

#include <ros/ros.h>
#include <geometry_msgs/Twist.h>

void cmd_vel_callback(const geometry_msgs::Twist& vel_cmd)
{ 
    ROS_INFO("I heard: [%f]", vel_cmd.linear.y);
    std::cout << "Twist Received " << std::endl;
}


int main( int argc, char* argv[] )
{
ros::init(argc, argv, "toeminator_publisher" );

ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("/cmd_vel", 1000, cmd_vel_callback);

while( n.ok() ) 
{
    ros::spin();
}

return 1;
}

I changed ROS_INFO("I heard: [%s]", vel_cmd.linear.y); to ROS_INFO("I heard: [%f]", vel_cmd.linear.y); because it was giving me an Segmentation fault error message. Make sure you have added the geometry_msgs to your dependencies. I hope this helps. Good luck!


Originally posted by Pedro_85 with karma: 182 on 2014-02-16

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by MarkyMark2012 on 2014-02-26:
Hi - Thanks for the help. I've had a chance to play around with this some more.It seem to have something to do with the fact that I'm running across two machines. Running roscore on the same machine and it all works.Put roscore on another machine (With ROS_IP set) then nothing. Although ros_topic and rqt_graph see everything

$\endgroup$
0
$\begingroup$

Rosanswers logo

Ok so found the problem. Whilst the ROS_IP addresses were set correctly I'm running the heavy weight ROS side on a virtual box and the sensor/actuator side on rasp pi. It was the network setup of the VM it was set to NAT - changed it to bridged. Now all is well.

Thanks

Mark


Originally posted by MarkyMark2012 with karma: 1834 on 2014-02-28

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.