@@ -102,7 +102,7 @@ PidLongitudinalController::PidLongitudinalController(rclcpp::Node & node)
102
102
103
103
// set lowpass filter for vel error and pitch
104
104
const double lpf_vel_error_gain{node.declare_parameter <double >(" lpf_vel_error_gain" )};
105
- m_lpf_vel_error = std::make_shared <LowpassFilter1d>(0.0 , lpf_vel_error_gain);
105
+ m_lpf_vel_error = std::make_unique <LowpassFilter1d>(0.0 , lpf_vel_error_gain);
106
106
107
107
m_enable_integration_at_low_speed =
108
108
node.declare_parameter <bool >(" enable_integration_at_low_speed" );
@@ -162,6 +162,13 @@ PidLongitudinalController::PidLongitudinalController(rclcpp::Node & node)
162
162
p.jerk = node.declare_parameter <double >(" emergency_jerk" ); // [m/s^3]
163
163
}
164
164
165
+ // parameters for acc feedback
166
+ {
167
+ const double lpf_acc_error_gain{node.declare_parameter <double >(" lpf_acc_error_gain" )};
168
+ m_lpf_acc_error = std::make_unique<LowpassFilter1d>(0.0 , lpf_acc_error_gain);
169
+ m_acc_feedback_gain = node.declare_parameter <double >(" acc_feedback_gain" );
170
+ }
171
+
165
172
// parameters for acceleration limit
166
173
m_max_acc = node.declare_parameter <double >(" max_acc" ); // [m/s^2]
167
174
m_min_acc = node.declare_parameter <double >(" min_acc" ); // [m/s^2]
@@ -175,7 +182,7 @@ PidLongitudinalController::PidLongitudinalController(rclcpp::Node & node)
175
182
m_adaptive_trajectory_velocity_th =
176
183
node.declare_parameter <double >(" adaptive_trajectory_velocity_th" ); // [m/s^2]
177
184
const double lpf_pitch_gain{node.declare_parameter <double >(" lpf_pitch_gain" )};
178
- m_lpf_pitch = std::make_shared <LowpassFilter1d>(0.0 , lpf_pitch_gain);
185
+ m_lpf_pitch = std::make_unique <LowpassFilter1d>(0.0 , lpf_pitch_gain);
179
186
m_max_pitch_rad = node.declare_parameter <double >(" max_pitch_rad" ); // [rad]
180
187
m_min_pitch_rad = node.declare_parameter <double >(" min_pitch_rad" ); // [rad]
181
188
@@ -363,6 +370,9 @@ rcl_interfaces::msg::SetParametersResult PidLongitudinalController::paramCallbac
363
370
update_param (" emergency_jerk" , p.jerk );
364
371
}
365
372
373
+ // acceleration limit
374
+ update_param (" acc_feedback_gain" , m_acc_feedback_gain);
375
+
366
376
// acceleration limit
367
377
update_param (" min_acc" , m_min_acc);
368
378
@@ -842,8 +852,22 @@ PidLongitudinalController::Motion PidLongitudinalController::calcCtrlCmd(
842
852
// store acceleration without slope compensation
843
853
m_prev_raw_ctrl_cmd = raw_ctrl_cmd;
844
854
855
+ // calc acc feedback
856
+ const double acc_err = control_data.current_motion .acc - raw_ctrl_cmd.acc ;
857
+ m_debug_values.setValues (DebugValues::TYPE::ERROR_ACC, acc_err);
858
+ m_lpf_acc_error->filter (acc_err);
859
+ m_debug_values.setValues (DebugValues::TYPE::ERROR_ACC_FILTERED, m_lpf_acc_error->getValue ());
860
+
861
+ const double acc_cmd = raw_ctrl_cmd.acc - m_lpf_acc_error->getValue () * m_acc_feedback_gain;
862
+ m_debug_values.setValues (DebugValues::TYPE::ACC_CMD_ACC_FB_APPLIED, acc_cmd);
863
+ RCLCPP_DEBUG (
864
+ logger_,
865
+ " [acc feedback]: raw_ctrl_cmd.acc: %1.3f, control_data.current_motion.acc: %1.3f, "
866
+ " m_lpf_acc_error.getValue(): %1.3f, acc_cmd: %1.3f" ,
867
+ raw_ctrl_cmd.acc , control_data.current_motion .acc , 0.0 , acc_cmd);
868
+
845
869
ctrl_cmd_as_pedal_pos.acc =
846
- applySlopeCompensation (raw_ctrl_cmd. acc , control_data.slope_angle , control_data.shift );
870
+ applySlopeCompensation (acc_cmd , control_data.slope_angle , control_data.shift );
847
871
m_debug_values.setValues (DebugValues::TYPE::ACC_CMD_SLOPE_APPLIED, ctrl_cmd_as_pedal_pos.acc );
848
872
ctrl_cmd_as_pedal_pos.vel = raw_ctrl_cmd.vel ;
849
873
}
0 commit comments