Skip to content

Commit ccbe319

Browse files
refactor(bpp): path shifter clang tidy and logging level configuration (#6917)
Signed-off-by: Muhammad Zulfaqar Azmi <zulfaqar.azmi@tier4.jp>
1 parent 4200be3 commit ccbe319

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

common/tier4_logging_level_configure_rviz_plugin/config/logger_config.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Planning:
3333
logger_name: planning.scenario_planning.lane_driving.behavior_planning.behavior_path_planner
3434
- node_name: /planning/scenario_planning/lane_driving/behavior_planning/behavior_path_planner
3535
logger_name: tier4_autoware_utils
36+
- node_name: /planning/scenario_planning/lane_driving/behavior_planning/behavior_path_planner
37+
logger_name: behavior_path_planner.path_shifter
3638

3739
behavior_path_planner_avoidance:
3840
- node_name: /planning/scenario_planning/lane_driving/behavior_planning/behavior_path_planner

planning/behavior_path_planner_common/include/behavior_path_planner_common/utils/path_shifter/path_shifter.hpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ class PathShifter
9494
void setLongitudinalAcceleration(const double longitudinal_acc);
9595

9696
/**
97-
* @brief Add shift point. You don't have to care about the start/end_idx.
97+
* @brief Add shift line. You don't have to care about the start/end_idx.
9898
*/
99-
void addShiftLine(const ShiftLine & point);
99+
void addShiftLine(const ShiftLine & line);
100100

101101
/**
102102
* @brief Set new shift point. You don't have to care about the start/end_idx.
@@ -143,7 +143,7 @@ class PathShifter
143143
////////////////////////////////////////
144144

145145
static double calcFeasibleVelocityFromJerk(
146-
const double lateral, const double jerk, const double distance);
146+
const double lateral, const double jerk, const double longitudinal_distance);
147147

148148
static double calcLateralDistFromJerk(
149149
const double longitudinal, const double jerk, const double velocity);
@@ -196,12 +196,12 @@ class PathShifter
196196
std::pair<std::vector<double>, std::vector<double>> calcBaseLengths(
197197
const double arclength, const double shift_length, const bool offset_back) const;
198198

199-
std::pair<std::vector<double>, std::vector<double>> getBaseLengthsWithoutAccelLimit(
200-
const double arclength, const double shift_length, const bool offset_back) const;
199+
static std::pair<std::vector<double>, std::vector<double>> getBaseLengthsWithoutAccelLimit(
200+
const double arclength, const double shift_length, const bool offset_back);
201201

202-
std::pair<std::vector<double>, std::vector<double>> getBaseLengthsWithoutAccelLimit(
202+
static std::pair<std::vector<double>, std::vector<double>> getBaseLengthsWithoutAccelLimit(
203203
const double arclength, const double shift_length, const double velocity,
204-
const double longitudinal_acc, const double total_time, const bool offset_back) const;
204+
const double longitudinal_acc, const double total_time, const bool offset_back);
205205

206206
/**
207207
* @brief Calculate path index for shift_lines and set is_index_aligned_ to true.
@@ -235,9 +235,9 @@ class PathShifter
235235
*/
236236
bool checkShiftLinesAlignment(const ShiftLineArray & shift_lines) const;
237237

238-
void addLateralOffsetOnIndexPoint(ShiftedPath * path, double offset, size_t index) const;
238+
static void addLateralOffsetOnIndexPoint(ShiftedPath * path, double offset, size_t index);
239239

240-
void shiftBaseLength(ShiftedPath * path, double offset) const;
240+
static void shiftBaseLength(ShiftedPath * path, double offset);
241241

242242
void setBaseOffset(const double val)
243243
{

planning/behavior_path_planner_common/src/utils/path_shifter/path_shifter.cpp

+25-20
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ bool PathShifter::generate(
116116
}
117117

118118
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;
120126
if (idx_gap <= 1) {
121127
RCLCPP_WARN_STREAM_THROTTLE(
122128
logger_, clock_, 3000,
@@ -185,7 +191,7 @@ void PathShifter::applyLinearShifter(ShiftedPath * shifted_path) const
185191
// For all path.points,
186192
for (size_t i = 0; i < shifted_path->path.points.size(); ++i) {
187193
// Set shift length.
188-
double ith_shift_length;
194+
double ith_shift_length = 0.0;
189195
if (i < shift_line.start_idx) {
190196
ith_shift_length = 0.0;
191197
} 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
235241
logger_, "base_distance = %s, base_length = %s", toStr(base_distance).c_str(),
236242
toStr(base_length).c_str());
237243

238-
std::vector<double> query_distance, query_length;
244+
std::vector<double> query_distance;
245+
std::vector<double> query_length;
239246

240247
// For all path.points,
241248
// Note: start_idx is not included since shift = 0,
@@ -257,7 +264,7 @@ void PathShifter::applySplineShifter(ShiftedPath * shifted_path, const bool offs
257264
}
258265
}
259266

260-
if (offset_back == true) {
267+
if (offset_back) {
261268
// Apply shifting after shift
262269
for (size_t i = shift_line.end_idx; i < shifted_path->path.points.size(); ++i) {
263270
addLateralOffsetOnIndexPoint(shifted_path, delta_shift, i);
@@ -272,7 +279,7 @@ void PathShifter::applySplineShifter(ShiftedPath * shifted_path, const bool offs
272279
}
273280

274281
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)
276283
{
277284
const auto s = arclength;
278285
const auto l = shift_length;
@@ -286,14 +293,13 @@ std::pair<std::vector<double>, std::vector<double>> PathShifter::getBaseLengthsW
286293

287294
std::pair<std::vector<double>, std::vector<double>> PathShifter::getBaseLengthsWithoutAccelLimit(
288295
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)
290297
{
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;
297303

298304
const double s1 = std::min(v0 * t + 0.5 * a * t * t, s);
299305
const double v1 = v0 + a * t;
@@ -322,7 +328,7 @@ std::pair<std::vector<double>, std::vector<double>> PathShifter::calcBaseLengths
322328
return getBaseLengthsWithoutAccelLimit(arclength, shift_length, offset_back);
323329
}
324330

325-
const auto & S = arclength;
331+
const auto S = arclength;
326332
const auto L = std::abs(shift_length);
327333
const auto T = a > acc_threshold ? (-v0 + std::sqrt(v0 * v0 + 2 * a * S)) / a : S / v0;
328334
const auto lateral_a_max = 8.0 * L / (T * T);
@@ -512,8 +518,7 @@ void PathShifter::removeBehindShiftLineAndSetBaseOffset(const size_t nearest_idx
512518
setBaseOffset(new_base_offset);
513519
}
514520

515-
void PathShifter::addLateralOffsetOnIndexPoint(
516-
ShiftedPath * path, double offset, size_t index) const
521+
void PathShifter::addLateralOffsetOnIndexPoint(ShiftedPath * path, double offset, size_t index)
517522
{
518523
if (fabs(offset) < 1.0e-8) {
519524
return;
@@ -527,10 +532,10 @@ void PathShifter::addLateralOffsetOnIndexPoint(
527532
path->shift_length.at(index) += offset;
528533
}
529534

530-
void PathShifter::shiftBaseLength(ShiftedPath * path, double offset) const
535+
void PathShifter::shiftBaseLength(ShiftedPath * path, double offset)
531536
{
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) {
534539
for (size_t i = 0; i < path->path.points.size(); ++i) {
535540
addLateralOffsetOnIndexPoint(path, offset, i);
536541
}
@@ -563,11 +568,11 @@ double PathShifter::calcShiftTimeFromJerk(const double lateral, const double jer
563568
}
564569

565570
double PathShifter::calcFeasibleVelocityFromJerk(
566-
const double lateral, const double jerk, const double longitudinal)
571+
const double lateral, const double jerk, const double longitudinal_distance)
567572
{
568573
const double j = std::abs(jerk);
569574
const double l = std::abs(lateral);
570-
const double d = std::abs(longitudinal);
575+
const double d = std::abs(longitudinal_distance);
571576
if (j < 1.0e-8) {
572577
return 1.0e10; // TODO(Horibe) maybe invalid arg?
573578
}

0 commit comments

Comments
 (0)