odometry messages to C++ node silently dropped
I'm sure this is something silly, but I'm stumped and would really appreciate some help.
I was writing a node that needs to consume odometry messages, and I just couldn't get it to actually consume the messages. (By that I mean that I can rostopic pub ...
a message and a rostopic echo ...
will show that it has been sent, but my subscriber callback method isn't called.) I have trimmed my code down to a small ROS package and posted it on GitHub ( https://github.com/sambishop/aav-ros-... ), but I will also post it below.
The problem seems to be related to nav_msgs/Odometry
messages somehow. If I modify the code to consume std_msgs/String
messages instead, then it works. Also, this code works on one of my computers, the one stuck on Hydro, but not on my computer running Indigo.
QuinticControl.h:
#include "nav_msgs/Odometry.h"
#include "ros/ros.h"
namespace aav_control {
class QuinticControl {
public:
void updateOdometry(const nav_msgs::Odometry::ConstPtr &odometry);
};
}
QuinticControl.cpp:
#include "QuinticControl.h"
using namespace aav_control;
void QuinticControl::updateOdometry(const nav_msgs::Odometry::ConstPtr &odometry) {
fprintf(stderr, "updateOdometry() called\n");
}
main.cpp:
#include "QuinticControl.h"
#include "ros/ros.h"
int main(int argc, char **argv) {
ros::init(argc, argv, "aav_control2");
ros::NodeHandle node;
aav_control::QuinticControl control;
ros::Subscriber subscriber = node.subscribe(
"odometry/filtered",
1000,
&aav_control::QuinticControl::updateOdometry,
&control
);
ros::spin();
return 0;
}
This is my rostopic
command:
rostopic pub /odometry/filtered nav_msgs/Odometry -f src/aav_control2/odom_.1_.5.yaml
EDIT 1
This is the output of rosnode
:
$ rosnode info /aav_control2
--------------------------------------------------------------------------------
Node [/aav_control2]
Publications:
* /rosout [rosgraph_msgs/Log]
Subscriptions:
* /odometry/filtered [unknown type]
Services:
* /aav_control2/get_loggers
* /aav_control2/set_logger_level
contacting node http://turbo:36683/ ...
Pid: 7592
Connections:
* topic: /rosout
* to: /rosout
* direction: outbound
* transport: TCPROS
Here is the version using std_msgs::String
that works:
QuinticControl.h:
#include "std_msgs/String.h"
#include "ros/ros.h"
namespace aav_control {
class QuinticControl {
public:
void updateOdometry(const std_msgs::String::ConstPtr &odometry);
};
}
QuinticControl.cpp:
#include "QuinticControl.h"
using namespace aav_control;
void QuinticControl::updateOdometry(const std_msgs::String::ConstPtr &odometry) {
fprintf(stderr, "updateOdometry() called\n");
}
And the rostopic
command:
rostopic pub /odometry/filtered std_msgs/String 'hello'
When that is run, the "updateOdometry() called" message is written to the console. You can see that I have only modified the callback method signature and the #include
. Unless there's a problem with the way I'm using rostopic
?
I have verified the works-with-strings/doesn't-work-with-odometry-messages on a second computer running Indigo. Unfortunately, I don't have easy access to a second computer running Hydro.
can you verify using
rosnode info
your node really subscribes to the correct topic/odometry/filtered
?Good question. I have edited my question, adding that and other information. Thank you!
Are you sure your message is not malformed via the YAML file?
I don't think
rostopic
will publish a malformed message, and I am able torostopic pub
androstopic echo
the message (using Indigo) without errors or warnings. I have also confirmed again that all of this, including the C++ code, works with Hydro.Did you copy you yaml file from your hydro PC? Maybe the definition of the nav_msgs::Odometry changed between both versions??
I did. I created it manually there, and used the error messages from
rostopic
to tell me when it was malformed. It seems like the message is okay though given thatrostopic
on Indigo has no problem sending or receiving it.rostopic does plot you the message even if it is outdated! Your really have to check the md5sum for being sure the message can be received by your subscriber.
I believe that the MD5 sum would only matter if it was a bag file. But
rosmsg md5 nav_msgs/Odometry
returnscd5e73d190d741a2f92e81eda573aca7
on both Indigo and Hydro, so it doesn't look like the message format has changed anyways.