Subscriber callback function isn't called

asked 2020-08-21 04:27:06 -0600

eed gravatar image

updated 2020-08-21 11:16:06 -0600

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 image description

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
---
....
edit retag flag offensive close merge delete

Comments

1

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 does rostopic 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...).

Delb gravatar image Delb  ( 2020-08-21 09:03:32 -0600 )edit

Hi, I added the launch file and I checked, that messages are really published (I play a prerecorded bag file and used rostopic echo)

eed gravatar image eed  ( 2020-08-21 11:12:20 -0600 )edit

Alright so to debug this you should check several things :

  • Make sure you have correctly set the ROS_MASTER_URI to the same value in each terminal.
  • With rostopic info /RosAria/pose check that your node is in the list of the subscriber nodes.
  • Do you have the message Setup completed when you create an instance of your class ?
  • Maybe add output="screen" in the tag node of your launch file
Delb gravatar image Delb  ( 2020-08-24 02:49:51 -0600 )edit
  • I checked the ROS_MASTER_URI and indeed it was different but when I set it in each terminal it doesnt change anything export ROS_MASTER_URI=http://ztm140:11311/
  • rostopic info /RosAria/cmd_vel Type: geometry_msgs/Twist

    Publishers: None

    Subscribers:

    same for /RosAria/pose

eed gravatar image eed  ( 2020-08-24 03:05:08 -0600 )edit
  • 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

    • /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..

eed gravatar image eed  ( 2020-08-24 03:07:00 -0600 )edit

In the moment when I start playing the messages I get:

[recordmodeldata-1] process has died [pid 25787, exit code -11, cmd /home/eva_die/catkin_ws/devel/lib/cause/TestNode __name:=recordmodeldata __log:=/home/eva_die/.ros/log/5bd03f7e-e5df-11ea-b3b2-f832e4a24d73/recordmodeldata-1.log].
log file: /home/eva_die/.ros/log/5bd03f7e-e5df-11ea-b3b2-f832e4a24d73/recordmodeldata-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete

the mentioned log file is empty

eed gravatar image eed  ( 2020-08-24 03:29:35 -0600 )edit
1

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 add launch-prefix="gdb" in the node tag of your launch file.

Delb gravatar image Delb  ( 2020-08-24 04:01:49 -0600 )edit

I did as you said:

Reading symbols from /home/eva_die/catkin_ws/devel/lib/cause/TestNode...done.
/home/eva_die/.ros/__name:=recordmodeldata: File or Folder not found.
eed gravatar image eed  ( 2020-08-24 05:31:29 -0600 )edit