With the recent use of cameras and lidar to capture data, two different messages need to be synchronized here.
Because it's a previously recorded package, you need to set a parameter when playing.
Rosparam Set Use_sim_time True
Lower playback speed:
Rosbag play-r 0.1 stereo_camera.bag--clock --pause
In addition, because we read the image compressed, if the direct receipt of compressed data, there will be some problems. Let's say we're recording the information in the bag.
/camera_17023549/pg_17023549/image_raw/compressed
You can topic forward the data first.
Rosrun Image_transport Republish Compressed In:=/camera_17023549/pg_17023549/image_raw raw Out:=/camera_17023549/pg_ 17023549/image_raw
In this case, we only need to receive the message in CPP:
/camera_17023549/pg_17023549/image_raw
And then there's another way to do that, on the Ros wiki.
Rosparam Set/compressed_listener/image_transport Compressed
In addition, there are small techniques such as how to read a message fixframe
Rostopic Echo/horizontal_hokuyo/scan | grep frame_id
When you have a lot of information in your bag, you just want to take out a part of it and you can do it.
Rosbag filter sensor_data.bag only-tf.bag "topic = = '/camera_17023549/pg_17023549/image_raw/compressed ' or topic = = '/ Left_velodyne/velodyne_points ' "
Only two messages are kept here.
/camera_17023549/pg_17023549/image_raw/compressed and/left_velodyne/velodyne_points
Okay, let's get to the point where we start synchronizing two messages.
#include <ros/ros.h> #include <message_filters/subscriber.h> #include <message_filters/time_ synchronizer.h> #include <message_filters/sync_policies/approximate_time.h> #include <sensor_msgs/ image.h> #include <sensor_msgs/CameraInfo.h> #include <geometry_msgs/PoseStamped.h> #include <
Iostream> #include <beginner_tutorials/myNum.h> using namespace std;
using namespace Sensor_msgs;
using namespace Message_filters;
using namespace Geometry_msgs; Global variable typedef message_filters::sync_policies::approximatetime<image, image> Sync_policy_
Classification; void callback (const imageconstptr& cam_info, const imageconstptr& POS) {cout << "I should record the P"
OSE: "<< Endl;}
int main (int argc, char** argv) {ros::init (argc, argv, "msg_filter_xuqw");
Ros::nodehandle NH;
Message_filters::subscriber<image> info_sub (NH, "/camera_17082012/pg_17082012/image_raw", 1); Message_fiLters::subscriber<image> pose_sub (NH, "/camera_17082034/pg_17082034/image_raw", 1); message_filters::synchronizer<sync_policy_classification> Sync (sync_policy_classification), Info_sub,
POSE_SUB);
Timesynchronizer<camerainfo, posestamped> sync (info_sub, pose_sub, 10);
Sync.registercallback (Boost::bind (&callback, _1, _2));
Ros::spin ();
return 0; }