ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Rosbags saving empty messages

asked 2019-02-22 17:26:17 -0500

stevenjediknight gravatar image

updated 2019-02-22 18:52:41 -0500

jayess gravatar image

I am trying to record data from data from a Razor 9DOF imu, Hokuyo LIDAR and a ZED camera. The code compiles and runs fine but it is saving empty messages to the rosbag file. I have tried printing data in at different points and it wont. Can you tell me what my code is missing and why the messages are empty? I am running ROS kinetic 1.12.14 on Ubuntu 16.04 on an Nvidia Jetson TX2.

#include <iostream>
#include <ros/ros.h>
#include <rosbag/bag.h>
#include <sensor_msgs/Imu.h>
#include <sensor_msgs/LaserScan.h>
#include <sensor_msgs/Image.h>

sensor_msgs::Imu    imu_msg;
sensor_msgs::LaserScan scan;
sensor_msgs::Image msgr;
sensor_msgs::Image msgl;

   void imuCallback(const sensor_msgs::Imu &imu_msg)
  {

  }

  void scanCallback(const sensor_msgs::LaserScan::ConstPtr& scan)
  {

  }

  void imageRightRectifiedCallback(const sensor_msgs::Image &msgr) {

  }

  void imageLeftRectifiedCallback(const sensor_msgs::Image &msgl) {

  }


int main(int argc, char** argv){

    ros::init(argc, argv, "talker"); 
    ros::NodeHandle n; 

    rosbag::Bag bag; // create a bag named bag 
    bag.open("data.bag", rosbag::bagmode::Write); //open bag and create a file to save to.


    ros::Subscriber imu_sub = n.subscribe("imu_data", 1000, imuCallback); // subscribes to the imu and start the callback function
    ros::Subscriber sub = n.subscribe<sensor_msgs::LaserScan>("/scan", 1000, scanCallback); // subscribes to the lidar and start the callback function
    // subscribes to the zed and get the right image and start the callback function
    ros::Subscriber subRightRectified = n.subscribe("/zed/right/image_rect_color", 10, imageRightRectifiedCallback); 
    // subscribes to the zed and get the left image and start the callback function
    ros::Subscriber subLeftRectified = n.subscribe("/zed/left/image_rect_color", 10, imageLeftRectifiedCallback); 
   while(ros::ok()){
       bag.write("imu", ros::Time::now(), imu_msg); // sending msg into the bag
       bag.write("lidar", ros::Time::now(), scan);
       bag.write("ZED_RightImage", ros::Time::now(), msgr);
       bag.write("ZED_LeftImage", ros::Time::now(), msgl);



        ROS_INFO("Recording data...");
        ros::spinOnce();
    }
    bag.close();
    return 0;
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-02-23 01:44:51 -0500

gvdhoorn gravatar image

Where in your code are you storing incoming msgs in the imu_msg, scan, msgr and msgl global variables?

The bodies of your callbacks are empty, so incoming msgs are never actually processed.


Also: is there any reason you cannot use rosbag itself? That would seem to already be capable of what you are showing here, but without any custom code.

edit flag offensive delete link more

Comments

Sorry could not work on this over the weekend. I assumed const sensor_msgs::LaserScan::ConstPtr& scan would store in the global variables i will try doing tin the call back function. the reason I am writing this is to run one command and have a rosbag for playback and .cvs files.

stevenjediknight gravatar image stevenjediknight  ( 2019-02-25 10:29:34 -0500 )edit

Personally I would still use rosbag and then afterwards post-process that into a .csv file, but it's up to you of course.

gvdhoorn gravatar image gvdhoorn  ( 2019-02-25 11:06:11 -0500 )edit

It's still not working even after saving the data from callback messages to the global variables. It seems like my callbacks are return empty messages even though i cant rostopic ech /imu and see my data.

stevenjediknight gravatar image stevenjediknight  ( 2019-02-25 14:13:40 -0500 )edit

It could probably work, but you are ros::spinOnce()-ing at the absolute maximum frequency your PC supports (no sleep) which most likely results in many, many duplicate msgs.

Without seeing updated code we cannot help you, but I would say again that it's a little strange to -- basically -- ..

gvdhoorn gravatar image gvdhoorn  ( 2019-02-25 14:16:03 -0500 )edit

.. reimplement what rosbag already does.

gvdhoorn gravatar image gvdhoorn  ( 2019-02-25 14:16:16 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-02-22 17:26:17 -0500

Seen: 259 times

Last updated: Feb 23 '19