Skip to content

Commit d8087f4

Browse files
authored
feat(pid_longitudinal_controller): suppress rclcpp_warning/error (#9384)
* feat(pid_longitudinal_controller): suppress rclcpp_warning/error Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> * update codeowner Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> --------- Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com>
1 parent 6c20d58 commit d8087f4

File tree

4 files changed

+56
-31
lines changed

4 files changed

+56
-31
lines changed

control/autoware_pid_longitudinal_controller/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ project(autoware_pid_longitudinal_controller)
44
find_package(autoware_cmake REQUIRED)
55
autoware_package()
66

7+
find_package(fmt REQUIRED)
8+
79
set(PID_LON_CON_LIB ${PROJECT_NAME}_lib)
810
ament_auto_add_library(${PID_LON_CON_LIB} SHARED
911
DIRECTORY src

control/autoware_pid_longitudinal_controller/include/autoware/pid_longitudinal_controller/pid_longitudinal_controller.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ class PidLongitudinalController : public trajectory_follower::LongitudinalContro
254254
void setupDiagnosticUpdater();
255255
void checkControlState(diagnostic_updater::DiagnosticStatusWrapper & stat);
256256

257+
struct ResultWithReason
258+
{
259+
bool result{false};
260+
std::string reason{""};
261+
};
262+
257263
/**
258264
* @brief set current and previous velocity with received message
259265
* @param [in] msg current state message
@@ -298,6 +304,13 @@ class PidLongitudinalController : public trajectory_follower::LongitudinalContro
298304
*/
299305
Motion calcEmergencyCtrlCmd(const double dt);
300306

307+
/**
308+
* @brief change control state
309+
* @param [in] new state
310+
* @param [in] reason to change control state
311+
*/
312+
void changeControlState(const ControlState & control_state, const std::string & reason = "");
313+
301314
/**
302315
* @brief update control state according to the current situation
303316
* @param [in] control_data control data

control/autoware_pid_longitudinal_controller/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<maintainer email="takamasa.horibe@tier4.jp">Takamasa Horibe</maintainer>
99
<maintainer email="takayuki.murooka@tier4.jp">Takayuki Murooka</maintainer>
1010
<maintainer email="mamoru.sobue@tier4.jp">Mamoru Sobue</maintainer>
11+
<maintainer email="yuki.takagi@tier4.jp">Yuki Takagi</maintainer>
1112

1213
<license>Apache 2.0</license>
1314

control/autoware_pid_longitudinal_controller/src/pid_longitudinal_controller.cpp

+40-31
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "autoware/universe_utils/geometry/geometry.hpp"
1919
#include "autoware/universe_utils/math/normalization.hpp"
2020

21+
#include <fmt/format.h>
22+
2123
#include <algorithm>
2224
#include <limits>
2325
#include <memory>
@@ -424,7 +426,8 @@ trajectory_follower::LongitudinalOutput PidLongitudinalController::run(
424426
// self pose is far from trajectory
425427
if (control_data.is_far_from_trajectory) {
426428
if (m_enable_large_tracking_error_emergency) {
427-
m_control_state = ControlState::EMERGENCY; // update control state
429+
// update control state
430+
changeControlState(ControlState::EMERGENCY, "the tracking error is too large");
428431
}
429432
const Motion raw_ctrl_cmd = calcEmergencyCtrlCmd(control_data.dt); // calculate control command
430433
m_prev_raw_ctrl_cmd = raw_ctrl_cmd;
@@ -606,13 +609,23 @@ PidLongitudinalController::Motion PidLongitudinalController::calcEmergencyCtrlCm
606609
longitudinal_utils::applyDiffLimitFilter(raw_ctrl_cmd.acc, m_prev_raw_ctrl_cmd.acc, dt, p.jerk);
607610
m_debug_values.setValues(DebugValues::TYPE::ACC_CMD_JERK_LIMITED, raw_ctrl_cmd.acc);
608611

609-
RCLCPP_ERROR_THROTTLE(
610-
logger_, *clock_, 3000, "[Emergency stop] vel: %3.3f, acc: %3.3f", raw_ctrl_cmd.vel,
611-
raw_ctrl_cmd.acc);
612-
613612
return raw_ctrl_cmd;
614613
}
615614

615+
void PidLongitudinalController::changeControlState(
616+
const ControlState & control_state, const std::string & reason)
617+
{
618+
if (control_state != m_control_state) {
619+
RCLCPP_DEBUG_STREAM(
620+
logger_,
621+
"controller state changed: " << toStr(m_control_state) << " -> " << toStr(control_state));
622+
if (control_state == ControlState::EMERGENCY) {
623+
RCLCPP_ERROR(logger_, "Emergency Stop since %s", reason.c_str());
624+
}
625+
}
626+
m_control_state = control_state;
627+
}
628+
616629
void PidLongitudinalController::updateControlState(const ControlData & control_data)
617630
{
618631
const double current_vel = control_data.current_motion.vel;
@@ -662,19 +675,16 @@ void PidLongitudinalController::updateControlState(const ControlData & control_d
662675
// ==========================================================================================
663676
const double current_vel_cmd = std::fabs(
664677
control_data.interpolated_traj.points.at(control_data.nearest_idx).longitudinal_velocity_mps);
665-
const bool emergency_condition = m_enable_overshoot_emergency &&
666-
stop_dist < -p.emergency_state_overshoot_stop_dist &&
667-
current_vel_cmd < vel_epsilon;
668-
const bool has_nonzero_target_vel = std::abs(current_vel_cmd) > 1.0e-5;
669-
670-
const auto changeState = [this](const auto s) {
671-
if (s != m_control_state) {
672-
RCLCPP_DEBUG_STREAM(
673-
logger_, "controller state changed: " << toStr(m_control_state) << " -> " << toStr(s));
678+
const auto emergency_condition = [&]() {
679+
if (
680+
m_enable_overshoot_emergency && stop_dist < -p.emergency_state_overshoot_stop_dist &&
681+
current_vel_cmd < vel_epsilon) {
682+
return ResultWithReason{
683+
true, fmt::format("the target velocity {} is less than {}", current_vel_cmd, vel_epsilon)};
674684
}
675-
m_control_state = s;
676-
return;
677-
};
685+
return ResultWithReason{false};
686+
}();
687+
const bool has_nonzero_target_vel = std::abs(current_vel_cmd) > 1.0e-5;
678688

679689
const auto debug_msg_once = [this](const auto & s) { RCLCPP_DEBUG_ONCE(logger_, "%s", s); };
680690

@@ -694,11 +704,11 @@ void PidLongitudinalController::updateControlState(const ControlData & control_d
694704
// transit state
695705
// in DRIVE state
696706
if (m_control_state == ControlState::DRIVE) {
697-
if (emergency_condition) {
698-
return changeState(ControlState::EMERGENCY);
707+
if (emergency_condition.result) {
708+
return changeControlState(ControlState::EMERGENCY, emergency_condition.reason);
699709
}
700710
if (!is_under_control && stopped_condition) {
701-
return changeState(ControlState::STOPPED);
711+
return changeControlState(ControlState::STOPPED);
702712
}
703713

704714
if (m_enable_smooth_stop) {
@@ -709,31 +719,31 @@ void PidLongitudinalController::updateControlState(const ControlData & control_d
709719
control_data.stop_dist -
710720
0.5 * (pred_vel_in_target + current_vel) * m_delay_compensation_time;
711721
m_smooth_stop.init(pred_vel_in_target, pred_stop_dist);
712-
return changeState(ControlState::STOPPING);
722+
return changeControlState(ControlState::STOPPING);
713723
}
714724
} else {
715725
if (stopped_condition && !departure_condition_from_stopped) {
716-
return changeState(ControlState::STOPPED);
726+
return changeControlState(ControlState::STOPPED);
717727
}
718728
}
719729
return;
720730
}
721731

722732
// in STOPPING state
723733
if (m_control_state == ControlState::STOPPING) {
724-
if (emergency_condition) {
725-
return changeState(ControlState::EMERGENCY);
734+
if (emergency_condition.result) {
735+
return changeControlState(ControlState::EMERGENCY, emergency_condition.reason);
726736
}
727737
if (stopped_condition) {
728-
return changeState(ControlState::STOPPED);
738+
return changeControlState(ControlState::STOPPED);
729739
}
730740

731741
if (departure_condition_from_stopping) {
732742
m_pid_vel.reset();
733743
m_lpf_vel_error->reset(0.0);
734744
// prevent the car from taking a long time to start to move
735745
m_prev_ctrl_cmd.acc = std::max(0.0, m_prev_raw_ctrl_cmd.acc);
736-
return changeState(ControlState::DRIVE);
746+
return changeControlState(ControlState::DRIVE);
737747
}
738748
return;
739749
}
@@ -779,7 +789,7 @@ void PidLongitudinalController::updateControlState(const ControlData & control_d
779789
m_pid_vel.reset();
780790
m_lpf_vel_error->reset(0.0);
781791
m_lpf_acc_error->reset(0.0);
782-
return changeState(ControlState::DRIVE);
792+
return changeControlState(ControlState::DRIVE);
783793
}
784794

785795
return;
@@ -788,13 +798,13 @@ void PidLongitudinalController::updateControlState(const ControlData & control_d
788798
// in EMERGENCY state
789799
if (m_control_state == ControlState::EMERGENCY) {
790800
if (stopped_condition) {
791-
return changeState(ControlState::STOPPED);
801+
return changeControlState(ControlState::STOPPED);
792802
}
793803

794-
if (!emergency_condition) {
804+
if (!emergency_condition.result) {
795805
if (!is_under_control) {
796806
// NOTE: On manual driving, no need stopping to exit the emergency.
797-
return changeState(ControlState::DRIVE);
807+
return changeControlState(ControlState::DRIVE);
798808
}
799809
}
800810
return;
@@ -1213,7 +1223,6 @@ void PidLongitudinalController::updateDebugVelAcc(const ControlData & control_da
12131223

12141224
void PidLongitudinalController::setupDiagnosticUpdater()
12151225
{
1216-
diag_updater_->setHardwareID("autoware_pid_longitudinal_controller");
12171226
diag_updater_->add("control_state", this, &PidLongitudinalController::checkControlState);
12181227
}
12191228

0 commit comments

Comments
 (0)