Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

bag file not created from launched node

Hello, I am having trouble creating a .bag file from a node when that node is executed from a launch file. However, when I execute the node by itself using rosrun, it does create the .bag file. details are below:

I have a package called "motor_driver" and in the src folder in this package I have the .cpp file orientation.cpp This creates the executable node orientation_node . Here is the .cpp file:

#include "ros/ros.h"   //provides standard ROS functions
#include "rosbag/bag.h"
#include "iostream"  //not sure if needed.
#include "string"    //needed for using std::string
#include "motor_driver/orientations.h"
#include "ros/console.h"
#include "stdlib.h"
#include "orientation.h"
#include "adjustment.h"

float roll, pitch, yaw;
float phi;

Orientation orientation;
Adjustment current;
motor_driver::orientations angles;
rosbag::Bag bag;

int main(int argc, char** argv){
        sleep(5);
        ros::init(argc,argv, "orientation_node");
        ros::NodeHandle nh;
        ros::Rate loop_rate(1);
        bag.open("test.bag", rosbag::bagmode::Write);
        while(ros::ok()){
                angles.yaw = 123.1;
                angles.phi = 456.4;
                bag.write("test_topic", ros::Time::now(), angles);
                loop_rate.sleep();
        }
        bag.close();
        ros::shutdown();
        return 0;
}

When I do run this node using: rosrun motor_driver orientation_node it creates the test.bag file

However, I have a launch file that launches this node but the test.bag file is not created. Here is my launch file:

<launch>

  <node pkg="motor_driver"   name="orientation_node"  type="orientation_node" output="screen">
  </node>

</launch>

Does anyone know why the .bag file is not created when launching the node from a .launch file?