17
17
#include " tf2/LinearMath/Matrix3x3.h"
18
18
#include " tf2/LinearMath/Quaternion.h"
19
19
20
- #include < experimental/optional> // NOLINT
21
-
22
20
#ifdef ROS_DISTRO_GALACTIC
23
21
#include " tf2_geometry_msgs/tf2_geometry_msgs.h"
24
22
#else
28
26
#include < algorithm>
29
27
#include < limits>
30
28
31
- namespace autoware ::motion::control::pid_longitudinal_controller
32
- {
33
- namespace longitudinal_utils
29
+ namespace autoware ::motion::control::pid_longitudinal_controller::longitudinal_utils
34
30
{
35
31
36
32
bool isValidTrajectory (const Trajectory & traj)
@@ -48,11 +44,7 @@ bool isValidTrajectory(const Trajectory & traj)
48
44
}
49
45
50
46
// when trajectory is empty
51
- if (traj.points .empty ()) {
52
- return false ;
53
- }
54
-
55
- return true ;
47
+ return !traj.points .empty ();
56
48
}
57
49
58
50
double calcStopDistance (
@@ -75,7 +67,9 @@ double calcStopDistance(
75
67
76
68
double getPitchByPose (const Quaternion & quaternion_msg)
77
69
{
78
- double roll, pitch, yaw;
70
+ double roll{0.0 };
71
+ double pitch{0.0 };
72
+ double yaw{0.0 };
79
73
tf2::Quaternion quaternion;
80
74
tf2::fromMsg (quaternion_msg, quaternion);
81
75
tf2::Matrix3x3{quaternion}.getRPY (roll, pitch, yaw);
@@ -128,12 +122,11 @@ double calcElevationAngle(const TrajectoryPoint & p_from, const TrajectoryPoint
128
122
return pitch;
129
123
}
130
124
131
- Pose calcPoseAfterTimeDelay (
132
- const Pose & current_pose, const double delay_time, const double current_vel,
133
- const double current_acc)
125
+ std::pair<double , double > calcDistAndVelAfterTimeDelay (
126
+ const double delay_time, const double current_vel, const double current_acc)
134
127
{
135
128
if (delay_time <= 0.0 ) {
136
- return current_pose ;
129
+ return std::make_pair ( 0.0 , 0.0 ) ;
137
130
}
138
131
139
132
// check time to stop
@@ -142,17 +135,11 @@ Pose calcPoseAfterTimeDelay(
142
135
const double delay_time_calculation =
143
136
time_to_stop > 0.0 && time_to_stop < delay_time ? time_to_stop : delay_time;
144
137
// simple linear prediction
145
- const double yaw = tf2::getYaw (current_pose. orientation ) ;
138
+ const double vel_after_delay = current_vel + current_acc * delay_time_calculation ;
146
139
const double running_distance = delay_time_calculation * current_vel + 0.5 * current_acc *
147
140
delay_time_calculation *
148
141
delay_time_calculation;
149
- const double dx = running_distance * std::cos (yaw);
150
- const double dy = running_distance * std::sin (yaw);
151
-
152
- auto pred_pose = current_pose;
153
- pred_pose.position .x += dx;
154
- pred_pose.position .y += dy;
155
- return pred_pose;
142
+ return std::make_pair (running_distance, vel_after_delay);
156
143
}
157
144
158
145
double lerp (const double v_from, const double v_to, const double ratio)
@@ -162,7 +149,8 @@ double lerp(const double v_from, const double v_to, const double ratio)
162
149
163
150
Quaternion lerpOrientation (const Quaternion & o_from, const Quaternion & o_to, const double ratio)
164
151
{
165
- tf2::Quaternion q_from, q_to;
152
+ tf2::Quaternion q_from;
153
+ tf2::Quaternion q_to;
166
154
tf2::fromMsg (o_from, q_from);
167
155
tf2::fromMsg (o_to, q_to);
168
156
@@ -187,5 +175,35 @@ double applyDiffLimitFilter(
187
175
const double min_val = -max_val;
188
176
return applyDiffLimitFilter (input_val, prev_val, dt, max_val, min_val);
189
177
}
190
- } // namespace longitudinal_utils
191
- } // namespace autoware::motion::control::pid_longitudinal_controller
178
+
179
+ geometry_msgs::msg::Pose findTrajectoryPoseAfterDistance (
180
+ const size_t src_idx, const double distance,
181
+ const autoware_auto_planning_msgs::msg::Trajectory & trajectory)
182
+ {
183
+ double remain_dist = distance;
184
+ geometry_msgs::msg::Pose p = trajectory.points .back ().pose ;
185
+ for (size_t i = src_idx; i < trajectory.points .size () - 1 ; ++i) {
186
+ const double dist = tier4_autoware_utils::calcDistance3d (
187
+ trajectory.points .at (i).pose , trajectory.points .at (i + 1 ).pose );
188
+ if (remain_dist < dist) {
189
+ if (remain_dist <= 0.0 ) {
190
+ return trajectory.points .at (i).pose ;
191
+ }
192
+ double ratio = remain_dist / dist;
193
+ p = trajectory.points .at (i).pose ;
194
+ p.position .x = trajectory.points .at (i).pose .position .x +
195
+ ratio * (trajectory.points .at (i + 1 ).pose .position .x -
196
+ trajectory.points .at (i).pose .position .x );
197
+ p.position .y = trajectory.points .at (i).pose .position .y +
198
+ ratio * (trajectory.points .at (i + 1 ).pose .position .y -
199
+ trajectory.points .at (i).pose .position .y );
200
+ p.position .z = trajectory.points .at (i).pose .position .z +
201
+ ratio * (trajectory.points .at (i + 1 ).pose .position .z -
202
+ trajectory.points .at (i).pose .position .z );
203
+ break ;
204
+ }
205
+ remain_dist -= dist;
206
+ }
207
+ return p;
208
+ }
209
+ } // namespace autoware::motion::control::pid_longitudinal_controller::longitudinal_utils
0 commit comments