My Project 1.0
Holistic Fusion: A Generic Framework for Multimodal Sensor Fusion
Loading...
Searching...
No Matches
ImuPose3Fuser.cpp
Go to the documentation of this file.
1/*
2Copyright 2024 by Julian Nubert, Robotic Systems Lab, ETH Zurich.
3All rights reserved.
4This file is released under the "BSD-3-Clause License".
5Please see the LICENSE file that has been included as part of this package.
6 */
7
8// Implementation
10
11// Workspace
17
18namespace imu_pose3_fuser {
19
20ImuPose3Fuser::ImuPose3Fuser(std::shared_ptr<ros::NodeHandle> privateNodePtr) : holistic_fusion::HolisticFusionRos(privateNodePtr) {
21 REGULAR_COUT << GREEN_START << " ImuPose3Fuser-Constructor called." << COLOR_END << std::endl;
22
23 // Configurations ----------------------------
24 // Static transforms
25 throw std::runtime_error("Static transforms not implemented yet.");
26 // staticTransformsPtr_ = std::make_shared<holistic_fusion::StaticTransforms>();
27
28 // Set up
30}
31
33 REGULAR_COUT << GREEN_START << " ImuPose3Fuser-Setup called." << COLOR_END << std::endl;
34
35 // Read parameters
37
38 // Super class
39 HolisticFusionRos::setup(staticTransformsPtr_);
40
41 // Find transformations
42 staticTransformsPtr_->findTransformations();
43
44 // Publishers ----------------------------
46
47 // Subscribers ----------------------------
49
50 // Messages ----------------------------
52
53 // Server ----------------------------
55
56 // Wrap up ----------------------------
57 REGULAR_COUT << GREEN_START << " Set up successfully." << COLOR_END << std::endl;
58}
59
61 // Paths
62 pubMeasPose3Path_ = privateNode.advertise<nav_msgs::Path>("/holistic_fusion/measPose3_path_world_imu", ROS_QUEUE_SIZE);
63}
64
66 // Pose3 Odometry
67 subPose3Odometry_ = privateNode.subscribe<nav_msgs::Odometry>("/pose3_odometry_topic", ROS_QUEUE_SIZE, &ImuPose3Fuser::pose3Callback_,
68 this, ros::TransportHints().tcpNoDelay());
69 REGULAR_COUT << COLOR_END << " Initialized Pose3 Odometry subscriber with topic: " << subPose3Odometry_.getTopic() << std::endl;
70}
71
73 // Path
74 measPose3_worldImuPathPtr_ = nav_msgs::PathPtr(new nav_msgs::Path);
75}
76
78 // Nothing
79}
80
81void ImuPose3Fuser::pose3Callback_(const nav_msgs::Odometry::ConstPtr& odomPtr) {
82 // Static members
83 static int odometryCallbackCounter__ = -1;
84
85 // Counter
86 ++odometryCallbackCounter__;
87
88 Eigen::Isometry3d T_W_Ik;
89 holistic_fusion::odomMsgToEigen(*odomPtr, T_W_Ik.matrix());
90
91 // Transform to IMU frame
92 double odometryTimeK = odomPtr->header.stamp.toSec();
93
94 // Measurement
97 T_W_Ik, pose3UnaryNoise_, staticTransformsPtr_->getWorldFrame(), staticTransformsPtr_->getWorldFrame());
98
99 // Only add measurement once every second in beginning
100 bool addMeasurementFlag = false;
101 if (odometryCallbackCounter__ < 4000) {
102 if ((odometryCallbackCounter__ % 200) == 0) {
103 addMeasurementFlag = true;
104 }
105 } else { // And more rarely later
106 if ((odometryCallbackCounter__ % 2000) == 0) {
107 addMeasurementFlag = true;
108 }
109 }
110
111 // Add measurement or initialize
112 if (odometryCallbackCounter__ <= 2) {
113 return;
114 } else if (!areYawAndPositionInited()) { // Initializing
115 REGULAR_COUT << GREEN_START << " Odometry callback is setting global yaw, as it was not set so far." << COLOR_END << std::endl;
116 this->initYawAndPosition(unary6DMeasurement);
117 } else if (addMeasurementFlag) { // Already initialized --> unary factor
118 this->addUnaryPose3AbsoluteMeasurement(unary6DMeasurement);
119 }
120
121 // Visualization ----------------------------
122 // Add to path message
123 addToPathMsg(measPose3_worldImuPathPtr_, staticTransformsPtr_->getWorldFrame(), odomPtr->header.stamp, T_W_Ik.matrix().block<3, 1>(0, 3),
124 graphConfigPtr_->imuBufferLength_ * 4);
125
126 // Publish Path
128}
129
130} // namespace imu_pose3_fuser
#define REGULAR_COUT
#define COLOR_END
#define GREEN_START
#define ROS_QUEUE_SIZE
void addUnaryPose3AbsoluteMeasurement(const UnaryMeasurementXDAbsolute< Eigen::Isometry3d, 6 > &R_T_R_S, const bool addToOnlineSmootherFlag=true) override
Unary Measurements / Absolute Measurements: In reference frame --> systematic drift.
static void addToPathMsg(const nav_msgs::PathPtr &pathPtr, const std::string &frameName, const ros::Time &stamp, const Eigen::Vector3d &t, int maxBufferLength)
HolisticFusionRos(const std::shared_ptr< ros::NodeHandle > &privateNodePtr)
std::shared_ptr< GraphConfig > graphConfigPtr_
std::shared_ptr< StaticTransforms > staticTransformsPtr_
bool initYawAndPosition(const UnaryMeasurementXD< Eigen::Isometry3d, 6 > &unary6DMeasurement)
Class to represent x-dimensional absolute unary measurement in the graph.
nav_msgs::PathPtr measPose3_worldImuPathPtr_
void initializeServices(ros::NodeHandle &privateNode) override
void readParams(const ros::NodeHandle &privateNode) override
void pose3Callback_(const nav_msgs::Odometry::ConstPtr &lidarOdomPtr)
ImuPose3Fuser(std::shared_ptr< ros::NodeHandle > privateNodePtr)
void initializePublishers(ros::NodeHandle &privateNode) override
Eigen::Matrix< double, 6, 1 > pose3UnaryNoise_
void initializeSubscribers(ros::NodeHandle &privateNode) override
void initializeMessages(ros::NodeHandle &privateNode) override
void odomMsgToEigen(const nav_msgs::Odometry &odomLidar, Eigen::Matrix4d &T)
static RobustNorm None()
Definition Measurement.h:33