@@ -116,7 +116,13 @@ bool PathShifter::generate(
116
116
}
117
117
118
118
for (const auto & shift_line : shift_lines_) {
119
- int idx_gap = shift_line.end_idx - shift_line.start_idx ;
119
+ if (shift_line.end_idx < shift_line.start_idx ) {
120
+ RCLCPP_WARN_STREAM_THROTTLE (
121
+ logger_, clock_, 3000 , " Invalid indices: end_idx is less than start_idx" );
122
+ return false ;
123
+ }
124
+
125
+ const auto idx_gap = shift_line.end_idx - shift_line.start_idx ;
120
126
if (idx_gap <= 1 ) {
121
127
RCLCPP_WARN_STREAM_THROTTLE (
122
128
logger_, clock_, 3000 ,
@@ -185,7 +191,7 @@ void PathShifter::applyLinearShifter(ShiftedPath * shifted_path) const
185
191
// For all path.points,
186
192
for (size_t i = 0 ; i < shifted_path->path .points .size (); ++i) {
187
193
// Set shift length.
188
- double ith_shift_length;
194
+ double ith_shift_length = 0.0 ;
189
195
if (i < shift_line.start_idx ) {
190
196
ith_shift_length = 0.0 ;
191
197
} else if (shift_line.start_idx <= i && i <= shift_line.end_idx ) {
@@ -235,7 +241,8 @@ void PathShifter::applySplineShifter(ShiftedPath * shifted_path, const bool offs
235
241
logger_, " base_distance = %s, base_length = %s" , toStr (base_distance).c_str (),
236
242
toStr (base_length).c_str ());
237
243
238
- std::vector<double > query_distance, query_length;
244
+ std::vector<double > query_distance;
245
+ std::vector<double > query_length;
239
246
240
247
// For all path.points,
241
248
// Note: start_idx is not included since shift = 0,
@@ -257,7 +264,7 @@ void PathShifter::applySplineShifter(ShiftedPath * shifted_path, const bool offs
257
264
}
258
265
}
259
266
260
- if (offset_back == true ) {
267
+ if (offset_back) {
261
268
// Apply shifting after shift
262
269
for (size_t i = shift_line.end_idx ; i < shifted_path->path .points .size (); ++i) {
263
270
addLateralOffsetOnIndexPoint (shifted_path, delta_shift, i);
@@ -272,7 +279,7 @@ void PathShifter::applySplineShifter(ShiftedPath * shifted_path, const bool offs
272
279
}
273
280
274
281
std::pair<std::vector<double >, std::vector<double >> PathShifter::getBaseLengthsWithoutAccelLimit (
275
- const double arclength, const double shift_length, const bool offset_back) const
282
+ const double arclength, const double shift_length, const bool offset_back)
276
283
{
277
284
const auto s = arclength;
278
285
const auto l = shift_length;
@@ -286,14 +293,13 @@ std::pair<std::vector<double>, std::vector<double>> PathShifter::getBaseLengthsW
286
293
287
294
std::pair<std::vector<double >, std::vector<double >> PathShifter::getBaseLengthsWithoutAccelLimit (
288
295
const double arclength, const double shift_length, const double velocity,
289
- const double longitudinal_acc, const double total_time, const bool offset_back) const
296
+ const double longitudinal_acc, const double total_time, const bool offset_back)
290
297
{
291
- const auto & s = arclength;
292
- const auto & l = shift_length;
293
- const auto & v0 = velocity;
294
- const auto & a = longitudinal_acc;
295
- const auto & T = total_time;
296
- const double t = T / 4 ;
298
+ const auto s = arclength;
299
+ const auto l = shift_length;
300
+ const auto v0 = velocity;
301
+ const auto a = longitudinal_acc;
302
+ const auto t = total_time / 4 ;
297
303
298
304
const double s1 = std::min (v0 * t + 0.5 * a * t * t, s);
299
305
const double v1 = v0 + a * t;
@@ -322,7 +328,7 @@ std::pair<std::vector<double>, std::vector<double>> PathShifter::calcBaseLengths
322
328
return getBaseLengthsWithoutAccelLimit (arclength, shift_length, offset_back);
323
329
}
324
330
325
- const auto & S = arclength;
331
+ const auto S = arclength;
326
332
const auto L = std::abs (shift_length);
327
333
const auto T = a > acc_threshold ? (-v0 + std::sqrt (v0 * v0 + 2 * a * S)) / a : S / v0;
328
334
const auto lateral_a_max = 8.0 * L / (T * T);
@@ -512,8 +518,7 @@ void PathShifter::removeBehindShiftLineAndSetBaseOffset(const size_t nearest_idx
512
518
setBaseOffset (new_base_offset);
513
519
}
514
520
515
- void PathShifter::addLateralOffsetOnIndexPoint (
516
- ShiftedPath * path, double offset, size_t index) const
521
+ void PathShifter::addLateralOffsetOnIndexPoint (ShiftedPath * path, double offset, size_t index)
517
522
{
518
523
if (fabs (offset) < 1.0e-8 ) {
519
524
return ;
@@ -527,10 +532,10 @@ void PathShifter::addLateralOffsetOnIndexPoint(
527
532
path->shift_length .at (index ) += offset;
528
533
}
529
534
530
- void PathShifter::shiftBaseLength (ShiftedPath * path, double offset) const
535
+ void PathShifter::shiftBaseLength (ShiftedPath * path, double offset)
531
536
{
532
- constexpr double BASE_OFFSET_THR = 1.0e-4 ;
533
- if (std::abs (offset) > BASE_OFFSET_THR ) {
537
+ constexpr double base_offset_thr = 1.0e-4 ;
538
+ if (std::abs (offset) > base_offset_thr ) {
534
539
for (size_t i = 0 ; i < path->path .points .size (); ++i) {
535
540
addLateralOffsetOnIndexPoint (path, offset, i);
536
541
}
@@ -563,11 +568,11 @@ double PathShifter::calcShiftTimeFromJerk(const double lateral, const double jer
563
568
}
564
569
565
570
double PathShifter::calcFeasibleVelocityFromJerk (
566
- const double lateral, const double jerk, const double longitudinal )
571
+ const double lateral, const double jerk, const double longitudinal_distance )
567
572
{
568
573
const double j = std::abs (jerk);
569
574
const double l = std::abs (lateral);
570
- const double d = std::abs (longitudinal );
575
+ const double d = std::abs (longitudinal_distance );
571
576
if (j < 1.0e-8 ) {
572
577
return 1.0e10 ; // TODO(Horibe) maybe invalid arg?
573
578
}
0 commit comments