Skip to content

Commit 9aae0a9

Browse files
minor refactor for updateOffset
Signed-off-by: kyoichi-sugahara <kyoichi.sugahara@tier4.jp>
1 parent 5d6449d commit 9aae0a9

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

control/mpc_lateral_controller/include/mpc_lateral_controller/steering_offset/steering_offset.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class SteeringOffsetEstimator
3030
~SteeringOffsetEstimator() = default;
3131

3232
double getOffset() const;
33-
void updateOffset(const geometry_msgs::msg::Twist & twist, const double steering);
33+
void updateOffset(const geometry_msgs::msg::Twist & twist, const double measured_steering_angle);
3434

3535
private:
3636
// parameters

control/mpc_lateral_controller/src/steering_offset/steering_offset.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ SteeringOffsetEstimator::SteeringOffsetEstimator(
3030
}
3131

3232
void SteeringOffsetEstimator::updateOffset(
33-
const geometry_msgs::msg::Twist & twist, const double steering)
33+
const geometry_msgs::msg::Twist & twist, const double measured_steering_angle)
3434
{
3535
const bool update_offset =
3636
(std::abs(twist.linear.x) > update_vel_threshold_ &&
37-
std::abs(steering) < update_steer_threshold_);
37+
std::abs(measured_steering_angle) < update_steer_threshold_);
3838

3939
if (!update_offset) return;
4040

41-
const auto steer_angvel = std::atan2(twist.angular.z * wheelbase_, twist.linear.x);
42-
const auto steer_offset = steering - steer_angvel;
41+
// calculate the steering angle needed to achieve the current rate of rotation given the current
42+
// velocity along the x-axis of the vehicle, under the below assumptions
43+
// (i.e., no slipping, no lag in the steering mechanism, etc.).
44+
const auto expected_steering_angle = std::atan2(twist.angular.z * wheelbase_, twist.linear.x);
45+
const auto steer_offset = measured_steering_angle - expected_steering_angle;
4346
steering_offset_storage_.push_back(steer_offset);
4447
if (steering_offset_storage_.size() > average_num_) {
4548
steering_offset_storage_.pop_front();

0 commit comments

Comments
 (0)