25 #include <sensor_msgs/Image.h>
26 #include <sensor_msgs/Imu.h>
37 std::shared_ptr<VioManager>
sys;
38 std::shared_ptr<ROS1Visualizer>
viz;
41 int main(
int argc,
char **argv) {
44 std::string config_path =
"unset_path_to_config.yaml";
46 config_path = argv[1];
50 ros::init(argc, argv,
"ros1_serial_msckf");
51 auto nh = std::make_shared<ros::NodeHandle>(
"~");
52 nh->param<std::string>(
"config_path", config_path, config_path);
55 auto parser = std::make_shared<ov_core::YamlParser>(config_path);
56 parser->set_node_handler(nh);
59 std::string verbosity =
"INFO";
60 parser->parse_config(
"verbosity", verbosity);
69 sys = std::make_shared<VioManager>(params);
70 viz = std::make_shared<ROS1Visualizer>(nh,
sys);
73 if (!parser->successful()) {
75 std::exit(EXIT_FAILURE);
83 std::string topic_imu;
84 nh->param<std::string>(
"topic_imu", topic_imu,
"/imu0");
85 parser->parse_external(
"relative_config_imu",
"imu0",
"rostopic", topic_imu);
86 PRINT_DEBUG(
"[SERIAL]: imu: %s\n", topic_imu.c_str());
89 std::vector<std::string> topic_cameras;
91 std::string cam_topic;
92 nh->param<std::string>(
"topic_camera" + std::to_string(i), cam_topic,
"/cam" + std::to_string(i) +
"/image_raw");
93 parser->parse_external(
"relative_config_imucam",
"cam" + std::to_string(i),
"rostopic", cam_topic);
94 topic_cameras.emplace_back(cam_topic);
95 PRINT_DEBUG(
"[SERIAL]: cam: %s\n", cam_topic.c_str());
99 std::string path_to_bag;
100 nh->param<std::string>(
"path_bag", path_to_bag,
"/home/patrick/datasets/eth/V1_01_easy.bag");
101 PRINT_DEBUG(
"[SERIAL]: ros bag path is: %s\n", path_to_bag.c_str());
105 std::map<double, Eigen::Matrix<double, 17, 1>> gt_states;
106 if (nh->hasParam(
"path_gt")) {
107 std::string path_to_gt;
108 nh->param<std::string>(
"path_gt", path_to_gt,
"");
109 if (!path_to_gt.empty()) {
111 PRINT_DEBUG(
"[SERIAL]: gt file path is: %s\n", path_to_gt.c_str());
117 double bag_start, bag_durr;
118 nh->param<
double>(
"bag_start", bag_start, 0);
119 nh->param<
double>(
"bag_durr", bag_durr, -1);
120 PRINT_DEBUG(
"[SERIAL]: bag start: %.1f\n", bag_start);
121 PRINT_DEBUG(
"[SERIAL]: bag duration: %.1f\n", bag_durr);
144 view.
addQuery(bag, time_init, time_finish);
147 if (view.
size() == 0) {
158 double max_camera_time = -1;
159 std::vector<rosbag::MessageInstance> msgs;
163 if (msg.getTopic() == topic_imu) {
172 if (msg.getTopic() == topic_cameras.at(i)) {
181 max_camera_time = std::max(max_camera_time, msg.getTime().toSec());
185 PRINT_DEBUG(
"[SERIAL]: total of %zu messages!\n", msgs.size());
192 std::set<int> used_index;
193 for (
int m = 0; m < (int)msgs.size(); m++) {
196 if (!
ros::ok() || msgs.at(m).getTime() > time_finish || msgs.at(m).getTime().
toSec() > max_camera_time)
198 if (msgs.at(m).getTime() < time_init)
202 if (used_index.find(m) != used_index.end()) {
208 if (msgs.at(m).getTopic() == topic_imu) {
210 viz->callback_inertial(msgs.at(m).instantiate<sensor_msgs::Imu>());
217 if (msgs.at(m).getTopic() != topic_cameras.at(cam_id))
223 std::map<int, int> camid_to_msg_index;
224 double meas_time = msgs.at(m).getTime().toSec();
226 if (cam_idt == cam_id) {
227 camid_to_msg_index.insert({cam_id, m});
230 int cam_idt_idx = -1;
231 for (
int mt = m; mt < (int)msgs.size(); mt++) {
232 if (msgs.at(mt).getTopic() != topic_cameras.at(cam_idt))
234 if (std::abs(msgs.at(mt).getTime().toSec() - meas_time) < 0.02)
238 if (cam_idt_idx != -1) {
239 camid_to_msg_index.insert({cam_idt, cam_idt_idx});
245 PRINT_DEBUG(
YELLOW "[SERIAL]: Unable to find stereo pair for message %d at %.2f into bag (will skip!)\n" RESET, m,
246 meas_time - time_init.
toSec());
251 Eigen::Matrix<double, 17, 1> imustate;
255 sys->initialize_with_gt(imustate);
261 viz->callback_monocular(msgs.at(camid_to_msg_index.at(0)).instantiate<sensor_msgs::Image>(), 0);
263 auto msg0 = msgs.at(camid_to_msg_index.at(0));
264 auto msg1 = msgs.at(camid_to_msg_index.at(1));
265 used_index.insert(camid_to_msg_index.at(0));
266 used_index.insert(camid_to_msg_index.at(1));
267 viz->callback_stereo(msg0.instantiate<sensor_msgs::Image>(), msg1.instantiate<sensor_msgs::Image>(), 0, 1);
269 PRINT_ERROR(
RED "[SERIAL]: We currently only support 1 or 2 camera serial input....\n" RESET);
278 viz->visualize_final();