Autoware.Auto
longitudinal_controller_utils.hpp
Go to the documentation of this file.
1 // Copyright 2018-2021 Tier IV, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef TRAJECTORY_FOLLOWER__LONGITUDINAL_CONTROLLER_UTILS_HPP_
16 #define TRAJECTORY_FOLLOWER__LONGITUDINAL_CONTROLLER_UTILS_HPP_
17 
18 #include <cmath>
19 #include <experimental/optional> // NOLINT
20 #include <limits>
21 
22 #include "eigen3/Eigen/Core"
23 #include "eigen3/Eigen/Geometry"
24 
25 #include "autoware_auto_planning_msgs/msg/trajectory.hpp"
26 #include "common/types.hpp"
27 #include "geometry_msgs/msg/pose.hpp"
28 #include "geometry/common_2d.hpp"
31 #include "tf2/utils.h"
33 
34 namespace autoware
35 {
36 namespace motion
37 {
38 namespace control
39 {
40 namespace trajectory_follower
41 {
42 namespace longitudinal_utils
43 {
49 using geometry_msgs::msg::Pose;
50 using geometry_msgs::msg::Quaternion;
51 namespace motion_common = ::motion::motion_common;
52 namespace trajectory_common = ::autoware::motion::motion_common;
53 
57 TRAJECTORY_FOLLOWER_PUBLIC bool8_t isValidTrajectory(const Trajectory & traj);
58 
62 TRAJECTORY_FOLLOWER_PUBLIC float64_t calcStopDistance(
63  const Point & current_pos,
64  const Trajectory & traj);
65 
69 TRAJECTORY_FOLLOWER_PUBLIC float64_t getPitchByPose(const Quaternion & quaternion);
70 
78 TRAJECTORY_FOLLOWER_PUBLIC float64_t getPitchByTraj(
79  const Trajectory & trajectory, const size_t closest_idx,
80  const float64_t wheel_base);
81 
85 TRAJECTORY_FOLLOWER_PUBLIC float64_t calcElevationAngle(
86  const TrajectoryPoint & p_from,
87  const TrajectoryPoint & p_to);
88 
92 TRAJECTORY_FOLLOWER_PUBLIC Pose calcPoseAfterTimeDelay(
93  const Pose & current_pose, const float64_t delay_time, const float64_t current_vel);
94 
101 TRAJECTORY_FOLLOWER_PUBLIC Quaternion lerpOrientation(
102  const Quaternion & o_from,
103  const Quaternion & o_to,
104  const float64_t ratio);
105 
111 template<class T>
112 TRAJECTORY_FOLLOWER_PUBLIC
113 TrajectoryPoint lerpTrajectoryPoint(const T & points, const Point & point)
114 {
115  TrajectoryPoint interpolated_point;
116 
117  const size_t nearest_seg_idx = trajectory_common::findNearestSegmentIndex(points, point);
118 
119  const float64_t len_to_interpolated =
120  trajectory_common::calcLongitudinalOffsetToSegment(points, nearest_seg_idx, point);
121  const float64_t len_segment =
122  trajectory_common::calcSignedArcLength(points, nearest_seg_idx, nearest_seg_idx + 1);
123  const float64_t interpolate_ratio = len_to_interpolated / len_segment;
124 
125  {
126  const size_t i = nearest_seg_idx;
127 
128  interpolated_point.pose.position.x = motion_common::interpolate(
129  points.at(i).pose.position.x, points.at(
130  i + 1).pose.position.x, interpolate_ratio);
131  interpolated_point.pose.position.y = motion_common::interpolate(
132  points.at(i).pose.position.y, points.at(
133  i + 1).pose.position.y, interpolate_ratio);
134  interpolated_point.pose.orientation = lerpOrientation(
135  points.at(i).pose.orientation, points.at(i + 1).pose.orientation, interpolate_ratio);
136  interpolated_point.longitudinal_velocity_mps =
138  points.at(i).longitudinal_velocity_mps, points.at(
139  i + 1).longitudinal_velocity_mps, interpolate_ratio);
140  interpolated_point.lateral_velocity_mps =
142  points.at(i).lateral_velocity_mps, points.at(
143  i + 1).lateral_velocity_mps, interpolate_ratio);
144  interpolated_point.acceleration_mps2 =
146  points.at(i).acceleration_mps2, points.at(
147  i + 1).acceleration_mps2, interpolate_ratio);
148  interpolated_point.heading_rate_rps =
150  points.at(i).heading_rate_rps, points.at(
151  i + 1).heading_rate_rps, interpolate_ratio);
152  }
153 
154  return interpolated_point;
155 }
156 
164 TRAJECTORY_FOLLOWER_PUBLIC float64_t applyDiffLimitFilter(
165  const float64_t input_val, const float64_t prev_val, const float64_t dt, const float64_t lim_val);
166 
175 TRAJECTORY_FOLLOWER_PUBLIC float64_t applyDiffLimitFilter(
176  const float64_t input_val, const float64_t prev_val, const float64_t dt, const float64_t max_val,
177  const float64_t min_val);
178 } // namespace longitudinal_utils
179 } // namespace trajectory_follower
180 } // namespace control
181 } // namespace motion
182 } // namespace autoware
183 
184 #endif // TRAJECTORY_FOLLOWER__LONGITUDINAL_CONTROLLER_UTILS_HPP_
motion::motion_testing_nodes::TrajectoryPoint
autoware_auto_planning_msgs::msg::TrajectoryPoint TrajectoryPoint
Definition: motion_testing_publisher.hpp:36
autoware::motion::motion_common::findNearestSegmentIndex
MOTION_COMMON_PUBLIC size_t findNearestSegmentIndex(const Points &points, const geometry_msgs::msg::Point &point)
find nearest segment index to point segment is straight path between two continuous points of traject...
Definition: trajectory_common.cpp:137
visibility_control.hpp
types.hpp
This file includes common type definition.
autoware::motion::control::trajectory_follower::longitudinal_utils::applyDiffLimitFilter
TRAJECTORY_FOLLOWER_PUBLIC float64_t applyDiffLimitFilter(const float64_t input_val, const float64_t prev_val, const float64_t dt, const float64_t lim_val)
limit variable whose differential is within a certain value
Definition: longitudinal_controller_utils.cpp:176
autoware::motion::motion_common
Definition: trajectory_common.hpp:37
common_2d.hpp
This file includes common functionality for 2D geometry, such as dot products.
trajectory_common.hpp
autoware::motion::motion_common::calcLongitudinalOffsetToSegment
MOTION_COMMON_PUBLIC float64_t calcLongitudinalOffsetToSegment(const Points &points, const size_t seg_idx, const geometry_msgs::msg::Point &p_target)
calculate length along trajectory from seg_idx point to nearest point to p_target on trajectory If se...
Definition: trajectory_common.cpp:114
autoware::motion::motion_common::calcSignedArcLength
MOTION_COMMON_PUBLIC float64_t calcSignedArcLength(const Points &points, const size_t src_idx, const size_t dst_idx)
calculate arc length along points
Definition: trajectory_common.cpp:156
autoware::motion::control::trajectory_follower::longitudinal_utils::lerpTrajectoryPoint
TRAJECTORY_FOLLOWER_PUBLIC TrajectoryPoint lerpTrajectoryPoint(const T &points, const Point &point)
apply linear interpolation to trajectory point that is nearest to a certain point
Definition: longitudinal_controller_utils.hpp:113
autoware::common::types::bool8_t
bool bool8_t
Definition: types.hpp:39
time_utils::interpolate
TIME_UTILS_PUBLIC std::chrono::nanoseconds interpolate(std::chrono::nanoseconds a, std::chrono::nanoseconds b, float t) noexcept
Standard interpolation.
Definition: time_utils.cpp:96
autoware::motion::control::trajectory_follower::longitudinal_utils::getPitchByPose
TRAJECTORY_FOLLOWER_PUBLIC float64_t getPitchByPose(const Quaternion &quaternion)
calculate pitch angle from estimated current pose
Definition: longitudinal_controller_utils.cpp:75
autoware
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
autoware::motion::control::trajectory_follower::longitudinal_utils::calcStopDistance
TRAJECTORY_FOLLOWER_PUBLIC float64_t calcStopDistance(const Point &current_pos, const Trajectory &traj)
calculate distance to stopline from current vehicle position where velocity is 0
Definition: longitudinal_controller_utils.cpp:61
autoware::motion::control::trajectory_follower::longitudinal_utils::isValidTrajectory
TRAJECTORY_FOLLOWER_PUBLIC bool8_t isValidTrajectory(const Trajectory &traj)
check if trajectory is invalid or not
Definition: longitudinal_controller_utils.cpp:38
motion_common.hpp
autoware::motion::control::trajectory_follower
Definition: debug_values.hpp:29
autoware::motion::control::trajectory_follower::longitudinal_utils::calcPoseAfterTimeDelay
TRAJECTORY_FOLLOWER_PUBLIC Pose calcPoseAfterTimeDelay(const Pose &current_pose, const float64_t delay_time, const float64_t current_vel)
calculate vehicle pose after time delay by moving the vehicle at current velocity for delayed time
Definition: longitudinal_controller_utils.cpp:135
motion
Definition: controller_base.hpp:31
autoware::motion::control::trajectory_follower::longitudinal_utils::getPitchByTraj
TRAJECTORY_FOLLOWER_PUBLIC float64_t getPitchByTraj(const Trajectory &trajectory, const size_t closest_idx, const float64_t wheel_base)
calculate pitch angle from trajectory on map NOTE: there is currently no z information so this always...
Definition: longitudinal_controller_utils.cpp:85
autoware::motion::control::trajectory_follower::longitudinal_utils::calcElevationAngle
TRAJECTORY_FOLLOWER_PUBLIC float64_t calcElevationAngle(const TrajectoryPoint &p_from, const TrajectoryPoint &p_to)
calculate elevation angle
Definition: longitudinal_controller_utils.cpp:123
motion::motion_common::Trajectory
autoware_auto_planning_msgs::msg::Trajectory Trajectory
Definition: motion_common.hpp:41
Point
geometry_msgs::msg::Point32 Point
Definition: cluster2d.cpp:28
autoware::common::types::float64_t
double float64_t
Definition: types.hpp:47
autoware::motion::control::trajectory_follower::longitudinal_utils::lerpOrientation
TRAJECTORY_FOLLOWER_PUBLIC Quaternion lerpOrientation(const Quaternion &o_from, const Quaternion &o_to, const float64_t ratio)
apply linear interpolation to orientation
Definition: longitudinal_controller_utils.cpp:155