-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrosbag_edit.cpp
64 lines (59 loc) · 3.09 KB
/
rosbag_edit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
///rosbag rewrite, and reorganize data by header timestamp
///support sensor_msgs::IMU CompressedImage,livox_ros_driver::CustomMsg and sensor_msgs::Imu
///Create Time: 2022.6.12
///Update Time: 2022.11.10: IMU msg preprocess, change the coordinate system and change degree to rad for helmet data
///Update Time: 2023.04.16: provide the option for organizing date by the receive order when recording. You can comment(uncomment) the bag_out.write() function for using it.
///Author: Weitong Wu, Wuhan University
///Contact: wwtgeomatics@gmail.com
#include <livox_ros_driver/CustomMsg.h>
#include <ros/ros.h>
#include <rosbag/bag.h>
#include <rosbag/view.h>
#include <sensor_msgs/CompressedImage.h>
#include <sensor_msgs/Imu.h>
using namespace std;
int main(int argc, char **argv) {
std::string bag_in_path = argv[1];
std::string bag_out_path = argv[2];
rosbag::Bag bag_in, bag_out;
bag_in.open(bag_in_path);
bag_out.open(bag_out_path, rosbag::bagmode::Write);
for (auto &m : rosbag::View(bag_in)) {
if (m.isType<sensor_msgs::Imu>()) {
sensor_msgs::Imu imu_msg = *m.instantiate<sensor_msgs::Imu>();
sensor_msgs::Imu imu_msg_tmp = *m.instantiate<sensor_msgs::Imu>();
if (0)
{
//for Avia
imu_msg.angular_velocity.x = -imu_msg_tmp.angular_velocity.y / 180.0 * M_PI;
imu_msg.angular_velocity.y = -imu_msg_tmp.angular_velocity.z / 180.0 * M_PI;
imu_msg.angular_velocity.z = imu_msg_tmp.angular_velocity.x / 180.0 * M_PI;
imu_msg.linear_acceleration.x = -imu_msg_tmp.linear_acceleration.y;
imu_msg.linear_acceleration.y = -imu_msg_tmp.linear_acceleration.z;
imu_msg.linear_acceleration.z = imu_msg_tmp.linear_acceleration.x;
}else{
//for Mid70
imu_msg.angular_velocity.x = imu_msg_tmp.angular_velocity.y / 180.0 * M_PI;
imu_msg.angular_velocity.y = imu_msg_tmp.angular_velocity.z / 180.0 * M_PI;
imu_msg.angular_velocity.z = imu_msg_tmp.angular_velocity.x / 180.0 * M_PI;
imu_msg.linear_acceleration.x = imu_msg_tmp.linear_acceleration.y;
imu_msg.linear_acceleration.y = imu_msg_tmp.linear_acceleration.z;
imu_msg.linear_acceleration.z = imu_msg_tmp.linear_acceleration.x;
}
//bag_out.write("/imu0", imu_msg.header.stamp, imu_msg);
bag_out.write("/imu0", m.getTime(), imu_msg);
}
if (m.isType<livox_ros_driver::CustomMsg>()) {
auto lidar_msg = m.instantiate<livox_ros_driver::CustomMsg>();
//bag_out.write("/livox/lidar", lidar_msg->header.stamp, lidar_msg);
bag_out.write("/livox/lidar", m.getTime(), lidar_msg);
}
if(m.isType<sensor_msgs::CompressedImage>()){
auto image_msg = m.instantiate<sensor_msgs::CompressedImage>();
//bag_out.write("/camera0/compressed", image_msg->header.stamp, image_msg);
bag_out.write("/camera0/compressed", m.getTime(), image_msg);
}
}
bag_in.close();
bag_out.close();
}