Rosbags saving empty messages
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;
}
Asked by stevenjediknight on 2019-02-22 18:26:17 UTC
Answers
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.
Asked by gvdhoorn on 2019-02-23 02:44:51 UTC
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.
Asked by stevenjediknight on 2019-02-25 11:29:34 UTC
Personally I would still use rosbag
and then afterwards post-process that into a .csv
file, but it's up to you of course.
Asked by gvdhoorn on 2019-02-25 12:06:11 UTC
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.
Asked by stevenjediknight on 2019-02-25 15:13:40 UTC
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 -- ..
Asked by gvdhoorn on 2019-02-25 15:16:03 UTC
.. reimplement what rosbag
already does.
Asked by gvdhoorn on 2019-02-25 15:16:16 UTC
Comments