Skip to content

Commit 35e57fb

Browse files
authored
Port PR #753 and #728 to ROS2 version (#765)
* compiling version of commit #753 and #728 ported to ros2 rolling * format fixes * fix time source disagreement by converting to seconds beforehand, append parameter usage, fix linting * fix linting and uncrustify
1 parent a8b92e9 commit 35e57fb

File tree

3 files changed

+191
-47
lines changed

3 files changed

+191
-47
lines changed

include/robot_localization/ros_filter.hpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,19 @@ struct CallbackData
7272
const std::string & topic_name,
7373
const std::vector<bool> & update_vector, const int update_sum,
7474
const bool differential, const bool relative,
75+
const bool pose_use_child_frame,
7576
const double rejection_threshold)
7677
: topic_name_(topic_name), update_vector_(update_vector),
7778
update_sum_(update_sum), differential_(differential),
78-
relative_(relative), rejection_threshold_(rejection_threshold) {}
79+
relative_(relative), pose_use_child_frame_(pose_use_child_frame),
80+
rejection_threshold_(rejection_threshold) {}
7981

8082
std::string topic_name_;
8183
std::vector<bool> update_vector_;
8284
int update_sum_;
8385
bool differential_;
8486
bool relative_;
87+
bool pose_use_child_frame_;
8588
double rejection_threshold_;
8689
};
8790

@@ -147,6 +150,16 @@ class RosFilter : public rclcpp::Node
147150
void
148151
controlStampedCallback(const geometry_msgs::msg::TwistStamped::SharedPtr msg);
149152

153+
//! @brief Differentiate angular velocity for angular acceleration
154+
//!
155+
//! @param[in] currentTime - The time at which to carry out differentiation (the current time)
156+
//!
157+
//! Maybe more state variables can be time-differentiated to estimate higher-order states,
158+
//! but now we only focus on obtaining the angular acceleration. It implements a backward-
159+
//! Euler differentiation.
160+
//!
161+
void differentiateMeasurements(const rclcpp::Time & current_time);
162+
150163
//! @brief Adds a measurement to the queue of measurements to be processed
151164
//!
152165
//! @param[in] topic_name - The name of the measurement source (only used for
@@ -263,11 +276,14 @@ class RosFilter : public rclcpp::Node
263276
//! @param[in] callback_data - Relevant static callback data
264277
//! @param[in] target_frame - The target frame_id into which to transform the
265278
//! data
279+
//! @param[in] pose_source_frame - The source frame_id from which to transform
280+
//! the data
266281
//! @param[in] imu_data - Whether this data comes from an IMU
267282
//!
268283
void poseCallback(
269284
const geometry_msgs::msg::PoseWithCovarianceStamped::SharedPtr msg,
270285
const CallbackData & callback_data, const std::string & target_frame,
286+
const std::string & pose_source_frame,
271287
const bool imu_data);
272288

273289
//! @brief initialize the filter
@@ -420,6 +436,8 @@ class RosFilter : public rclcpp::Node
420436
//! @param[in] topic_name - The name of the topic over which this message was
421437
//! received
422438
//! @param[in] target_frame - The target tf frame
439+
//! @param[in] relative - whether the IMU sensor reports pose relative to
440+
//! initialization pose
423441
//! @param[in] update_vector - The update vector for the data source
424442
//! @param[in] measurement - The twist data converted to a measurement
425443
//! @param[in] measurement_covariance - The covariance of the converted
@@ -429,6 +447,7 @@ class RosFilter : public rclcpp::Node
429447
const sensor_msgs::msg::Imu::SharedPtr msg,
430448
const std::string & topic_name,
431449
const std::string & target_frame,
450+
const bool relative,
432451
std::vector<bool> & update_vector,
433452
Eigen::VectorXd & measurement,
434453
Eigen::MatrixXd & measurement_covariance);
@@ -438,6 +457,7 @@ class RosFilter : public rclcpp::Node
438457
//! @param[in] topic_name - The name of the topic over which this message was
439458
//! received
440459
//! @param[in] target_frame - The target tf frame
460+
//! @param[in] source_frame - The source tf frame
441461
//! @param[in] differential - Whether we're carrying out differential
442462
//! integration
443463
//! @param[in] relative - Whether this measurement is processed relative to
@@ -453,6 +473,7 @@ class RosFilter : public rclcpp::Node
453473
bool preparePose(
454474
const geometry_msgs::msg::PoseWithCovarianceStamped::SharedPtr msg,
455475
const std::string & topic_name, const std::string & target_frame,
476+
const std::string & source_frame,
456477
const bool differential, const bool relative, const bool imu_data,
457478
std::vector<bool> & update_vector, Eigen::VectorXd & measurement,
458479
Eigen::MatrixXd & measurement_covariance);
@@ -651,6 +672,22 @@ class RosFilter : public rclcpp::Node
651672
//!
652673
std::map<std::string, rclcpp::Time> last_message_times_;
653674

675+
//! @brief Last time mark that time-differentiation is calculated, in seconds
676+
//!
677+
double last_diff_time_;
678+
679+
//! @brief Last record of filtered angular velocity
680+
//!
681+
tf2::Vector3 last_state_twist_rot_;
682+
683+
//! @brief Calculated angular acceleration from time-differencing
684+
//!
685+
tf2::Vector3 angular_acceleration_;
686+
687+
//! @brief Covariance of the calculated angular acceleration
688+
//!
689+
Eigen::MatrixXd angular_acceleration_cov_;
690+
654691
//! @brief Stores the first measurement from each topic for relative
655692
//! measurements
656693
//!

params/ekf.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ ekf_filter_node:
116116
# integrating it. If you simply want your measurements to start at 0 for a given sensor, set this to true.
117117
odom0_relative: false
118118

119+
# [ADVANCED] Whether to use the starting pose of child_frame_id as the origin of odometry.
120+
# Note: this is different from setting odom0_relative to true, as when child_frame is different from
121+
# base_link_frame, the rotation of base_link will be coupled into the translation of child_frame.
122+
# Set to true for fusing secondary odometry sources that are rigidly connected to base_link but has a non-zero
123+
# offset from base_link.
124+
odom0_pose_use_child_frame: false
125+
119126
# [ADVANCED] If your data is subject to outliers, use these threshold settings, expressed as Mahalanobis distances, to
120127
# control how far away from the current vehicle state a sensor measurement is permitted to be. Each defaults to
121128
# numeric_limits<double>::max() if unspecified. It is strongly recommended that these parameters be removed if not

0 commit comments

Comments
 (0)