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

refactor(pid_longitudinal_controller): use common elevetation angle calculation #5090

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ double getPitchByPose(const Quaternion & quaternion);
double getPitchByTraj(
const Trajectory & trajectory, const size_t closest_idx, const double wheel_base);

/**
* @brief calculate elevation angle
*/
double calcElevationAngle(const TrajectoryPoint & p_from, const TrajectoryPoint & p_to);

/**
* @brief calculate vehicle pose after time delay by moving the vehicle at current velocity and
* acceleration for delayed time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ double getPitchByTraj(
trajectory.points.at(nearest_idx), trajectory.points.at(i));
if (dist > wheel_base) {
// calculate pitch from trajectory between rear wheel (nearest) and front center (i)
return calcElevationAngle(trajectory.points.at(nearest_idx), trajectory.points.at(i));
return tier4_autoware_utils::calcElevationAngle(
trajectory.points.at(nearest_idx).pose.position, trajectory.points.at(i).pose.position);
}
}

Expand All @@ -108,24 +109,14 @@ double getPitchByTraj(
if (dist > wheel_base) {
// calculate pitch from trajectory
// between wheelbase behind the end of trajectory (i) and the end of trajectory (back)
return calcElevationAngle(trajectory.points.at(i), trajectory.points.back());
return tier4_autoware_utils::calcElevationAngle(
trajectory.points.at(i).pose.position, trajectory.points.back().pose.position);
}
}

// calculate pitch from trajectory between the beginning and end of trajectory
return calcElevationAngle(trajectory.points.at(0), trajectory.points.back());
}

double calcElevationAngle(const TrajectoryPoint & p_from, const TrajectoryPoint & p_to)
{
const double dx = p_from.pose.position.x - p_to.pose.position.x;
const double dy = p_from.pose.position.y - p_to.pose.position.y;
const double dz = p_from.pose.position.z - p_to.pose.position.z;

const double dxy = std::max(std::hypot(dx, dy), std::numeric_limits<double>::epsilon());
const double pitch = std::atan2(dz, dxy);

return pitch;
return tier4_autoware_utils::calcElevationAngle(
trajectory.points.at(0).pose.position, trajectory.points.back().pose.position);
}

Pose calcPoseAfterTimeDelay(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ double PidLongitudinalController::applySlopeCompensation(
const double pitch_limited = std::min(std::max(pitch, m_min_pitch_rad), m_max_pitch_rad);

// Acceleration command is always positive independent of direction (= shift) when car is running
double sign = (shift == Shift::Forward) ? -1 : (shift == Shift::Reverse ? 1 : 0);
double sign = (shift == Shift::Forward) ? 1.0 : (shift == Shift::Reverse ? -1.0 : 0);
double compensated_acc = input_acc + sign * 9.81 * std::sin(pitch_limited);
return compensated_acc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,33 +158,6 @@ TEST(TestLongitudinalControllerUtils, getPitchByTraj)
std::atan2(0.5, 1));
}

TEST(TestLongitudinalControllerUtils, calcElevationAngle)
{
using autoware_auto_planning_msgs::msg::TrajectoryPoint;
TrajectoryPoint p_from;
p_from.pose.position.x = 0.0;
p_from.pose.position.y = 0.0;
TrajectoryPoint p_to;
p_to.pose.position.x = 1.0;
p_to.pose.position.y = 0.0;
EXPECT_DOUBLE_EQ(longitudinal_utils::calcElevationAngle(p_from, p_to), 0.0);
p_to.pose.position.x = 1.0;
p_to.pose.position.z = 1.0;
EXPECT_DOUBLE_EQ(longitudinal_utils::calcElevationAngle(p_from, p_to), -M_PI_4);
p_to.pose.position.x = -1.0;
p_to.pose.position.z = 1.0;
EXPECT_DOUBLE_EQ(longitudinal_utils::calcElevationAngle(p_from, p_to), -M_PI_4);
p_to.pose.position.x = 0.0;
p_to.pose.position.z = 1.0;
EXPECT_DOUBLE_EQ(longitudinal_utils::calcElevationAngle(p_from, p_to), -M_PI_2);
p_to.pose.position.x = 1.0;
p_to.pose.position.z = -1.0;
EXPECT_DOUBLE_EQ(longitudinal_utils::calcElevationAngle(p_from, p_to), M_PI_4);
p_to.pose.position.x = -1.0;
p_to.pose.position.z = -1.0;
EXPECT_DOUBLE_EQ(longitudinal_utils::calcElevationAngle(p_from, p_to), M_PI_4);
}

TEST(TestLongitudinalControllerUtils, calcPoseAfterTimeDelay)
{
using geometry_msgs::msg::Pose;
Expand Down