Skip to content

Commit 0277191

Browse files
committed
Change the starting pose for DR to EKF odometry, even if the comparison target is ndt pose.
Signed-off-by: TaikiYamada4 <taiki.yamada@tier4.jp>
1 parent f331d8c commit 0277191

File tree

4 files changed

+40
-37
lines changed

4 files changed

+40
-37
lines changed

localization/pose_instability_detector/config/pose_instability_detector.param.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**:
22
ros__parameters:
33
timer_period: 0.5 # [sec]
4-
subscription_type: "odometry" # select from "pose_with_covariance" or "odometry"
4+
comparison_target: "pose_with_covariance" # select from "pose_with_covariance" or "odometry"
55

66
heading_velocity_maximum: 2.778 # [m/s]
77
heading_velocity_scale_factor_tolerance: 3.0 # [%]

localization/pose_instability_detector/include/autoware/pose_instability_detector/pose_instability_detector.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class PoseInstabilityDetector : public rclcpp::Node
8181

8282
// parameters
8383
const double timer_period_; // [sec]
84+
bool use_ndt_pose_;
8485

8586
const double heading_velocity_maximum_; // [m/s]
8687
const double heading_velocity_scale_factor_tolerance_; // [%]
@@ -97,6 +98,7 @@ class PoseInstabilityDetector : public rclcpp::Node
9798
// variables
9899
std::optional<Odometry> latest_odometry_ = std::nullopt;
99100
std::optional<Odometry> prev_odometry_ = std::nullopt;
101+
std::optional<PoseWithCovariance> latest_ndt_pose_ = std::nullopt;
100102
std::deque<TwistWithCovarianceStamped> twist_buffer_;
101103
};
102104

localization/pose_instability_detector/launch/pose_instability_detector.launch.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<node pkg="pose_instability_detector" exec="pose_instability_detector_node" name="$(var node_name)" output="both">
1111
<remap from="~/input/odometry" to="$(var input_odometry)"/>
1212
<remap from="~/input/twist" to="$(var input_twist)"/>
13-
<remap from="~/input/pose" to="/localization/pose_estimator/pose_with_covariance"/>
13+
<remap from="~/input/pose" to="$(var input_pose)"/>
1414
<param from="$(var param_file)"/>
1515
</node>
1616
</launch>

localization/pose_instability_detector/src/pose_instability_detector.cpp

