Subscriber callback function isn't called
Hi everyone, I'm trying to get an older project working again. There I have an subscriber which saves the data to a file unfortunately the callback function isnt called. The rqt_graph showes, that there are the right connections and even messages are published
The project is quite large so I hope i have everything included here.
TestNode.cpp:
#include <ros/ros.h>
#include "utils/Log.h"
#include "guidance/Test.h"
int main(int argc, char** argv){
// Init ROS
ros::init( argc, argv, "paramIdent" );
// Create ROS node
l_inf( "Creating ROS node... " );
ros::NodeHandle node( "/cause/guidupdate" );
// Creating datarecorder
l_inf( "Creating datarecorder..." );
cause::Test recordData( &node );
// Loop
l_inf( "Processing..." );
while(ros::ok()) ros::spinOnce();
l_inf( "Done." );
return 0;
}
Test.cpp
#include "utils/Log.h"
#include "cause_msgs/Deviation.h"
#include "utils/Timestamp.h"
#include "guidance/Test.h"
#include "utils/PoseSE3.h"
#include <thread>
#include <future>
#include <math.h>
#include <memory>
#include <geometry_msgs/Point.h>
#include <geometry_msgs/Quaternion.h>
#include <geometry_msgs/TwistStamped.h>
#include <geometry_msgs/PoseStamped.h>
#include <std_msgs/Bool.h>
namespace cause {
Test::Test(ros::NodeHandle *node) :
m_node(node) {
m_controlSub = m_node->subscribe("/RosAria/cmd_vel", 1000, &Test::GetControlCallback, this);
m_odomSub = m_node->subscribe("/RosAria/pose", 1000, &Test::GetOdometryCallback, this);
l_inf("Setup completed");
}
void Test::GetControlCallback(const geometry_msgs::TwistConstPtr &control)
{
l_inf("Entering Callback");
}
void Test::GetOdometryCallback(const nav_msgs::OdometryConstPtr &odometry)
{
l_inf("Entering Odometry Callback");
}
UPDATE
RecordData.launch
<launch>
<node pkg="cause" type="TestNode" name="recordmodeldata" />
</launch>
.
rostopic echo /RosAria/cmd_vel
linear:
x: 0.7
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: -0.5
---
linear:
x: 0.7
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: -0.5
---
....
The
rqt_graph
shows indeed that the topic are connected but you can't ensure they are actually publishing. Indeed there is a connection between the topics you try to subscribe to and your node but doesrostopic echo /RosAria/pose
output something ?I've tried your code and it worked so you might need to give more information avout what you are doing exactly (commands, launch files, error message if any etc...).
Hi, I added the launch file and I checked, that messages are really published (I play a prerecorded bag file and used rostopic echo)
Alright so to debug this you should check several things :
ROS_MASTER_URI
to the same value in each terminal.rostopic info /RosAria/pose
check that your node is in the list of the subscriber nodes.Setup completed
when you create an instance of your class ?output="screen"
in the tagnode
of your launch fileexport ROS_MASTER_URI=http://ztm140:11311/
rostopic info /RosAria/cmd_vel Type: geometry_msgs/Twist
Publishers: None
Subscribers:
same for /RosAria/pose
roslaunch record_data Recorddata.launch
... logging to /home/eva_die/.ros/log/5bd03f7e-e5df-11ea-b3b2-f832e4a24d73/roslaunch-ztm140-24831.log Checking log directory for disk usage. This may take awhile. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://ztm140:44379/
SUMMARY
PARAMETERS
ROS_MASTER_URI=http://ztm140:11311/ process[recordmodeldata-1]: started with pid [24849] /home/eva_die/catkin_ws/devel/lib/cause/testNode: /home/evadie/Programme/anaconda3/lib/libuuid.so.1: no version information available (required by /usr/lib/x86_64-linux-gnu/libapr-1.so.0)
[ INFO] [1598256177.560002592]: Creating ROS node...
[ INFO] [1598256177.566174218]: Creating datarecorder...
[ INFO] [1598256177.570789654]: Setup completed
[ INFO] [1598256177.570822473]: Processing..
In the moment when I start playing the messages I get:
the mentioned log file is empty
So you do have an error message you should have start with this first. The node dying once you start publishing the messages means that there is something wrong with the implementation of your callbacks, how are they defined in your header file ? Try using
gdb
to see what happen when you enter in the callback function : You need to compile in debug mode (catkin_make -DCMAKE_BUILD_TYPE=Debug
) and then addlaunch-prefix="gdb"
in thenode
tag of your launch file.I did as you said: