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
---
....
Asked by eed on 2020-08-21 04:27:06 UTC
Comments
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...).
Asked by Delb on 2020-08-21 09:03:32 UTC
Hi, I added the launch file and I checked, that messages are really published (I play a prerecorded bag file and used rostopic echo)
Asked by eed on 2020-08-21 11:12:20 UTC
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 fileAsked by Delb on 2020-08-24 02:49:51 UTC
export ROS_MASTER_URI=http://ztm140:11311/
Publishers: None
Subscribers: * /recordmodeldata (http://ztm140:39469/)
same for /RosAria/pose
Asked by eed on 2020-08-24 03:05:08 UTC
... 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 * /rosdistro: kinetic * /rosversion: 1.12.14 NODES / recordmodeldata (cause/TestNode)
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..
Asked by eed on 2020-08-24 03:07:00 UTC
In the moment when I start playing the messages I get:
the mentioned log file is empty
Asked by eed on 2020-08-24 03:29:35 UTC
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.Asked by Delb on 2020-08-24 04:01:49 UTC
I did as you said:
Asked by eed on 2020-08-24 05:31:29 UTC
So what happen when you enter the callback function ?
Asked by Delb on 2020-08-24 05:56:37 UTC
It now works. I don't know exactly why but I found out, that when I separated this recorder from the hole project I forgot to change one occurrence so I still loaded something old.
Thank you a lot for your support!!
Asked by eed on 2020-08-24 06:08:30 UTC
Plus 1 for coming back and explaining what happened instead of leaving Delb hanging after so much work.
Asked by billy on 2020-08-24 21:11:36 UTC