Skip to content

Commit ee52a19

Browse files
committed
Added prediction with latest imu timestamp and added timestamp to odom msg
1 parent 91337d2 commit ee52a19

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

glider/include/glider/core/odometry.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Odometry
3535
Odometry(gtsam::Values& val, gtsam::Key key, double scale, int64_t timestamp, bool init = true);
3636
Odometry(gtsam::NavState& ns, bool init = true);
3737
Odometry(gtsam::NavState& ns, Eigen::Vector3d& gyro, bool init = true);
38+
Odometry(gtsam::NavState& ns, Eigen::Vector3d& gyro, int64_t timestamp, bool init = true);
3839

3940
template<typename T>
4041
T getPose() const;

glider/include/ros/glider_node.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,7 @@ class GliderNode : public rclcpp::Node
7272

7373
// tracker
7474
Glider::State current_state_;
75+
76+
int64_t latest_imu_timestamp_;
7577
};
7678
}

glider/ros/glider_node.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ GliderNode::GliderNode(const rclcpp::NodeOptions& options) : rclcpp::Node("glide
5757

5858
current_state_ = Glider::State::Uninitialized();
5959

60+
latest_imu_timestamp_ = 0;
61+
6062
if (use_odom)
6163
{
6264
auto odom_sub_options = rclcpp::SubscriptionOptions();
@@ -94,7 +96,11 @@ void GliderNode::interpolationCallback()
9496
{
9597
if (!initialized_ || !current_state_.isInitialized()) return;
9698

97-
int64_t timestamp = getTime(this->now());
99+
if (latest_imu_timestamp_ <= 0)
100+
{
101+
return;
102+
}
103+
int64_t timestamp = latest_imu_timestamp_;
98104
Glider::Odometry odom = glider_->interpolate(timestamp);
99105

100106
if (!odom.isInitialized()) return;
@@ -121,6 +127,8 @@ void GliderNode::imuCallback(const sensor_msgs::msg::Imu::ConstSharedPtr msg)
121127
int64_t timestamp = getTime(msg->header.stamp);
122128

123129
glider_->addIMU(timestamp, accel, gyro, orient);
130+
131+
latest_imu_timestamp_ = timestamp;
124132
}
125133

126134
void GliderNode::magCallback(const sensor_msgs::msg::MagneticField::ConstSharedPtr msg)

glider/src/factor_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ Odometry FactorManager::predict(int64_t timestamp)
275275
}
276276
gtsam::NavState result = pim_copy_->predict(current_state_.getNavState(), bias_);
277277

278-
Odometry ret(result, gyro_);
278+
Odometry ret(result, gyro_, timestamp);
279279

280280
return ret;
281281
}

glider/src/odometry.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ Odometry::Odometry(gtsam::NavState& ns, Eigen::Vector3d& gyro, bool init)
5050
initialized_ = init;
5151
}
5252

53+
Odometry::Odometry(gtsam::NavState& ns, Eigen::Vector3d& gyro, int64_t timestamp, bool init)
54+
{
55+
position_ = ns.position();
56+
orientation_ = ns.attitude();
57+
pose_ = gtsam::Pose3(orientation_, position_);
58+
velocity_ = ns.v();
59+
altitude_ = position_.z();
60+
heading_ = orientation_.yaw();
61+
gyro_ = gyro;
62+
initialized_ = init;
63+
timestamp_ = timestamp;
64+
}
65+
5366
Odometry Odometry::Uninitialized()
5467
{
5568
Odometry odom;

0 commit comments

Comments
 (0)