24
24
#include < numeric>
25
25
#include < vector>
26
26
27
+ #define VERBOSE_TRAJECTORY_VELOCITY false
28
+
27
29
namespace motion_velocity_smoother
28
30
{
29
31
JerkFilteredSmoother::JerkFilteredSmoother (rclcpp::Node & node) : SmootherBase(node)
@@ -71,8 +73,6 @@ bool JerkFilteredSmoother::apply(
71
73
return true ;
72
74
}
73
75
74
- bool TMP_SHOW_DEBUG_INFO = false ;
75
-
76
76
const auto ts = std::chrono::system_clock::now ();
77
77
78
78
const double a_max = base_param_.max_accel ;
@@ -93,28 +93,29 @@ bool JerkFilteredSmoother::apply(
93
93
const auto filtered =
94
94
mergeFilteredTrajectory (v0, a0, a_min, j_min, forward_filtered, backward_filtered);
95
95
96
- // Set debug trajectories
97
- debug_trajectories.resize (3 );
98
- debug_trajectories[0 ] = forward_filtered;
99
- debug_trajectories[1 ] = backward_filtered;
100
- debug_trajectories[2 ] = filtered;
101
-
102
96
// Resample TrajectoryPoints for Optimization
103
97
// TODO(planning/control team) deal with overlapped lanes with the same direction
104
98
const auto initial_traj_pose = filtered.front ().pose ;
105
- auto opt_resampled_trajectory = resampling::resampleTrajectory (
106
- filtered, v0, initial_traj_pose, std::numeric_limits<double >::max (),
107
- std::numeric_limits<double >::max (), base_param_.resample_param );
108
99
109
- if (!opt_resampled_trajectory) {
110
- RCLCPP_WARN (logger_, " Resample failed!" );
111
- return false ;
112
- }
100
+ const auto resample = [&](const auto & trajectory) {
101
+ return resampling::resampleTrajectory (
102
+ trajectory, v0, initial_traj_pose, std::numeric_limits<double >::max (),
103
+ std::numeric_limits<double >::max (), base_param_.resample_param );
104
+ };
105
+
106
+ auto opt_resampled_trajectory = resample (filtered);
107
+
108
+ // Set debug trajectories
109
+ debug_trajectories.resize (3 );
110
+ debug_trajectories[0 ] = resample (forward_filtered);
111
+ debug_trajectories[1 ] = resample (backward_filtered);
112
+ debug_trajectories[2 ] = resample (filtered);
113
+
113
114
// Ensure terminal velocity is zero
114
- opt_resampled_trajectory-> back ().longitudinal_velocity_mps = 0.0 ;
115
+ opt_resampled_trajectory. back ().longitudinal_velocity_mps = 0.0 ;
115
116
116
117
// If Resampled Size is too small, we don't do optimization
117
- if (opt_resampled_trajectory-> size () == 1 ) {
118
+ if (opt_resampled_trajectory. size () == 1 ) {
118
119
// No need to do optimization
119
120
output.front ().longitudinal_velocity_mps = v0;
120
121
output.front ().acceleration_mps2 = a0;
@@ -127,7 +128,7 @@ bool JerkFilteredSmoother::apply(
127
128
// to avoid getting 0 as a stop point, search zero velocity index from 1.
128
129
// the size of the resampled trajectory must not be less than 2.
129
130
const auto zero_vel_id = motion_utils::searchZeroVelocityIndex (
130
- * opt_resampled_trajectory, 1 , opt_resampled_trajectory-> size ());
131
+ opt_resampled_trajectory, 1 , opt_resampled_trajectory. size ());
131
132
132
133
if (!zero_vel_id) {
133
134
RCLCPP_WARN (logger_, " opt_resampled_trajectory must have stop point." );
@@ -137,14 +138,14 @@ bool JerkFilteredSmoother::apply(
137
138
// Clip trajectory from 0 to zero_vel_id (the size becomes zero_vel_id_ + 1)
138
139
const size_t N = *zero_vel_id + 1 ;
139
140
140
- output = * opt_resampled_trajectory;
141
+ output = opt_resampled_trajectory;
141
142
142
143
const std::vector<double > interval_dist_arr =
143
- trajectory_utils::calcTrajectoryIntervalDistance (* opt_resampled_trajectory);
144
+ trajectory_utils::calcTrajectoryIntervalDistance (opt_resampled_trajectory);
144
145
145
146
std::vector<double > v_max_arr (N, 0.0 );
146
147
for (size_t i = 0 ; i < N; ++i) {
147
- v_max_arr.at (i) = opt_resampled_trajectory-> at (i).longitudinal_velocity_mps ;
148
+ v_max_arr.at (i) = opt_resampled_trajectory. at (i).longitudinal_velocity_mps ;
148
149
}
149
150
150
151
/*
@@ -306,44 +307,29 @@ bool JerkFilteredSmoother::apply(
306
307
307
308
qp_solver_.logUnsolvedStatus (" [motion_velocity_smoother]" );
308
309
309
- if (TMP_SHOW_DEBUG_INFO) {
310
- // jerk calculation
311
- std::vector<double > p_jerk, jerk_converted, jerk_ideal;
312
- for (size_t i = 0 ; i < input.size () - 1 ; ++i) {
313
- double v_ref0 = filtered.at (i).longitudinal_velocity_mps ;
314
- double v0 = output.at (i).longitudinal_velocity_mps ;
315
- double a0 = output.at (i).acceleration_mps2 ;
316
- double a1 = output.at (i + 1 ).acceleration_mps2 ;
317
- double ds = interval_dist_arr.at (i);
318
- p_jerk.push_back ((a1 - a0) / ds);
319
- jerk_converted.push_back ((a1 - a0) / ds * v_ref0);
320
- jerk_ideal.push_back ((a1 - a0) / ds * v0);
321
- }
322
- p_jerk.push_back (0.0 );
323
- jerk_converted.push_back (0.0 );
324
- jerk_ideal.push_back (0.0 );
325
-
326
- // print
327
- size_t i = 0 ;
328
- auto getVx = [&i](const TrajectoryPoints & trajectory) {
329
- return trajectory.at (i).longitudinal_velocity_mps ;
330
- };
331
- auto getAx = [&i](const TrajectoryPoints & trajectory) {
332
- return trajectory.at (i).acceleration_mps2 ;
333
- };
334
- printf (" v0 = %.3f, a0 = %.3f\n " , v0, a0);
335
- for (; i < input.size (); ++i) {
336
- double gamma = optval.at (IDX_GAMMA0 + i);
337
- printf (
338
- " i = %lu, input: %.3f, filt_f: (%.3f, %.3f), filt_b: (%.3f, %.3f), filt_fb: (%.3f, %.3f), "
339
- " opt: (%.3f, %f), p_jerk = %.3f, p_jerk*v_ref: %.3f (min: %.3f, mac: %.3f), p_jerk*v_opt "
340
- " (to "
341
- " check): %.3f, gamma: %.3f\n " ,
342
- i, getVx (input), getVx (forward_filtered), getAx (forward_filtered), getVx (backward_filtered),
343
- getAx (backward_filtered), getVx (filtered), getAx (filtered), getVx (output), getAx (output),
344
- p_jerk.at (i), jerk_converted.at (i), j_min, j_max, jerk_ideal.at (i), gamma );
310
+ const int status_polish = std::get<2 >(result);
311
+ if (status_polish != 1 ) {
312
+ const auto msg = status_polish == 0 ? " unperformed"
313
+ : status_polish == -1 ? " unsuccessful"
314
+ : " unknown" ;
315
+ RCLCPP_WARN (logger_, " osqp polish process failed : %s. The result may be inaccurate" , msg);
316
+ }
317
+
318
+ if (VERBOSE_TRAJECTORY_VELOCITY) {
319
+ const auto s_output = trajectory_utils::calcArclengthArray (output);
320
+
321
+ std::cerr << " \n\n " << std::endl;
322
+ for (size_t i = 0 ; i < N; ++i) {
323
+ const auto v_opt = output.at (i).longitudinal_velocity_mps ;
324
+ const auto a_opt = output.at (i).acceleration_mps2 ;
325
+ const auto ds = i < interval_dist_arr.size () ? interval_dist_arr.at (i) : 0.0 ;
326
+ const auto v_rs = i < opt_resampled_trajectory.size ()
327
+ ? opt_resampled_trajectory.at (i).longitudinal_velocity_mps
328
+ : 0.0 ;
329
+ RCLCPP_INFO (
330
+ logger_, " i = %4lu | s: %5f | ds: %5f | rs: %9f | op_v: %10f | op_a: %10f |" , i,
331
+ s_output.at (i), ds, v_rs, v_opt, a_opt);
345
332
}
346
- printf (" \n " );
347
333
}
348
334
349
335
return true ;
@@ -467,7 +453,7 @@ TrajectoryPoints JerkFilteredSmoother::mergeFilteredTrajectory(
467
453
return merged;
468
454
}
469
455
470
- boost::optional< TrajectoryPoints> JerkFilteredSmoother::resampleTrajectory (
456
+ TrajectoryPoints JerkFilteredSmoother::resampleTrajectory (
471
457
const TrajectoryPoints & input, [[maybe_unused]] const double v0,
472
458
const geometry_msgs::msg::Pose & current_pose, const double nearest_dist_threshold,
473
459
const double nearest_yaw_threshold) const
0 commit comments