25 #ifndef PARKING_PLANNER__NLP_ADAPTERS_HPP_ 26 #define PARKING_PLANNER__NLP_ADAPTERS_HPP_ 47 namespace parking_planner
76 m_steering = steering;
77 m_throttle = throttle;
83 return std::vector<T>({m_steering, m_throttle, m_goal});
89 if (serialized.size() != expected_length) {
90 throw std::length_error {
"Need a vector of length " + std::string{expected_length}};
92 NLPCostWeights weights(serialized[0], serialized[1], serialized[2]);
97 {
return internal_weights_number;}
104 static constexpr std::size_t internal_weights_number = 3;
124 std::vector<T> lambda,
135 std::vector<T> serialized{};
136 serialized.reserve(internal_lambda_number + internal_mu_number);
137 serialized.insert(serialized.end(), m_lambda.begin(), m_lambda.end());
138 serialized.insert(serialized.end(), m_mu.begin(), m_mu.end());
143 {
return internal_lambda_number;}
146 {
return internal_mu_number;}
149 {
return internal_mu_number + internal_lambda_number;}
155 static constexpr
auto expected_length =
157 if (serialized.size() != expected_length) {
158 throw std::length_error {
"Need a vector of length " + std::string{expected_length}};
161 const auto start = serialized.begin();
163 std::vector<T>(start, start + lambda_length),
164 std::vector<T>(start + lambda_length, start + lambda_length + mu_length) );
167 std::vector<T>
get_lambda() const noexcept {
return m_lambda;}
168 std::vector<T>
get_mu() const noexcept {
return m_mu;}
178 std::vector<T> m_lambda;
197 m_stage_variables = stage_variables;
198 m_halfplanes = halfplanes;
205 std::vector<T> serialized{};
206 serialized.reserve(m_stage_variables.size() * m_stage_variables[0].get_serialized_length() );
207 for (
const auto & stage : m_stage_variables) {
208 const auto serialized_stage = stage.serialize();
209 serialized.insert(serialized.end(), serialized_stage.begin(), serialized_stage.end());
218 std::vector<T> serialized{};
219 for (
const auto & halfplane : m_halfplanes) {
220 const auto serialized_halfplane = halfplane.serialize();
222 serialized.end(), serialized_halfplane.begin(),
223 serialized_halfplane.end() );
230 {
return m_halfplanes;}
234 {
return m_stage_variables;}
241 std::vector<std::vector<T>> A{};
242 for (
const auto & halfplane : this->m_halfplanes) {
243 auto coordinates = halfplane.get_coefficients().get_coord();
244 A.push_back(std::vector<T>({coordinates.first, coordinates.second}) );
253 for (
const auto & halfplane : this->m_halfplanes) {
254 auto rhs = halfplane.get_right_hand_side();
262 std::vector<Halfplane2D<T>> m_halfplanes;
265 std::vector<NLPObstacleStageVariables<T>> m_stage_variables;
297 std::vector<T> assembled_variables{};
298 std::vector<float64_t> lower_bounds{};
299 std::vector<float64_t> upper_bounds{};
300 const auto serialized_state_lower = lower_state_bounds.
serialize();
301 const auto serialized_state_upper = upper_state_bounds.
serialize();
302 const auto serialized_command_lower = lower_command_bounds.
serialize();
303 const auto serialized_command_upper = upper_command_bounds.
serialize();
304 for (
const auto & step : trajectory) {
306 const auto serialized_state = step.get_state().serialize();
307 assembled_variables.insert(
308 assembled_variables.end(),
309 serialized_state.begin(), serialized_state.end() );
312 serialized_state_lower.begin(), serialized_state_lower.end() );
315 serialized_state_upper.begin(), serialized_state_upper.end() );
318 const auto serialized_command = step.get_command().serialize();
319 assembled_variables.insert(
320 assembled_variables.end(),
321 serialized_command.begin(), serialized_command.end() );
324 serialized_command_lower.begin(), serialized_command_lower.end() );
327 serialized_command_upper.begin(), serialized_command_upper.end() );
331 for (
const auto & obstacle : obstacles) {
332 const auto serialized = obstacle.serialize_variables();
333 assembled_variables.insert(
334 assembled_variables.end(),
335 serialized.begin(), serialized.end()
337 for (std::size_t k = {}; k < serialized.size(); k++) {
338 lower_bounds.push_back(0.0);
339 upper_bounds.push_back(ARTIFICIAL_DUAL_MULTIPLIER_BOUND);
351 const std::vector<T> & variable_vector,
352 const std::size_t horizon_length)
358 disassembled.reserve(variable_vector.size());
359 auto vstart = variable_vector.begin();
360 for (std::size_t k = {}; k < horizon_length; k++) {
364 std::vector<T>(vstart, vstart + Ncommands)
385 std::vector<T> assembled{};
387 const auto serialized = current_state.
serialize();
388 assembled.insert(assembled.end(), serialized.begin(), serialized.end() );
391 const auto serialized = goal_state.
serialize();
392 assembled.insert(assembled.end(), serialized.begin(), serialized.end() );
395 const auto serialized = model_parameters.
serialize();
396 assembled.insert(assembled.end(), serialized.begin(), serialized.end() );
400 const auto serialized = cost_weights.
serialize();
401 assembled.insert(assembled.end(), serialized.begin(), serialized.end() );
404 for (
const auto & obstacle : obstacles) {
405 const auto serialized = obstacle.serialize_parameters();
406 assembled.insert(assembled.end(), serialized.begin(), serialized.end() );
417 #endif // PARKING_PLANNER__NLP_ADAPTERS_HPP_ std::vector< T > serialize(void) const
Definition: bicycle_model.hpp:59
std::vector< float64_t > lower_bounds
Definition: nlp_adapters.hpp:273
double float64_t
Definition: types.hpp:37
Class used to describe the additional dual variables required for each.
Definition: nlp_adapters.hpp:120
NLPCostWeights(T steering, T throttle, T goal)
Definition: nlp_adapters.hpp:70
std::vector< TrajectoryStep< T > > Trajectory
Class to represent a dynamic trajectory.
Definition: parking_planner_types.hpp:200
Definition: nlp_adapters.hpp:270
T
Definition: catr_diff.py:22
Class to represent the state of a vehicle.
Definition: parking_planner_types.hpp:37
static NLPCostWeights deserialize(std::vector< T > serialized)
Definition: nlp_adapters.hpp:86
NLPObstacleStageVariables(std::vector< T > lambda, std::vector< T > mu)
Definition: nlp_adapters.hpp:123
T get_steering_weight() const noexcept
Definition: nlp_adapters.hpp:99
std::vector< float64_t > upper_bounds
Definition: nlp_adapters.hpp:274
std::vector< T > serialize(void) const
Serialize the object into a vector of scalars.
Definition: nlp_adapters.hpp:133
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
Class used to represent an obstacle with the relevant data and conversions for the NLP solver...
Definition: nlp_adapters.hpp:190
NLPObstacle(std::vector< NLPObstacleStageVariables< T >> stage_variables, std::vector< Halfplane2D< T >> halfplanes) noexcept
Definition: nlp_adapters.hpp:193
static constexpr std::size_t get_lambda_length() noexcept
Definition: nlp_adapters.hpp:142
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
T get_goal_weight() const noexcept
Definition: nlp_adapters.hpp:101
constexpr auto Nstates
Definition: generate_nlp_planner_solver.cpp:80
constexpr std::size_t MAX_HYPERPLANES_PER_OBSTACLE
Maximum number of hyperplanes per obstacle supported by the NLP planner.
Definition: configuration.hpp:39
This file includes common type definition.
T get_throttle_weight() const noexcept
Definition: nlp_adapters.hpp:100
std::vector< T > serialize_parameters(void) const
Turn the obstacle parameter variables into a vector of scalars,.
Definition: nlp_adapters.hpp:216
std::vector< T > serialize(void) const
Definition: nlp_adapters.hpp:81
constexpr auto ARTIFICIAL_DUAL_MULTIPLIER_BOUND
Since we need upper and lower bounds in the constructs used here, but some variables do not have clea...
Definition: nlp_adapters.hpp:62
static VehicleState deserialize(std::vector< T > serialized_states)
Definition: parking_planner_types.hpp:61
std::vector< std::vector< T > > build_A() const
Assemble an A matrix from the halfplanes in form of a vector of vectors.
Definition: nlp_adapters.hpp:239
static constexpr std::size_t get_serialized_length() noexcept
Definition: nlp_adapters.hpp:96
Class for storing physical parameters of a bicycle model bicycle model.
Definition: bicycle_model.hpp:45
Definition: nlp_adapters.hpp:67
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
std::vector< Halfplane2D< T > > get_halfplanes() const noexcept
Getter for the halfplanes.
Definition: nlp_adapters.hpp:229
Definition: controller_base.hpp:30
Class describing a halfplane in two-dimensional space.
Definition: geometry.hpp:163
std::vector< NLPObstacleStageVariables< T > > get_stage_variables() const noexcept
Getter for the stage variables.
Definition: nlp_adapters.hpp:233
std::vector< T > get_mu() const noexcept
Definition: nlp_adapters.hpp:168
static constexpr std::size_t get_serialized_length() noexcept
Definition: nlp_adapters.hpp:148
std::vector< T > variables
Definition: nlp_adapters.hpp:272
Trajectory< float64_t > disassemble_variable_vector(const std::vector< T > &variable_vector, const std::size_t horizon_length)
Helper function to turn a serialized variable vector into a structured Trajectory object...
Definition: nlp_adapters.hpp:350
Class to represent the inputs of a vehicle.
Definition: parking_planner_types.hpp:127
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
std::vector< T > serialize_variables(void) const
Turn the obstacle variables into a vector of scalars, for use by.
Definition: nlp_adapters.hpp:203
Class to represent one timestep in a dynamic trajectory.
Definition: parking_planner_types.hpp:181
constexpr std::size_t MAX_EGO_HYPERPLANES
Maximum number of ego vehicle hyperplanes supported by the NLP planner.
Definition: configuration.hpp:42
std::vector< T > get_lambda() const noexcept
Definition: nlp_adapters.hpp:167
static constexpr std::size_t get_mu_length() noexcept
Definition: nlp_adapters.hpp:145
SerializedVariables< T > assemble_variable_vector_and_bounds(const Trajectory< T > &trajectory, const std::vector< NLPObstacle< T >> &obstacles, const VehicleState< float64_t > &lower_state_bounds, const VehicleState< float64_t > &upper_state_bounds, const VehicleCommand< float64_t > &lower_command_bounds, const VehicleCommand< float64_t > &upper_command_bounds)
Function to assemble the variable vector for the NLP from given states and commands. This is used in both the solver generation for specifying how the variables are ordered as well as when calling the solver because it will expect the initial guess in the same format. The adapter here serves as a single source of truth for how the serialization is to be done.
Definition: nlp_adapters.hpp:288
static NLPObstacleStageVariables deserialize(std::vector< T > serialized)
Definition: nlp_adapters.hpp:151
std::vector< T > assemble_parameter_vector(const VehicleState< T > ¤t_state, const VehicleState< T > &goal_state, const BicycleModelParameters< T > &model_parameters, const std::vector< NLPObstacle< T >> &obstacles, const NLPCostWeights< T > &cost_weights)
Helper function to turn the inputs to an NLP solve into a flat vector of scalars for use by the CasAD...
Definition: nlp_adapters.hpp:377
std::vector< T > build_b() const
Build the b matrix from the halfplanes of the obstacles.
Definition: nlp_adapters.hpp:250
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
constexpr auto Ncommands
Definition: generate_nlp_planner_solver.cpp:81
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24