Skip to content

Commit a4b5072

Browse files
committed
made glider be able to publish at IMU rate
1 parent 7977e3e commit a4b5072

4 files changed

Lines changed: 17 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ as this is standard for robotics, but we are working on supporting the NED frame
2727
## ROS2 Setup
2828
We recommend using Glider with ROS2, you can configure the ros parameters in `config/ros-params.yaml`. Here's more detail about what
2929
the parameters mean:
30-
- `publishers.rate`: the rate at which odometry is published in hz.
30+
- `publishers.rate`: the rate at which odometry is published in hz, setting this to 0 publishes at IMU rate.
3131
- `publishers.nav_sat_fix`: if true will publish the odometry as a `NavSatFix` msg, the default is an `Odometry` msg.
3232
- `publishers.viz.use`: if true will publish an `Odometry` topic for visualization centered around the origin.
3333
- `publishers.viz.origin_easting`: the easting value you want to viz odometry to center around.

glider/config/ros-params.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
glider_node:
22
ros__parameters:
33
publishers:
4-
rate: 100.0
4+
rate: 0.0
55
nav_sat_fix: false
66
viz:
77
use: true

glider/include/ros/glider_node.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class GliderNode : public rclcpp::Node
7676
std::string utm_zone_;
7777
double origin_easting_;
7878
double origin_northing_;
79+
double freq_;
7980

8081
// tracker
8182
Glider::OdometryWithCovariance current_state_;

glider/ros/glider_node.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ GliderNode::GliderNode(const rclcpp::NodeOptions& options) : rclcpp::Node("glide
2121
declare_parameter("path", "");
2222

2323
// Get parameters
24-
double freq = this->get_parameter("publishers.rate").as_double();
24+
freq_ = this->get_parameter("publishers.rate").as_double();
2525

2626
publish_nsf_ = this->get_parameter("publishers.nav_sat_fix").as_bool();
2727
viz_ = this->get_parameter("publishers.viz.use").as_bool();
@@ -60,13 +60,13 @@ GliderNode::GliderNode(const rclcpp::NodeOptions& options) : rclcpp::Node("glide
6060
if (publish_nsf_)
6161
{
6262
LOG(INFO) << "[GLIDER] Publishing NavSatFix msg on /glider/fix";
63-
LOG(INFO) << "[GLIDER] Using prediction rate: " << freq;
63+
LOG(INFO) << "[GLIDER] Using prediction rate: " << freq_;
6464
gps_pub_ = this->create_publisher<sensor_msgs::msg::NavSatFix>("/glider/fix", 10);
6565
}
6666
else
6767
{
6868
LOG(INFO) << "[GLIDER] Publishing Odometry msg on /glider/odom";
69-
LOG(INFO) << "[GLIDER] Using prediction rate: " << freq;
69+
LOG(INFO) << "[GLIDER] Using prediction rate: " << freq_;
7070
odom_pub_ = this->create_publisher<nav_msgs::msg::Odometry>("/glider/odom", 10);
7171
}
7272

@@ -76,9 +76,11 @@ GliderNode::GliderNode(const rclcpp::NodeOptions& options) : rclcpp::Node("glide
7676
odom_viz_pub_ = this->create_publisher<nav_msgs::msg::Odometry>("/glider/odom/viz", 10);
7777
}
7878

79-
// TODO add in predictor
80-
std::chrono::milliseconds d = GliderROS::Conversions::hzToDuration(freq);
81-
timer_ = this->create_wall_timer(d, std::bind(&GliderNode::interpolationCallback, this));
79+
if (freq_ > 0)
80+
{
81+
std::chrono::milliseconds d = GliderROS::Conversions::hzToDuration(freq_);
82+
timer_ = this->create_wall_timer(d, std::bind(&GliderNode::interpolationCallback, this));
83+
}
8284
LOG(INFO) << "[GLIDER] GliderNode Initialized";
8385
}
8486

@@ -106,6 +108,12 @@ void GliderNode::imuCallback(const sensor_msgs::msg::Imu::ConstSharedPtr msg)
106108
int64_t timestamp = getTime(msg->header.stamp);
107109

108110
glider_->addImu(timestamp, accel, gyro, orient);
111+
112+
if (freq_ == 0 && current_state_.isInitialized())
113+
{
114+
Glider::Odometry odom = glider_->interpolate(timestamp);
115+
(publish_nsf_) ? publishNavSatFix(odom) : publishOdometry(odom);
116+
}
109117
}
110118

111119
void GliderNode::gpsCallback(const sensor_msgs::msg::NavSatFix::ConstSharedPtr msg)

0 commit comments

Comments
 (0)