Autoware.Auto
parking_planner_types.hpp
Go to the documentation of this file.
1 // Copyright 2020 Embotech AG, Zurich, Switzerland. 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 #ifndef PARKING_PLANNER__PARKING_PLANNER_TYPES_HPP_
15 #define PARKING_PLANNER__PARKING_PLANNER_TYPES_HPP_
16 
17 #include <stdint.h>
18 #include <vector>
19 #include <string>
20 
21 #include "geometry.hpp"
22 
23 namespace autoware
24 {
25 
26 namespace motion
27 {
28 
29 namespace planning
30 {
31 
32 namespace parking_planner
33 {
34 // -- VehicleState ------------------------------------------------------------
36 template<typename T>
38 {
39 public:
41  // This is used for example in constructs such as VehicleState{}.
42  VehicleState() noexcept
43  : VehicleState({}, {}, {}, {}, {}) {}
44 
45  VehicleState(T x, T y, T velocity, T heading, T steering) noexcept
46  {
47  m_position_x = x;
48  m_position_y = y;
49  m_velocity = velocity;
50  m_heading = heading;
51  m_steering = steering;
52  }
53 
55  std::vector<T> serialize(void) const
56  {
57  return std::vector<T>{m_position_x, m_position_y, m_velocity, m_heading, m_steering};
58  }
59 
60  // \brief Turn a previously serialized state vector back into a VehicleState object
61  static VehicleState deserialize(std::vector<T> serialized_states)
62  {
63  if (serialized_states.size() != VehicleState::internal_states_number) {
64  throw std::length_error {"Need a vector of length " +
65  std::string{VehicleState::internal_states_number}
66  };
67  }
68 
69  return VehicleState(
70  serialized_states[0], serialized_states[1], serialized_states[2],
71  serialized_states[3],
72  serialized_states[4]);
73  }
74 
75  // Getters and setters, nothing fancy now but may get checks later
76  T get_x() const noexcept {return m_position_x;}
77  T get_y() const noexcept {return m_position_y;}
78  T get_velocity() const noexcept {return m_velocity;}
79  T get_heading() const noexcept {return m_heading;}
80  T get_steering() const noexcept {return m_steering;}
81  void set_x(T x) noexcept {m_position_x = x;}
82  void set_y(T y) noexcept {m_position_y = y;}
83  void set_velocity(T velocity) noexcept {m_velocity = velocity;}
84  void set_heading(T heading) noexcept {m_heading = heading;}
85  void set_steering(T steering) noexcept {m_steering = steering;}
86 
88  static constexpr std::size_t get_serialized_length() noexcept
89  {
90  return internal_states_number;
91  }
92 
94  bool operator==(const VehicleState<T> & other) const noexcept
95  {
96  return (this->m_position_x == other.m_position_x) &&
97  (this->m_position_y == other.m_position_y) &&
98  (this->m_velocity == other.m_velocity) &&
99  (this->m_heading == other.m_heading) &&
100  (this->m_steering == other.m_steering);
101  }
102 
103 private:
105  static constexpr std::size_t internal_states_number = 5;
106 
108  T m_position_x;
109 
111  T m_position_y;
112 
114  T m_velocity;
115 
117  T m_heading;
118 
120  T m_steering;
121 };
122 
123 
124 // -- VehicleCommand ----------------------------------------------------------
126 template<typename T>
128 {
129 public:
130  // No-input constructor sets everything to the zero of the template parameter.
131  // This is used when one creates empty std::vectors of those types.
132  VehicleCommand() noexcept
133  : VehicleCommand({}, {}) {}
134 
135  VehicleCommand(T steering_rate, T throttle) noexcept
136  {
137  m_steering_rate = steering_rate;
138  m_throttle = throttle;
139  }
140 
142  std::vector<T> serialize(void) const
143  {return std::vector<T>{m_steering_rate, m_throttle};}
144 
146  static VehicleCommand deserialize(std::vector<T> serialized_commands)
147  {
148  if (serialized_commands.size() != VehicleCommand::internal_commands_number) {
149  throw std::length_error {"Need a vector of length " +
150  std::string{VehicleCommand::internal_commands_number}
151  };
152  }
153 
154  return VehicleCommand(serialized_commands[0], serialized_commands[1]);
155  }
156 
157  T get_steering_rate() const noexcept {return m_steering_rate;}
158  T get_throttle() const noexcept {return m_throttle;}
159  void set_steering_rate(T steering_rate) noexcept {m_steering_rate = steering_rate;}
160  void set_throttle(T throttle) noexcept {m_throttle = throttle;}
161 
163  static constexpr std::size_t get_serialized_length() noexcept
164  {return internal_commands_number;}
165 
166 private:
168  static constexpr std::size_t internal_commands_number = 2;
169 
171  T m_steering_rate;
172 
174  T m_throttle;
175 };
176 
177 
178 // -- PlanningResult ----------------------------------------------------------
180 template<typename T>
182 {
183 public:
184  TrajectoryStep(const VehicleCommand<T> command, const VehicleState<T> state) noexcept
185  {
186  m_command = command;
187  m_state = state;
188  }
189 
190  VehicleState<T> get_state() const noexcept {return this->m_state;}
191  VehicleCommand<T> get_command() const noexcept {return this->m_command;}
192 
193 private:
194  VehicleCommand<T> m_command;
195  VehicleState<T> m_state;
196 };
197 
199 template<typename T>
200 using Trajectory = std::vector<TrajectoryStep<T>>;
201 
202 } // namespace parking_planner
203 } // namespace planning
204 } // namespace motion
205 } // namespace autoware
206 
207 #endif // PARKING_PLANNER__PARKING_PLANNER_TYPES_HPP_
autoware::motion::planning::parking_planner::VehicleState::operator==
bool operator==(const VehicleState< T > &other) const noexcept
Equality comparison operator.
Definition: parking_planner_types.hpp:94
autoware::motion::planning::parking_planner::VehicleState::get_heading
T get_heading() const noexcept
Definition: parking_planner_types.hpp:79
autoware::motion::planning::parking_planner::VehicleState::VehicleState
VehicleState(T x, T y, T velocity, T heading, T steering) noexcept
Definition: parking_planner_types.hpp:45
autoware::motion::planning::parking_planner::VehicleCommand::VehicleCommand
VehicleCommand(T steering_rate, T throttle) noexcept
Definition: parking_planner_types.hpp:135
catr_diff.T
T
Definition: catr_diff.py:22
autoware::motion::planning::parking_planner::VehicleState::set_x
void set_x(T x) noexcept
Definition: parking_planner_types.hpp:81
y
DifferentialState y
Definition: kinematic_bicycle.snippet.hpp:28
autoware::motion::planning::parking_planner::VehicleCommand
Class to represent the inputs of a vehicle.
Definition: parking_planner_types.hpp:127
autoware::motion::planning::parking_planner::VehicleCommand::deserialize
static VehicleCommand deserialize(std::vector< T > serialized_commands)
Turn a previously serialized command vector back into a VehicleCommand object.
Definition: parking_planner_types.hpp:146
autoware::motion::planning::parking_planner::VehicleCommand::get_throttle
T get_throttle() const noexcept
Definition: parking_planner_types.hpp:158
autoware::motion::planning::parking_planner::TrajectoryStep
Class to represent one timestep in a dynamic trajectory.
Definition: parking_planner_types.hpp:181
autoware::motion::planning::parking_planner::VehicleState::serialize
std::vector< T > serialize(void) const
Turn the object into flat vector of doubles (for use with numerical code)
Definition: parking_planner_types.hpp:55
autoware::motion::planning::parking_planner::VehicleState::get_velocity
T get_velocity() const noexcept
Definition: parking_planner_types.hpp:78
autoware::motion::planning::parking_planner::VehicleState::set_heading
void set_heading(T heading) noexcept
Definition: parking_planner_types.hpp:84
autoware
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
autoware::motion::planning::parking_planner::VehicleState
Class to represent the state of a vehicle.
Definition: parking_planner_types.hpp:37
autoware::motion::planning::parking_planner::VehicleState::set_velocity
void set_velocity(T velocity) noexcept
Definition: parking_planner_types.hpp:83
autoware::motion::planning::parking_planner::VehicleCommand::set_steering_rate
void set_steering_rate(T steering_rate) noexcept
Definition: parking_planner_types.hpp:159
autoware::motion::planning::parking_planner::TrajectoryStep::get_state
VehicleState< T > get_state() const noexcept
Definition: parking_planner_types.hpp:190
autoware::motion::planning::parking_planner::TrajectoryStep::TrajectoryStep
TrajectoryStep(const VehicleCommand< T > command, const VehicleState< T > state) noexcept
Definition: parking_planner_types.hpp:184
geometry.hpp
x
DifferentialState x
Definition: kinematic_bicycle.snippet.hpp:28
autoware::motion::planning::parking_planner::TrajectoryStep::get_command
VehicleCommand< T > get_command() const noexcept
Definition: parking_planner_types.hpp:191
autoware::motion::planning::parking_planner::VehicleState::set_steering
void set_steering(T steering) noexcept
Definition: parking_planner_types.hpp:85
autoware::motion::planning::parking_planner::VehicleState::set_y
void set_y(T y) noexcept
Definition: parking_planner_types.hpp:82
autoware::motion::planning::parking_planner::VehicleState::get_steering
T get_steering() const noexcept
Definition: parking_planner_types.hpp:80
motion
Definition: controller_base.hpp:30
autoware::motion::planning::parking_planner::Trajectory
std::vector< TrajectoryStep< T > > Trajectory
Class to represent a dynamic trajectory.
Definition: parking_planner_types.hpp:200
autoware::motion::planning::parking_planner::VehicleCommand::serialize
std::vector< T > serialize(void) const
Turn the object into flat vector of doubles (for use with numerical code)
Definition: parking_planner_types.hpp:142
autoware::motion::planning::parking_planner::VehicleState::get_y
T get_y() const noexcept
Definition: parking_planner_types.hpp:77
autoware::motion::planning::parking_planner::VehicleState::deserialize
static VehicleState deserialize(std::vector< T > serialized_states)
Definition: parking_planner_types.hpp:61
autoware::motion::planning::parking_planner::VehicleCommand::VehicleCommand
VehicleCommand() noexcept
Definition: parking_planner_types.hpp:132
autoware::motion::planning::parking_planner::VehicleCommand::set_throttle
void set_throttle(T throttle) noexcept
Definition: parking_planner_types.hpp:160
autoware::motion::planning::parking_planner::VehicleState::get_serialized_length
static constexpr std::size_t get_serialized_length() noexcept
Get number of scalars a serialized version of this object has.
Definition: parking_planner_types.hpp:88
autoware::motion::planning::parking_planner::VehicleCommand::get_serialized_length
static constexpr std::size_t get_serialized_length() noexcept
Get number of scalars a serialized version of this object has.
Definition: parking_planner_types.hpp:163
autoware::motion::planning::parking_planner::VehicleCommand::get_steering_rate
T get_steering_rate() const noexcept
Definition: parking_planner_types.hpp:157
autoware::motion::planning::parking_planner::VehicleState::get_x
T get_x() const noexcept
Definition: parking_planner_types.hpp:76
autoware::motion::planning::parking_planner::VehicleState::VehicleState
VehicleState() noexcept
No-input constructor sets everything to the zero of the template parameter.
Definition: parking_planner_types.hpp:42