+36-35
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,26 @@ PoseInstabilityDetector::PoseInstabilityDetector(const rclcpp::NodeOptions & opt
4444
this->declare_parameter<double>("pose_estimator_angular_tolerance"))
4545
{
4646
// Define subscription type
47-
std::string subscription_type = this->declare_parameter<std::string>("subscription_type");
47+
std::string comparison_target = this->declare_parameter<std::string>("comparison_target");
4848

4949
// Define subscribers, publishers and a timer.
50-
if(subscription_type == "odometry") {
51-
odometry_sub_ = this->create_subscription<Odometry>(
52-
"~/input/odometry", 10,
53-
std::bind(&PoseInstabilityDetector::callback_odometry, this, std::placeholders::_1));
54-
} else if (subscription_type == "pose_with_covariance") {
55-
pose_with_covarince_sub_ = this->create_subscription<PoseWithCovariance>(
56-
"~/input/pose", 10,
57-
std::bind(&PoseInstabilityDetector::callback_pose, this, std::placeholders::_1));
58-
RCLCPP_INFO(this->get_logger(), "Create subscriber");
50+
if (comparison_target == "odometry") {
51+
use_ndt_pose_ = false;
52+
} else if (comparison_target == "pose_with_covariance") {
53+
use_ndt_pose_ = true;
5954
} else {
60-
RCLCPP_ERROR(this->get_logger(), "Invalid subscription type!: %s", subscription_type.c_str());
55+
RCLCPP_ERROR(this->get_logger(), "Invalid subscription type!: %s", comparison_target.c_str());
56+
rclcpp::shutdown();
6157
}
6258

59+
odometry_sub_ = this->create_subscription<Odometry>(
60+
"~/input/odometry", 10,
61+
std::bind(&PoseInstabilityDetector::callback_odometry, this, std::placeholders::_1));
62+
63+
pose_with_covarince_sub_ = this->create_subscription<PoseWithCovariance>(
64+
"~/input/pose", 10,
65+
std::bind(&PoseInstabilityDetector::callback_pose, this, std::placeholders::_1));
66+
6367
twist_sub_ = this->create_subscription<TwistWithCovarianceStamped>(
6468
"~/input/twist", 10,
6569
std::bind(&PoseInstabilityDetector::callback_twist, this, std::placeholders::_1));
@@ -79,19 +83,7 @@ void PoseInstabilityDetector::callback_odometry(Odometry::ConstSharedPtr odometr
7983

8084
void PoseInstabilityDetector::callback_pose(PoseWithCovariance::ConstSharedPtr pose_msg_ptr)
8185
{
82-
//RCLCPP_INFO(this->get_logger(), "Pose Callback start");
83-
/*
84-
std::optional<Odometry> temp_odometry = std::nullopt;
85-
temp_odometry->header = pose_msg_ptr->header;
86-
temp_odometry->child_frame_id = "base_link";
87-
temp_odometry->pose = pose_msg_ptr->pose;
88-
latest_odometry_ = temp_odometry;
89-
*/
90-
latest_odometry_ = Odometry();
91-
latest_odometry_->header = pose_msg_ptr->header;
92-
latest_odometry_->child_frame_id = "base_link";
93-
latest_odometry_->pose = pose_msg_ptr->pose;
94-
//RCLCPP_INFO(this->get_logger(), "Pose Callback done");
86+
latest_ndt_pose_ = *pose_msg_ptr;
9587
}
9688

9789
void PoseInstabilityDetector::callback_twist(
@@ -106,6 +98,9 @@ void PoseInstabilityDetector::callback_timer()
10698
if (latest_odometry_ == std::nullopt) {
10799
return;
108100
}
101+
if (latest_ndt_pose_ == std::nullopt) {
102+
return;
103+
}
109104
if (prev_odometry_ == std::nullopt) {
110105
prev_odometry_ = latest_odometry_;
111106
return;
@@ -117,9 +112,12 @@ void PoseInstabilityDetector::callback_timer()
117112
}
118113

119114
// time variables
120-
const rclcpp::Time latest_odometry_time = rclcpp::Time(latest_odometry_->header.stamp);
121115
const rclcpp::Time prev_odometry_time = rclcpp::Time(prev_odometry_->header.stamp);
122-
116+
const rclcpp::Time latest_pose_time =
117+
use_ndt_pose_ ?
118+
rclcpp::Time(latest_ndt_pose_->header.stamp) :
119+
rclcpp::Time(latest_odometry_->header.stamp);
120+
123121
// define lambda function to convert quaternion to rpy
124122
auto quat_to_rpy = [](const Quaternion & quat) {
125123
tf2::Quaternion tf2_quat(quat.x, quat.y, quat.z, quat.w);
@@ -146,25 +144,28 @@ void PoseInstabilityDetector::callback_timer()
146144
prev_pose->pose = prev_odometry_->pose.pose;
147145

148146
Pose::SharedPtr dr_pose = std::make_shared<Pose>();
149-
dead_reckon(prev_pose, latest_odometry_time, twist_buffer_, dr_pose);
147+
dead_reckon(prev_pose, latest_pose_time, twist_buffer_, dr_pose);
150148

151149
// compare dead reckoning pose and latest_odometry_
152-
const Pose latest_ekf_pose = latest_odometry_->pose.pose;
153-
const Pose ekf_to_dr = inverseTransformPose(*dr_pose, latest_ekf_pose);
154-
const geometry_msgs::msg::Point pos = ekf_to_dr.position;
155-
const auto [ang_x, ang_y, ang_z] = quat_to_rpy(ekf_to_dr.orientation);
150+
const Pose latest_pose =
151+
use_ndt_pose_ ?
152+
latest_ndt_pose_->pose.pose :
153+
latest_odometry_->pose.pose;
154+
const Pose comparison_target_to_dr = inverseTransformPose(*dr_pose, latest_pose);
155+
const geometry_msgs::msg::Point pos = comparison_target_to_dr.position;
156+
const auto [ang_x, ang_y, ang_z] = quat_to_rpy(comparison_target_to_dr.orientation);
156157
const std::vector<double> values = {pos.x, pos.y, pos.z, ang_x, ang_y, ang_z};
157158

158159
// publish diff_pose for debug
159160
PoseStamped diff_pose;
160-
diff_pose.header.stamp = latest_odometry_time;
161+
diff_pose.header.stamp = latest_pose_time;
161162
diff_pose.header.frame_id = "base_link";
162-
diff_pose.pose = ekf_to_dr;
163+
diff_pose.pose = comparison_target_to_dr;
163164
diff_pose_pub_->publish(diff_pose);
164165

165166
// publish diagnostics
166167
ThresholdValues threshold_values =
167-
calculate_threshold((latest_odometry_time - prev_odometry_time).seconds());
168+
calculate_threshold((latest_pose_time - prev_odometry_time).seconds());
168169

169170
const std::vector<double> thresholds = {threshold_values.position_x, threshold_values.position_y,
170171
threshold_values.position_z, threshold_values.angle_x,
@@ -196,7 +197,7 @@ void PoseInstabilityDetector::callback_timer()
196197
status.message = (all_ok ? "OK" : "WARN");
197198

198199
DiagnosticArray diagnostics;
199-
diagnostics.header.stamp = latest_odometry_time;
200+
diagnostics.header.stamp = latest_pose_time;
200201
diagnostics.status.emplace_back(status);
201202
diagnostics_pub_->publish(diagnostics);
202203

0 commit comments

Comments
 (0)