Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pid_longitudinal_control): slope definition #5116

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions control/pid_longitudinal_controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ For instance, if the vehicle is attempting to start with an acceleration of `1.0

A suitable example of a vehicle system for the slope compensation function is one in which the output acceleration from the longitudinal_controller is converted into target accel/brake pedal input without any feedbacks. In this case, the output acceleration is just used as a feedforward term to calculate the target pedal, and hence the issue mentioned above does not arise.

Note: The angle of the slope is defined as positive for an uphill slope, while the pitch angle of the ego pose is defined as negative when facing upward. They have an opposite definition.

![slope_definition](./media/slope_definition.drawio.svg)

#### PID control

For deviations that cannot be handled by FeedForward control, such as model errors, PID control is used to construct a feedback system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ double calcStopDistance(
/**
* @brief calculate pitch angle from estimated current pose
*/
double getPitchByPose(const Quaternion & quaternion);
double getSlopeByPose(const Quaternion & quaternion);

/**
* @brief calculate pitch angle from trajectory on map
Expand All @@ -63,7 +63,7 @@ double getPitchByPose(const Quaternion & quaternion);
* @param [in] closest_idx nearest index to current vehicle position
* @param [in] wheel_base length of wheel base
*/
double getPitchByTraj(
double getSlopeByTraj(
const Trajectory & trajectory, const size_t closest_idx, const double wheel_base);

/**
Expand Down
165 changes: 165 additions & 0 deletions control/pid_longitudinal_controller/media/slope_definition.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,25 @@ double calcStopDistance(
return signed_length_on_traj;
}

double getPitchByPose(const Quaternion & quaternion_msg)
// Calculate pitch angle from ego_pose information.
// The angle of the slope is defined as positive for an uphill slope.
double getSlopeByPose(const Quaternion & quaternion_msg)
{
double roll, pitch, yaw;
tf2::Quaternion quaternion;
tf2::fromMsg(quaternion_msg, quaternion);
tf2::Matrix3x3{quaternion}.getRPY(roll, pitch, yaw);

return pitch;
// The pitch angle of the posture is defined as positive when facing downward.
// Thus, the definition is the opposite of the slope.
const auto slope = -pitch;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main fix of this PR.


return slope;
}

double getPitchByTraj(
// Calculate pitch angle from trajectory information.
// The angle of the slope is defined as positive for an uphill slope.
double getSlopeByTraj(
const Trajectory & trajectory, const size_t nearest_idx, const double wheel_base)
{
// cannot calculate pitch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,9 @@ PidLongitudinalController::ControlData PidLongitudinalController::getControlData
current_pose, m_trajectory, m_ego_nearest_dist_threshold, m_ego_nearest_yaw_threshold);

// pitch
const double raw_pitch = longitudinal_utils::getPitchByPose(current_pose.orientation);
const double raw_pitch = longitudinal_utils::getSlopeByPose(current_pose.orientation);
const double traj_pitch =
longitudinal_utils::getPitchByTraj(m_trajectory, control_data.nearest_idx, m_wheel_base);
longitudinal_utils::getSlopeByTraj(m_trajectory, control_data.nearest_idx, m_wheel_base);
control_data.slope_angle = m_use_traj_for_pitch ? traj_pitch : m_lpf_pitch->filter(raw_pitch);
updatePitchDebugValues(control_data.slope_angle, traj_pitch, raw_pitch);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,20 @@ TEST(TestLongitudinalControllerUtils, calcStopDistance)
EXPECT_EQ(longitudinal_utils::calcStopDistance(current_pose, traj, max_dist, max_yaw), 3.0);
}

TEST(TestLongitudinalControllerUtils, getPitchByPose)
TEST(TestLongitudinalControllerUtils, getSlopeByPose)
{
// NOTE: the slope is defined as positive for an uphill slope, while the pitch is defined as
// positive when facing downward. They are opposite.
tf2::Quaternion quaternion_tf;
quaternion_tf.setRPY(0.0, 0.0, 0.0);
EXPECT_EQ(longitudinal_utils::getPitchByPose(tf2::toMsg(quaternion_tf)), 0.0);
EXPECT_EQ(longitudinal_utils::getSlopeByPose(tf2::toMsg(quaternion_tf)), 0.0);
quaternion_tf.setRPY(0.0, 1.0, 0.0);
EXPECT_EQ(longitudinal_utils::getPitchByPose(tf2::toMsg(quaternion_tf)), 1.0);
EXPECT_EQ(longitudinal_utils::getSlopeByPose(tf2::toMsg(quaternion_tf)), -1.0);
quaternion_tf.setRPY(0.0, 0.1, 0.0);
EXPECT_EQ(longitudinal_utils::getSlopeByPose(tf2::toMsg(quaternion_tf)), -0.1);
}

TEST(TestLongitudinalControllerUtils, getPitchByTraj)
TEST(TestLongitudinalControllerUtils, getSlopeByTraj)
{
using autoware_auto_planning_msgs::msg::Trajectory;
using autoware_auto_planning_msgs::msg::TrajectoryPoint;
Expand Down Expand Up @@ -144,17 +148,17 @@ TEST(TestLongitudinalControllerUtils, getPitchByTraj)
traj.points.push_back(point);
size_t closest_idx = 0;
EXPECT_DOUBLE_EQ(
std::abs(longitudinal_utils::getPitchByTraj(traj, closest_idx, wheel_base)), M_PI_4);
std::abs(longitudinal_utils::getSlopeByTraj(traj, closest_idx, wheel_base)), M_PI_4);
closest_idx = 1;
EXPECT_DOUBLE_EQ(
std::abs(longitudinal_utils::getPitchByTraj(traj, closest_idx, wheel_base)), M_PI_4);
std::abs(longitudinal_utils::getSlopeByTraj(traj, closest_idx, wheel_base)), M_PI_4);
closest_idx = 2;
EXPECT_DOUBLE_EQ(
std::abs(longitudinal_utils::getPitchByTraj(traj, closest_idx, wheel_base)),
std::abs(longitudinal_utils::getSlopeByTraj(traj, closest_idx, wheel_base)),
std::atan2(0.5, 1));
closest_idx = 3;
EXPECT_DOUBLE_EQ(
std::abs(longitudinal_utils::getPitchByTraj(traj, closest_idx, wheel_base)),
std::abs(longitudinal_utils::getSlopeByTraj(traj, closest_idx, wheel_base)),
std::atan2(0.5, 1));
}

Expand Down
Loading