34 #if ROS_AVAILABLE == 1
35 sensor_msgs::PointCloud2 ROSVisualizerHelper::get_ros_pointcloud(
const std::vector<Eigen::Vector3d> &feats) {
38 sensor_msgs::PointCloud2 cloud;
39 cloud.header.frame_id =
"global";
41 cloud.width = feats.size();
43 cloud.is_bigendian =
false;
44 cloud.is_dense =
false;
48 modifier.setPointCloud2FieldsByString(1,
"xyz");
49 modifier.resize(feats.size());
57 for (
const auto &pt : feats) {
58 *out_x = (float)pt(0);
60 *out_y = (float)pt(1);
62 *out_z = (float)pt(2);
69 tf::StampedTransform ROSVisualizerHelper::get_stamped_transform_from_pose(
const std::shared_ptr<ov_type::PoseJPL> &pose,
bool flip_trans) {
72 Eigen::Vector4d q_ItoC = pose->quat();
73 Eigen::Vector3d p_CinI = pose->pos();
75 p_CinI = -pose->Rot().transpose() * pose->pos();
85 tf::Vector3 orig(p_CinI(0), p_CinI(1), p_CinI(2));
91 #if ROS_AVAILABLE == 2
92 sensor_msgs::msg::PointCloud2 ROSVisualizerHelper::get_ros_pointcloud(std::shared_ptr<rclcpp::Node> node,
93 const std::vector<Eigen::Vector3d> &feats) {
96 sensor_msgs::msg::PointCloud2 cloud;
97 cloud.header.frame_id =
"global";
98 cloud.header.stamp = node->now();
99 cloud.width = feats.size();
101 cloud.is_bigendian =
false;
102 cloud.is_dense =
false;
106 modifier.setPointCloud2FieldsByString(1,
"xyz");
107 modifier.resize(feats.size());
115 for (
const auto &pt : feats) {
116 *out_x = (float)pt(0);
118 *out_y = (float)pt(1);
120 *out_z = (float)pt(2);
127 geometry_msgs::msg::TransformStamped ROSVisualizerHelper::get_stamped_transform_from_pose(std::shared_ptr<rclcpp::Node> node,
128 const std::shared_ptr<ov_type::PoseJPL> &pose,
132 Eigen::Vector4d q_ItoC = pose->quat();
133 Eigen::Vector3d p_CinI = pose->pos();
135 p_CinI = -pose->Rot().transpose() * pose->pos();
141 geometry_msgs::msg::TransformStamped trans;
142 trans.header.stamp = node->now();
143 trans.transform.rotation.x = q_ItoC(0);
144 trans.transform.rotation.y = q_ItoC(1);
145 trans.transform.rotation.z = q_ItoC(2);
146 trans.transform.rotation.w = q_ItoC(3);
147 trans.transform.translation.x = p_CinI(0);
148 trans.transform.translation.y = p_CinI(1);
149 trans.transform.translation.z = p_CinI(2);
155 std::ofstream &of_state_est, std::ofstream &of_state_std,
156 std::ofstream &of_state_gt) {
160 double t_ItoC = state->_calib_dt_CAMtoIMU->value()(0);
161 double timestamp_inI = state->_timestamp + t_ItoC;
164 if (
sim !=
nullptr) {
168 Eigen::Matrix<double, 17, 1> state_gt;
169 timestamp_inI = state->_timestamp +
sim->get_true_parameters().calib_camimu_dt;
170 if (
sim->get_state(timestamp_inI, state_gt)) {
172 of_state_gt.precision(5);
173 of_state_gt.setf(std::ios::fixed, std::ios::floatfield);
174 of_state_gt << state_gt(0) <<
" ";
175 of_state_gt.precision(6);
176 of_state_gt << state_gt(1) <<
" " << state_gt(2) <<
" " << state_gt(3) <<
" " << state_gt(4) <<
" ";
177 of_state_gt << state_gt(5) <<
" " << state_gt(6) <<
" " << state_gt(7) <<
" ";
178 of_state_gt << state_gt(8) <<
" " << state_gt(9) <<
" " << state_gt(10) <<
" ";
179 of_state_gt << state_gt(11) <<
" " << state_gt(12) <<
" " << state_gt(13) <<
" ";
180 of_state_gt << state_gt(14) <<
" " << state_gt(15) <<
" " << state_gt(16) <<
" ";
183 of_state_gt.precision(7);
184 of_state_gt <<
sim->get_true_parameters().calib_camimu_dt <<
" ";
185 of_state_gt.precision(0);
186 of_state_gt << state->_options.num_cameras <<
" ";
187 of_state_gt.precision(6);
190 assert(state->_options.num_cameras ==
sim->get_true_parameters().state_options.num_cameras);
191 for (
int i = 0; i < state->_options.num_cameras; i++) {
193 of_state_gt <<
sim->get_true_parameters().camera_intrinsics.at(i)->get_value()(0) <<
" "
194 <<
sim->get_true_parameters().camera_intrinsics.at(i)->get_value()(1) <<
" "
195 <<
sim->get_true_parameters().camera_intrinsics.at(i)->get_value()(2) <<
" "
196 <<
sim->get_true_parameters().camera_intrinsics.at(i)->get_value()(3) <<
" ";
197 of_state_gt <<
sim->get_true_parameters().camera_intrinsics.at(i)->get_value()(4) <<
" "
198 <<
sim->get_true_parameters().camera_intrinsics.at(i)->get_value()(5) <<
" "
199 <<
sim->get_true_parameters().camera_intrinsics.at(i)->get_value()(6) <<
" "
200 <<
sim->get_true_parameters().camera_intrinsics.at(i)->get_value()(7) <<
" ";
202 of_state_gt <<
sim->get_true_parameters().camera_extrinsics.at(i)(0) <<
" " <<
sim->get_true_parameters().camera_extrinsics.at(i)(1)
203 <<
" " <<
sim->get_true_parameters().camera_extrinsics.at(i)(2) <<
" "
204 <<
sim->get_true_parameters().camera_extrinsics.at(i)(3) <<
" ";
205 of_state_gt <<
sim->get_true_parameters().camera_extrinsics.at(i)(4) <<
" " <<
sim->get_true_parameters().camera_extrinsics.at(i)(5)
206 <<
" " <<
sim->get_true_parameters().camera_extrinsics.at(i)(6) <<
" ";
210 of_state_gt.precision(0);
211 of_state_gt <<
sim->get_true_parameters().state_options.imu_model <<
" ";
212 of_state_gt.precision(8);
214 of_state_gt <<
sim->get_true_parameters().vec_dw(0) <<
" " <<
sim->get_true_parameters().vec_dw(1) <<
" "
215 <<
sim->get_true_parameters().vec_dw(2) <<
" " <<
sim->get_true_parameters().vec_dw(3) <<
" "
216 <<
sim->get_true_parameters().vec_dw(4) <<
" " <<
sim->get_true_parameters().vec_dw(5) <<
" ";
217 of_state_gt <<
sim->get_true_parameters().vec_da(0) <<
" " <<
sim->get_true_parameters().vec_da(1) <<
" "
218 <<
sim->get_true_parameters().vec_da(2) <<
" " <<
sim->get_true_parameters().vec_da(3) <<
" "
219 <<
sim->get_true_parameters().vec_da(4) <<
" " <<
sim->get_true_parameters().vec_da(5) <<
" ";
220 of_state_gt <<
sim->get_true_parameters().vec_tg(0) <<
" " <<
sim->get_true_parameters().vec_tg(1) <<
" "
221 <<
sim->get_true_parameters().vec_tg(2) <<
" " <<
sim->get_true_parameters().vec_tg(3) <<
" "
222 <<
sim->get_true_parameters().vec_tg(4) <<
" " <<
sim->get_true_parameters().vec_tg(5) <<
" "
223 <<
sim->get_true_parameters().vec_tg(6) <<
" " <<
sim->get_true_parameters().vec_tg(7) <<
" "
224 <<
sim->get_true_parameters().vec_tg(8) <<
" ";
225 of_state_gt <<
sim->get_true_parameters().q_GYROtoIMU(0) <<
" " <<
sim->get_true_parameters().q_GYROtoIMU(1) <<
" "
226 <<
sim->get_true_parameters().q_GYROtoIMU(2) <<
" " <<
sim->get_true_parameters().q_GYROtoIMU(3) <<
" ";
227 of_state_gt <<
sim->get_true_parameters().q_ACCtoIMU(0) <<
" " <<
sim->get_true_parameters().q_ACCtoIMU(1) <<
" "
228 <<
sim->get_true_parameters().q_ACCtoIMU(2) <<
" " <<
sim->get_true_parameters().q_ACCtoIMU(3) <<
" ";
243 of_state_est.precision(5);
244 of_state_est.setf(std::ios::fixed, std::ios::floatfield);
245 of_state_est << timestamp_inI <<
" ";
246 of_state_est.precision(6);
247 of_state_est << state->_imu->quat()(0) <<
" " << state->_imu->quat()(1) <<
" " << state->_imu->quat()(2) <<
" " << state->_imu->quat()(3)
249 of_state_est << state->_imu->pos()(0) <<
" " << state->_imu->pos()(1) <<
" " << state->_imu->pos()(2) <<
" ";
250 of_state_est << state->_imu->vel()(0) <<
" " << state->_imu->vel()(1) <<
" " << state->_imu->vel()(2) <<
" ";
251 of_state_est << state->_imu->bias_g()(0) <<
" " << state->_imu->bias_g()(1) <<
" " << state->_imu->bias_g()(2) <<
" ";
252 of_state_est << state->_imu->bias_a()(0) <<
" " << state->_imu->bias_a()(1) <<
" " << state->_imu->bias_a()(2) <<
" ";
255 of_state_std.precision(5);
256 of_state_std.setf(std::ios::fixed, std::ios::floatfield);
257 of_state_std << timestamp_inI <<
" ";
258 of_state_std.precision(6);
259 int id = state->_imu->q()->id();
260 of_state_std << std::sqrt(cov(
id + 0,
id + 0)) <<
" " << std::sqrt(cov(
id + 1,
id + 1)) <<
" " << std::sqrt(cov(
id + 2,
id + 2)) <<
" ";
261 id = state->_imu->p()->id();
262 of_state_std << std::sqrt(cov(
id + 0,
id + 0)) <<
" " << std::sqrt(cov(
id + 1,
id + 1)) <<
" " << std::sqrt(cov(
id + 2,
id + 2)) <<
" ";
263 id = state->_imu->v()->id();
264 of_state_std << std::sqrt(cov(
id + 0,
id + 0)) <<
" " << std::sqrt(cov(
id + 1,
id + 1)) <<
" " << std::sqrt(cov(
id + 2,
id + 2)) <<
" ";
265 id = state->_imu->bg()->id();
266 of_state_std << std::sqrt(cov(
id + 0,
id + 0)) <<
" " << std::sqrt(cov(
id + 1,
id + 1)) <<
" " << std::sqrt(cov(
id + 2,
id + 2)) <<
" ";
267 id = state->_imu->ba()->id();
268 of_state_std << std::sqrt(cov(
id + 0,
id + 0)) <<
" " << std::sqrt(cov(
id + 1,
id + 1)) <<
" " << std::sqrt(cov(
id + 2,
id + 2)) <<
" ";
271 of_state_est.precision(7);
272 of_state_est << state->_calib_dt_CAMtoIMU->value()(0) <<
" ";
273 of_state_est.precision(0);
274 of_state_est << state->_options.num_cameras <<
" ";
275 of_state_est.precision(6);
278 if (state->_options.do_calib_camera_timeoffset) {
279 of_state_std << std::sqrt(cov(state->_calib_dt_CAMtoIMU->id(), state->_calib_dt_CAMtoIMU->id())) <<
" ";
281 of_state_std << 0.0 <<
" ";
283 of_state_std.precision(0);
284 of_state_std << state->_options.num_cameras <<
" ";
285 of_state_std.precision(6);
288 for (
int i = 0; i < state->_options.num_cameras; i++) {
290 of_state_est << state->_cam_intrinsics.at(i)->value()(0) <<
" " << state->_cam_intrinsics.at(i)->value()(1) <<
" "
291 << state->_cam_intrinsics.at(i)->value()(2) <<
" " << state->_cam_intrinsics.at(i)->value()(3) <<
" ";
292 of_state_est << state->_cam_intrinsics.at(i)->value()(4) <<
" " << state->_cam_intrinsics.at(i)->value()(5) <<
" "
293 << state->_cam_intrinsics.at(i)->value()(6) <<
" " << state->_cam_intrinsics.at(i)->value()(7) <<
" ";
295 of_state_est << state->_calib_IMUtoCAM.at(i)->value()(0) <<
" " << state->_calib_IMUtoCAM.at(i)->value()(1) <<
" "
296 << state->_calib_IMUtoCAM.at(i)->value()(2) <<
" " << state->_calib_IMUtoCAM.at(i)->value()(3) <<
" ";
297 of_state_est << state->_calib_IMUtoCAM.at(i)->value()(4) <<
" " << state->_calib_IMUtoCAM.at(i)->value()(5) <<
" "
298 << state->_calib_IMUtoCAM.at(i)->value()(6) <<
" ";
300 if (state->_options.do_calib_camera_intrinsics) {
301 int index_in = state->_cam_intrinsics.at(i)->id();
302 of_state_std << std::sqrt(cov(index_in + 0, index_in + 0)) <<
" " << std::sqrt(cov(index_in + 1, index_in + 1)) <<
" "
303 << std::sqrt(cov(index_in + 2, index_in + 2)) <<
" " << std::sqrt(cov(index_in + 3, index_in + 3)) <<
" ";
304 of_state_std << std::sqrt(cov(index_in + 4, index_in + 4)) <<
" " << std::sqrt(cov(index_in + 5, index_in + 5)) <<
" "
305 << std::sqrt(cov(index_in + 6, index_in + 6)) <<
" " << std::sqrt(cov(index_in + 7, index_in + 7)) <<
" ";
307 of_state_std << 0.0 <<
" " << 0.0 <<
" " << 0.0 <<
" " << 0.0 <<
" ";
308 of_state_std << 0.0 <<
" " << 0.0 <<
" " << 0.0 <<
" " << 0.0 <<
" ";
310 if (state->_options.do_calib_camera_pose) {
311 int index_ex = state->_calib_IMUtoCAM.at(i)->id();
312 of_state_std << std::sqrt(cov(index_ex + 0, index_ex + 0)) <<
" " << std::sqrt(cov(index_ex + 1, index_ex + 1)) <<
" "
313 << std::sqrt(cov(index_ex + 2, index_ex + 2)) <<
" ";
314 of_state_std << std::sqrt(cov(index_ex + 3, index_ex + 3)) <<
" " << std::sqrt(cov(index_ex + 4, index_ex + 4)) <<
" "
315 << std::sqrt(cov(index_ex + 5, index_ex + 5)) <<
" ";
317 of_state_std << 0.0 <<
" " << 0.0 <<
" " << 0.0 <<
" ";
318 of_state_std << 0.0 <<
" " << 0.0 <<
" " << 0.0 <<
" ";
323 of_state_est.precision(0);
324 of_state_est << state->_options.imu_model <<
" ";
325 of_state_est.precision(8);
326 of_state_std.precision(0);
327 of_state_std << state->_options.imu_model <<
" ";
328 of_state_std.precision(8);
331 of_state_est << state->_calib_imu_dw->value()(0) <<
" " << state->_calib_imu_dw->value()(1) <<
" " << state->_calib_imu_dw->value()(2)
332 <<
" " << state->_calib_imu_dw->value()(3) <<
" " << state->_calib_imu_dw->value()(4) <<
" "
333 << state->_calib_imu_dw->value()(5) <<
" ";
334 if (state->_options.do_calib_imu_intrinsics) {
335 int index_dw = state->_calib_imu_dw->id();
336 of_state_std << std::sqrt(cov(index_dw + 0, index_dw + 0)) <<
" " << std::sqrt(cov(index_dw + 1, index_dw + 1)) <<
" "
337 << std::sqrt(cov(index_dw + 2, index_dw + 2)) <<
" " << std::sqrt(cov(index_dw + 3, index_dw + 3)) <<
" "
338 << std::sqrt(cov(index_dw + 4, index_dw + 4)) <<
" " << std::sqrt(cov(index_dw + 5, index_dw + 5)) <<
" ";
340 of_state_std << 0.0 <<
" " << 0.0 <<
" " << 0.0 <<
" ";
341 of_state_std << 0.0 <<
" " << 0.0 <<
" " << 0.0 <<
" ";
345 of_state_est << state->_calib_imu_da->value()(0) <<
" " << state->_calib_imu_da->value()(1) <<
" " << state->_calib_imu_da->value()(2)
346 <<
" " << state->_calib_imu_da->value()(3) <<
" " << state->_calib_imu_da->value()(4) <<
" "
347 << state->_calib_imu_da->value()(5) <<
" ";
348 if (state->_options.do_calib_imu_intrinsics) {
349 int index_da = state->_calib_imu_da->id();
350 of_state_std << std::sqrt(cov(index_da + 0, index_da + 0)) <<
" " << std::sqrt(cov(index_da + 1, index_da + 1)) <<
" "
351 << std::sqrt(cov(index_da + 2, index_da + 2)) <<
" " << std::sqrt(cov(index_da + 3, index_da + 3)) <<
" "
352 << std::sqrt(cov(index_da + 4, index_da + 4)) <<
" " << std::sqrt(cov(index_da + 5, index_da + 5)) <<
" ";
354 of_state_std << 0.0 <<
" " << 0.0 <<
" " << 0.0 <<
" ";
355 of_state_std << 0.0 <<
" " << 0.0 <<
" " << 0.0 <<
" ";
359 of_state_est << state->_calib_imu_tg->value()(0) <<
" " << state->_calib_imu_tg->value()(1) <<
" " << state->_calib_imu_tg->value()(2)
360 <<
" " << state->_calib_imu_tg->value()(3) <<
" " << state->_calib_imu_tg->value()(4) <<
" "
361 << state->_calib_imu_tg->value()(5) <<
" " << state->_calib_imu_tg->value()(6) <<
" " << state->_calib_imu_tg->value()(7)
362 <<
" " << state->_calib_imu_tg->value()(8) <<
" ";
363 if (state->_options.do_calib_imu_intrinsics && state->_options.do_calib_imu_g_sensitivity) {
364 int index_tg = state->_calib_imu_tg->id();
365 of_state_std << std::sqrt(cov(index_tg + 0, index_tg + 0)) <<
" " << std::sqrt(cov(index_tg + 1, index_tg + 1)) <<
" "
366 << std::sqrt(cov(index_tg + 2, index_tg + 2)) <<
" " << std::sqrt(cov(index_tg + 3, index_tg + 3)) <<
" "
367 << std::sqrt(cov(index_tg + 4, index_tg + 4)) <<
" " << std::sqrt(cov(index_tg + 5, index_tg + 5)) <<
" "
368 << std::sqrt(cov(index_tg + 6, index_tg + 6)) <<
" " << std::sqrt(cov(index_tg + 7, index_tg + 7)) <<
" "
369 << std::sqrt(cov(index_tg + 8, index_tg + 8)) <<
" ";
371 of_state_std << 0.0 <<
" " << 0.0 <<
" " << 0.0 <<
" ";
372 of_state_std << 0.0 <<
" " << 0.0 <<
" " << 0.0 <<
" ";
373 of_state_std << 0.0 <<
" " << 0.0 <<
" " << 0.0 <<
" ";
377 of_state_est << state->_calib_imu_GYROtoIMU->value()(0) <<
" " << state->_calib_imu_GYROtoIMU->value()(1) <<
" "
378 << state->_calib_imu_GYROtoIMU->value()(2) <<
" " << state->_calib_imu_GYROtoIMU->value()(3) <<
" ";
379 if (state->_options.do_calib_imu_intrinsics && state->_options.imu_model == StateOptions::ImuModel::KALIBR) {
380 int index_wtoI = state->_calib_imu_GYROtoIMU->id();
381 of_state_std << std::sqrt(cov(index_wtoI + 0, index_wtoI + 0)) <<
" " << std::sqrt(cov(index_wtoI + 1, index_wtoI + 1)) <<
" "
382 << std::sqrt(cov(index_wtoI + 2, index_wtoI + 2)) <<
" " << std::sqrt(cov(index_wtoI + 3, index_wtoI + 3)) <<
" ";
384 of_state_std << 0.0 <<
" " << 0.0 <<
" " << 0.0 <<
" ";
388 of_state_est << state->_calib_imu_ACCtoIMU->value()(0) <<
" " << state->_calib_imu_ACCtoIMU->value()(1) <<
" "
389 << state->_calib_imu_ACCtoIMU->value()(2) <<
" " << state->_calib_imu_ACCtoIMU->value()(3) <<
" ";
390 if (state->_options.do_calib_imu_intrinsics && state->_options.imu_model == StateOptions::ImuModel::RPNG) {
391 int index_atoI = state->_calib_imu_ACCtoIMU->id();
392 of_state_std << std::sqrt(cov(index_atoI + 0, index_atoI + 0)) <<
" " << std::sqrt(cov(index_atoI + 1, index_atoI + 1)) <<
" "
393 << std::sqrt(cov(index_atoI + 2, index_atoI + 2)) <<
" " << std::sqrt(cov(index_atoI + 3, index_atoI + 3)) <<
" ";
395 of_state_std << 0.0 <<
" " << 0.0 <<
" " << 0.0 <<
" ";
399 of_state_est << endl;
400 of_state_std << endl;