Autoware.Auto
motion_testing.hpp
Go to the documentation of this file.
1 // Copyright 2019 Christopher Ho
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 #ifndef MOTION_TESTING__MOTION_TESTING_HPP_
15 #define MOTION_TESTING__MOTION_TESTING_HPP_
16 
18 #include <autoware_auto_msgs/msg/trajectory.hpp>
19 #include <autoware_auto_msgs/msg/vehicle_control_command.hpp>
20 #include <autoware_auto_msgs/msg/vehicle_kinematic_state.hpp>
21 
22 #include <chrono>
23 #include <random>
24 
25 namespace motion
26 {
27 namespace motion_testing
28 {
29 using Generator = std::mt19937;
33 // TODO(c.ho) Make these more modular
34 
36 MOTION_TESTING_PUBLIC State make_state(
37  float x0,
38  float y0,
39  float heading,
40  float v0,
41  float a0,
42  float turn_rate,
43  std::chrono::system_clock::time_point t);
44 
47 MOTION_TESTING_PUBLIC State generate_state(Generator & gen);
48 
52 MOTION_TESTING_PUBLIC Trajectory generate_trajectory(const State & start_state, Generator & gen);
53 
58 MOTION_TESTING_PUBLIC
59 Trajectory constant_trajectory(const State & start_state, std::chrono::nanoseconds dt);
61 
62 MOTION_TESTING_PUBLIC
63 Trajectory bad_heading_trajectory(const State & start_state, std::chrono::nanoseconds dt);
65 
66 MOTION_TESTING_PUBLIC Trajectory constant_velocity_trajectory(
67  float x0,
68  float y0,
69  float heading,
70  float v0,
71  std::chrono::nanoseconds dt);
73 MOTION_TESTING_PUBLIC Trajectory constant_acceleration_trajectory(
74  float x0,
75  float y0,
76  float heading,
77  float v0,
78  float a0,
79  std::chrono::nanoseconds dt);
82  float x0,
83  float y0,
84  float heading,
85  float v0,
86  float turn_rate,
87  std::chrono::nanoseconds dt);
90  float x0,
91  float y0,
92  float heading,
93  float v0,
94  float a0,
95  float turn_rate,
96  std::chrono::nanoseconds dt);
97 
101 MOTION_TESTING_PUBLIC void next_state(
102  const Trajectory & trajectory,
103  State & state,
104  uint32_t hint,
105  Generator * gen = nullptr); // TODO(c.ho) std::optional NOLINT
106 // TODO(c.ho) version that takes control commands
107 
108 using Index = decltype(Trajectory::points)::size_type;
109 using Real = decltype(Point::x);
113 MOTION_TESTING_PUBLIC
115  const Trajectory & trajectory,
116  const Point & target,
117  Real heading_tolerance = Real{0.006F});
118 
122 MOTION_TESTING_PUBLIC
123 Index dynamically_feasible(const Trajectory & trajectory, Real tolerance = 0.05F);
124 } // namespace motion_testing
125 } // namespace motion
126 
127 #endif // MOTION_TESTING__MOTION_TESTING_HPP_
MOTION_TESTING_PUBLIC Trajectory constant_acceleration_turn_rate_trajectory(float x0, float y0, float heading, float v0, float a0, float turn_rate, std::chrono::nanoseconds dt)
Generates a constant acceleration and constant turn rate trajectory.
Definition: motion_testing.cpp:183
autoware_auto_msgs::msg::VehicleKinematicState VehicleKinematicState
Definition: trajectory_spoofer.hpp:44
MOTION_TESTING_PUBLIC void next_state(const Trajectory &trajectory, State &state, uint32_t hint, Generator *gen=nullptr)
Definition: motion_testing.cpp:199
MOTION_TESTING_PUBLIC Trajectory bad_heading_trajectory(const State &start_state, std::chrono::nanoseconds dt)
Generates a constant velocity trajectory.
Definition: motion_testing.cpp:119
autoware_auto_msgs::msg::TrajectoryPoint TrajectoryPoint
Definition: motion_testing_publisher.hpp:36
autoware_auto_msgs::msg::TrajectoryPoint Point
Definition: motion_testing.hpp:31
std::mt19937 Generator
Definition: motion_testing.hpp:29
MOTION_TESTING_PUBLIC Trajectory constant_velocity_turn_rate_trajectory(float x0, float y0, float heading, float v0, float turn_rate, std::chrono::nanoseconds dt)
Generates a constant velocity and constant turn rate trajectory.
Definition: motion_testing.cpp:171
t
Definition: catr_diff.py:22
MOTION_TESTING_PUBLIC Index dynamically_feasible(const Trajectory &trajectory, Real tolerance=0.05F)
Definition: motion_testing.cpp:241
decltype(Trajectory::points)::size_type Index
Definition: motion_testing.hpp:108
DifferentialState x
Definition: kinematic_bicycle.snippet.hpp:28
MOTION_TESTING_PUBLIC Trajectory constant_trajectory(const State &start_state, std::chrono::nanoseconds dt)
Generate a trajectory given the start state, assuming the highest derivatives are held constant...
Definition: motion_testing.cpp:79
Definition: controller_base.hpp:30
autoware_auto_msgs::msg::VehicleKinematicState State
Definition: motion_testing.hpp:30
MOTION_TESTING_PUBLIC Trajectory constant_acceleration_trajectory(float x0, float y0, float heading, float v0, float a0, std::chrono::nanoseconds dt)
Generates a constant acceleration trajectory.
Definition: motion_testing.cpp:159
MOTION_TESTING_PUBLIC State generate_state(Generator &gen)
Generates a state from a normal distribution with the following bounds: TODO(c.ho) ...
Definition: motion_testing.cpp:49
MOTION_TESTING_PUBLIC Trajectory generate_trajectory(const State &start_state, Generator &gen)
Generates a trajectory assuming the starting state, a bicycle model, and additive noise applied to XX...
Definition: motion_testing.cpp:70
MOTION_TESTING_PUBLIC State make_state(float x0, float y0, float heading, float v0, float a0, float turn_rate, std::chrono::system_clock::time_point t)
Makes a state, intended to make message generation more terse.
Definition: motion_testing.cpp:24
MOTION_TESTING_PUBLIC Trajectory constant_velocity_trajectory(float x0, float y0, float heading, float v0, std::chrono::nanoseconds dt)
Generates a constant velocity trajectory with invalid heading values.
Definition: motion_testing.cpp:148
MOTION_TESTING_PUBLIC Index progresses_towards_target(const Trajectory &trajectory, const Point &target, Real heading_tolerance=Real{0.006F})
Definition: motion_testing.cpp:212
decltype(Point::x) Real
Definition: motion_testing.hpp:109
autoware_auto_msgs::msg::Trajectory Trajectory
Definition: motion_testing.hpp:32