@@ -44,22 +44,26 @@ PoseInstabilityDetector::PoseInstabilityDetector(const rclcpp::NodeOptions & opt
44
44
this ->declare_parameter<double >(" pose_estimator_angular_tolerance" ))
45
45
{
46
46
// 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 " );
48
48
49
49
// 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 ;
59
54
} 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 ();
61
57
}
62
58
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
+
63
67
twist_sub_ = this ->create_subscription <TwistWithCovarianceStamped>(
64
68
" ~/input/twist" , 10 ,
65
69
std::bind (&PoseInstabilityDetector::callback_twist, this , std::placeholders::_1));
@@ -79,19 +83,7 @@ void PoseInstabilityDetector::callback_odometry(Odometry::ConstSharedPtr odometr
79
83
80
84
void PoseInstabilityDetector::callback_pose (PoseWithCovariance::ConstSharedPtr pose_msg_ptr)
81
85
{
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;
95
87
}
96
88
97
89
void PoseInstabilityDetector::callback_twist (
@@ -106,6 +98,9 @@ void PoseInstabilityDetector::callback_timer()
106
98
if (latest_odometry_ == std::nullopt) {
107
99
return ;
108
100
}
101
+ if (latest_ndt_pose_ == std::nullopt) {
102
+ return ;
103
+ }
109
104
if (prev_odometry_ == std::nullopt) {
110
105
prev_odometry_ = latest_odometry_;
111
106
return ;
@@ -117,9 +112,12 @@ void PoseInstabilityDetector::callback_timer()
117
112
}
118
113
119
114
// time variables
120
- const rclcpp::Time latest_odometry_time = rclcpp::Time (latest_odometry_->header .stamp );
121
115
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
+
123
121
// define lambda function to convert quaternion to rpy
124
122
auto quat_to_rpy = [](const Quaternion & quat) {
125
123
tf2::Quaternion tf2_quat (quat.x , quat.y , quat.z , quat.w );
@@ -146,25 +144,28 @@ void PoseInstabilityDetector::callback_timer()
146
144
prev_pose->pose = prev_odometry_->pose .pose ;
147
145
148
146
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);
150
148
151
149
// 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 );
156
157
const std::vector<double > values = {pos.x , pos.y , pos.z , ang_x, ang_y, ang_z};
157
158
158
159
// publish diff_pose for debug
159
160
PoseStamped diff_pose;
160
- diff_pose.header .stamp = latest_odometry_time ;
161
+ diff_pose.header .stamp = latest_pose_time ;
161
162
diff_pose.header .frame_id = " base_link" ;
162
- diff_pose.pose = ekf_to_dr ;
163
+ diff_pose.pose = comparison_target_to_dr ;
163
164
diff_pose_pub_->publish (diff_pose);
164
165
165
166
// publish diagnostics
166
167
ThresholdValues threshold_values =
167
- calculate_threshold ((latest_odometry_time - prev_odometry_time).seconds ());
168
+ calculate_threshold ((latest_pose_time - prev_odometry_time).seconds ());
168
169
169
170
const std::vector<double > thresholds = {threshold_values.position_x , threshold_values.position_y ,
170
171
threshold_values.position_z , threshold_values.angle_x ,
@@ -196,7 +197,7 @@ void PoseInstabilityDetector::callback_timer()
196
197
status.message = (all_ok ? " OK" : " WARN" );
197
198
198
199
DiagnosticArray diagnostics;
199
- diagnostics.header .stamp = latest_odometry_time ;
200
+ diagnostics.header .stamp = latest_pose_time ;
200
201
diagnostics.status .emplace_back (status);
201
202
diagnostics_pub_->publish (diagnostics);
202
203
0 commit comments