@@ -136,11 +136,11 @@ void PoseInstabilityDetector::callback_timer()
136
136
diff_pose_pub_->publish (diff_pose);
137
137
138
138
// publish diagnostics
139
- calculate_threshold ((latest_odometry_time - prev_odometry_time).seconds ());
139
+ ThresholdValues threshold_values = calculate_threshold ((latest_odometry_time - prev_odometry_time).seconds ());
140
140
141
- const std::vector<double > thresholds = {threshold_diff_position_x_, threshold_diff_position_y_ ,
142
- threshold_diff_position_z_, threshold_diff_angle_x_ ,
143
- threshold_diff_angle_y_ , threshold_diff_angle_z_ };
141
+ const std::vector<double > thresholds = {threshold_values. position_x , threshold_values. position_y ,
142
+ threshold_values. position_z , threshold_values. angle_x ,
143
+ threshold_values. angle_y , threshold_values. angle_z };
144
144
145
145
const std::vector<std::string> labels = {" diff_position_x" , " diff_position_y" , " diff_position_z" ,
146
146
" diff_angle_x" , " diff_angle_y" , " diff_angle_z" };
@@ -176,7 +176,7 @@ void PoseInstabilityDetector::callback_timer()
176
176
prev_odometry_ = latest_odometry_;
177
177
}
178
178
179
- void PoseInstabilityDetector::calculate_threshold (double interval_sec)
179
+ PoseInstabilityDetector::ThresholdValues PoseInstabilityDetector::calculate_threshold (double interval_sec)
180
180
{
181
181
// Calculate maximum longitudinal difference
182
182
const double longitudinal_difference =
@@ -227,12 +227,15 @@ void PoseInstabilityDetector::calculate_threshold(double interval_sec)
227
227
const double yaw_difference = roll_difference;
228
228
229
229
// Set thresholds
230
- threshold_diff_position_x_ = longitudinal_difference + pose_estimator_longitudinal_tolerance_;
231
- threshold_diff_position_y_ = lateral_difference + pose_estimator_lateral_tolerance_;
232
- threshold_diff_position_z_ = vertical_difference + pose_estimator_vertical_tolerance_;
233
- threshold_diff_angle_x_ = roll_difference + pose_estimator_angular_tolerance_;
234
- threshold_diff_angle_y_ = pitch_difference + pose_estimator_angular_tolerance_;
235
- threshold_diff_angle_z_ = yaw_difference + pose_estimator_angular_tolerance_;
230
+ ThresholdValues result_values;
231
+ result_values.position_x = longitudinal_difference + pose_estimator_longitudinal_tolerance_;
232
+ result_values.position_y = lateral_difference + pose_estimator_lateral_tolerance_;
233
+ result_values.position_z = vertical_difference + pose_estimator_vertical_tolerance_;
234
+ result_values.angle_x = roll_difference + pose_estimator_angular_tolerance_;
235
+ result_values.angle_y = pitch_difference + pose_estimator_angular_tolerance_;
236
+ result_values.angle_z = yaw_difference + pose_estimator_angular_tolerance_;
237
+
238
+ return result_values;
236
239
}
237
240
238
241
void PoseInstabilityDetector::dead_reckon (
@@ -302,9 +305,25 @@ PoseInstabilityDetector::clip_out_necessary_twist(
302
305
const std::deque<TwistWithCovarianceStamped> & twist_buffer, const rclcpp::Time & start_time,
303
306
const rclcpp::Time & end_time)
304
307
{
308
+ // If there is only one element in the twist_buffer, return a deque that has the same twist
309
+ // from the start till the end
310
+ if (twist_buffer.size () == 1 ) {
311
+ TwistWithCovarianceStamped twist = twist_buffer.front ();
312
+ std::deque<TwistWithCovarianceStamped> simple_twist_deque;
313
+
314
+ twist.header .stamp = start_time;
315
+ simple_twist_deque.push_back (twist);
316
+
317
+ twist.header .stamp = end_time;
318
+ simple_twist_deque.push_back (twist);
319
+
320
+ return simple_twist_deque;
321
+ }
322
+
305
323
// get iterator to the element that is right before start_time (if it does not exist, start_it =
306
324
// twist_buffer.begin())
307
325
auto start_it = twist_buffer.begin ();
326
+
308
327
for (auto it = twist_buffer.begin (); it != twist_buffer.end (); ++it) {
309
328
if (rclcpp::Time (it->header .stamp ) > start_time) {
310
329
break ;
@@ -326,21 +345,6 @@ PoseInstabilityDetector::clip_out_necessary_twist(
326
345
// Create result deque
327
346
std::deque<TwistWithCovarianceStamped> result_deque (start_it, end_it);
328
347
329
- // If the result deque has only one element, return a deque that starts and ends with the same
330
- // element
331
- if (result_deque.size () == 1 ) {
332
- TwistWithCovarianceStamped twist = *start_it;
333
- result_deque.clear ();
334
-
335
- twist.header .stamp = start_time;
336
- result_deque.push_back (twist);
337
-
338
- twist.header .stamp = end_time;
339
- result_deque.push_back (twist);
340
-
341
- return result_deque;
342
- }
343
-
344
348
// If the first element is later than start_time, add the first element to the front of the
345
349
// result_deque
346
350
if (rclcpp::Time (result_deque.front ().header .stamp ) > start_time) {
@@ -395,7 +399,6 @@ PoseInstabilityDetector::clip_out_necessary_twist(
395
399
396
400
result_deque[result_deque.size () - 1 ].header .stamp = end_time;
397
401
}
398
-
399
402
return result_deque;
400
403
}
401
404
0 commit comments