Skip to content
Snippets Groups Projects
Commit 2ab14382 authored by Andreas Rauschert's avatar Andreas Rauschert
Browse files

Merge branch 'initializable-base-classes' into 'main'

Allow custom initialization of base classes

Closes #78

See merge request !155
parents 392a9483 2731a917
No related branches found
No related tags found
1 merge request!155Allow custom initialization of base classes
Pipeline #56660 passed
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <MantleAPI/Traffic/traffic_light_properties.h> #include <MantleAPI/Traffic/traffic_light_properties.h>
#include <MantleAPI/Traffic/vehicle_light_properties.h> #include <MantleAPI/Traffic/vehicle_light_properties.h>
#include <utility> // std::move
#include <vector> #include <vector>
namespace mantle_api namespace mantle_api
...@@ -59,12 +60,20 @@ enum class ControlStrategyType ...@@ -59,12 +60,20 @@ enum class ControlStrategyType
/// The runtime mapping of an private action instance to the simulator core. /// The runtime mapping of an private action instance to the simulator core.
struct ControlStrategy struct ControlStrategy
{ {
/// @brief Constructs a ControlStrategy from its members
///
/// @param[in] movement_domain Movement domain of the control strategy
/// @param[in] type Type of the control strategy
explicit ControlStrategy(MovementDomain movement_domain = MovementDomain::kUndefined,
ControlStrategyType type = ControlStrategyType::kUndefined)
: movement_domain{movement_domain}, type{type} {}
virtual ~ControlStrategy() = default; virtual ~ControlStrategy() = default;
// TODO: extend by bool use_dynamic_constraints when needed (false assumed at the moment) // TODO: extend by bool use_dynamic_constraints when needed (false assumed at the moment)
MovementDomain movement_domain{MovementDomain::kUndefined}; ///< Movement domain of the control strategy MovementDomain movement_domain; ///< Movement domain of the control strategy
ControlStrategyType type{ControlStrategyType::kUndefined}; ///< Type of the control strategy ControlStrategyType type; ///< Type of the control strategy
}; };
/// @brief Equality comparison for ControlStrategy. /// @brief Equality comparison for ControlStrategy.
...@@ -90,53 +99,61 @@ constexpr bool operator!=(const ControlStrategy& lhs, const ControlStrategy& rhs ...@@ -90,53 +99,61 @@ constexpr bool operator!=(const ControlStrategy& lhs, const ControlStrategy& rhs
/// Controls an entity to keeps current velocity /// Controls an entity to keeps current velocity
struct KeepVelocityControlStrategy : public ControlStrategy struct KeepVelocityControlStrategy : public ControlStrategy
{ {
/// @brief Constructs a KeepVelocityControlStrategy as a ControlStrategy with predefined values
KeepVelocityControlStrategy() KeepVelocityControlStrategy()
{ : ControlStrategy{MovementDomain::kLongitudinal, ControlStrategyType::kKeepVelocity} {}
movement_domain = MovementDomain::kLongitudinal;
type = ControlStrategyType::kKeepVelocity;
}
// Doesn't need configuration attributes. Controller keeps current velocity on adding entity or update // Doesn't need configuration attributes. Controller keeps current velocity on adding entity or update
}; };
/// Controls an entity to keeps current lane offset /// Controls an entity to keeps current lane offset
struct KeepLaneOffsetControlStrategy : public ControlStrategy struct KeepLaneOffsetControlStrategy : public ControlStrategy
{ {
/// @brief Constructs a KeepLaneOffsetControlStrategy as a ControlStrategy with predefined values
KeepLaneOffsetControlStrategy() KeepLaneOffsetControlStrategy()
{ : ControlStrategy{MovementDomain::kLateral, ControlStrategyType::kKeepLaneOffset} {}
movement_domain = MovementDomain::kLateral;
type = ControlStrategyType::kKeepLaneOffset;
}
// Doesn't need configuration attributes. Controller keeps current lane offset on adding entity or update // Doesn't need configuration attributes. Controller keeps current lane offset on adding entity or update
}; };
/// Controls an entity to follow a heading angle from spline /// Controls an entity to follow a heading angle from spline
struct FollowHeadingSplineControlStrategy : public ControlStrategy struct FollowHeadingSplineControlStrategy : public ControlStrategy
{ {
FollowHeadingSplineControlStrategy() /// @brief Constructs a FollowHeadingSplineControlStrategy
{ /// as a ControlStrategy with predefined values
movement_domain = MovementDomain::kLateral; ///
type = ControlStrategyType::kFollowHeadingSpline; /// @param[in] heading_splines List of the heading angles of splines
} /// @param[in] default_value The default value of the heading angle
explicit FollowHeadingSplineControlStrategy(
std::vector<mantle_api::SplineSection<units::angle::radian>> heading_splines = {},
units::angle::radian_t default_value = {})
: ControlStrategy{MovementDomain::kLateral, ControlStrategyType::kFollowHeadingSpline},
heading_splines{std::move(heading_splines)},
default_value{default_value} {}
/// List of the heading angles of splines /// List of the heading angles of splines
std::vector<mantle_api::SplineSection<units::angle::radian>> heading_splines; std::vector<mantle_api::SplineSection<units::angle::radian>> heading_splines;
/// The default value of the heading angle /// The default value of the heading angle
units::angle::radian_t default_value{0}; units::angle::radian_t default_value;
}; };
/// Controls an entity to follow a velocity from spline /// Controls an entity to follow a velocity from spline
struct FollowVelocitySplineControlStrategy : public ControlStrategy struct FollowVelocitySplineControlStrategy : public ControlStrategy
{ {
FollowVelocitySplineControlStrategy() /// @brief Constructs a FollowVelocitySplineControlStrategy
{ /// as a ControlStrategy with predefined values
movement_domain = MovementDomain::kLongitudinal; ///
type = ControlStrategyType::kFollowVelocitySpline; /// @param[in] velocity_splines List of the velocities of splines
} /// @param[in] default_value The default value of the velocity
explicit FollowVelocitySplineControlStrategy(
std::vector<mantle_api::SplineSection<units::velocity::meters_per_second>> velocity_splines = {},
units::velocity::meters_per_second_t default_value = {})
: ControlStrategy{MovementDomain::kLongitudinal, ControlStrategyType::kFollowVelocitySpline},
velocity_splines{std::move(velocity_splines)},
default_value{default_value} {}
/// List of the velocities of splines /// List of the velocities of splines
std::vector<mantle_api::SplineSection<units::velocity::meters_per_second>> velocity_splines; std::vector<mantle_api::SplineSection<units::velocity::meters_per_second>> velocity_splines;
/// The default value of the velocity /// The default value of the velocity
units::velocity::meters_per_second_t default_value{0}; units::velocity::meters_per_second_t default_value;
}; };
/// @brief Equality comparison for FollowVelocitySplineControlStrategy. /// @brief Equality comparison for FollowVelocitySplineControlStrategy.
...@@ -164,11 +181,14 @@ constexpr bool operator!=(const FollowVelocitySplineControlStrategy& lhs, ...@@ -164,11 +181,14 @@ constexpr bool operator!=(const FollowVelocitySplineControlStrategy& lhs,
/// Controls an entity to follow a lateral offset from spline /// Controls an entity to follow a lateral offset from spline
struct FollowLateralOffsetSplineControlStrategy : public ControlStrategy struct FollowLateralOffsetSplineControlStrategy : public ControlStrategy
{ {
FollowLateralOffsetSplineControlStrategy() /// @brief Constructs a FollowLateralOffsetSplineControlStrategy
{ /// as a ControlStrategy with predefined values
movement_domain = MovementDomain::kLateral; ///
type = ControlStrategyType::kFollowLateralOffsetSpline; /// @param[in] lateral_offset_splines List of the lateral offsets of splines
} explicit FollowLateralOffsetSplineControlStrategy(
std::vector<mantle_api::SplineSection<units::length::meter>> lateral_offset_splines = {})
: ControlStrategy{MovementDomain::kLateral, ControlStrategyType::kFollowLateralOffsetSpline},
lateral_offset_splines{std::move(lateral_offset_splines)} {}
/// List of the lateral offsets of splines /// List of the lateral offsets of splines
std::vector<mantle_api::SplineSection<units::length::meter>> lateral_offset_splines; std::vector<mantle_api::SplineSection<units::length::meter>> lateral_offset_splines;
...@@ -207,14 +227,19 @@ struct TransitionDynamics ...@@ -207,14 +227,19 @@ struct TransitionDynamics
/// Controls the transition to a defined lane offset of an entity /// Controls the transition to a defined lane offset of an entity
struct AcquireLaneOffsetControlStrategy : public ControlStrategy struct AcquireLaneOffsetControlStrategy : public ControlStrategy
{ {
AcquireLaneOffsetControlStrategy() /// @brief Constructs a AcquireLaneOffsetControlStrategy
{ /// as a ControlStrategy with predefined values
movement_domain = MovementDomain::kLateral; ///
type = ControlStrategyType::kAcquireLaneOffset; /// @param[in] offset Lane offset
} /// @param[in] transition_dynamics Specifies the dynamics of a value transition
explicit AcquireLaneOffsetControlStrategy(units::length::meter_t offset = {},
TransitionDynamics transition_dynamics = {})
: ControlStrategy{MovementDomain::kLateral, ControlStrategyType::kAcquireLaneOffset},
offset{offset},
transition_dynamics{transition_dynamics} {}
/// Lane offset /// Lane offset
units::length::meter_t offset{}; units::length::meter_t offset;
/// Specifies the dynamics of a value transition /// Specifies the dynamics of a value transition
TransitionDynamics transition_dynamics; TransitionDynamics transition_dynamics;
}; };
...@@ -235,16 +260,21 @@ struct VehicleLightStatesControlStrategy : public ControlStrategy ...@@ -235,16 +260,21 @@ struct VehicleLightStatesControlStrategy : public ControlStrategy
/// Controls the transition of a current light state to the target light state /// Controls the transition of a current light state to the target light state
struct TrafficLightStateControlStrategy : public ControlStrategy struct TrafficLightStateControlStrategy : public ControlStrategy
{ {
TrafficLightStateControlStrategy() /// @brief Constructs a TrafficLightStateControlStrategy
{ /// as a ControlStrategy with predefined values
type = ControlStrategyType::kUpdateTrafficLightStates; ///
movement_domain = MovementDomain::kNone; /// @param[in] traffic_light_phases List of specific traffic light phases
} /// @param[in] repeat_states Whether the light state is repeated or not
explicit TrafficLightStateControlStrategy(std::vector<TrafficLightPhase> traffic_light_phases = {},
bool repeat_states = false)
: ControlStrategy{MovementDomain::kNone, ControlStrategyType::kUpdateTrafficLightStates},
traffic_light_phases{std::move(traffic_light_phases)},
repeat_states{repeat_states} {}
/// List of specific traffic light phases /// List of specific traffic light phases
std::vector<TrafficLightPhase> traffic_light_phases{}; std::vector<TrafficLightPhase> traffic_light_phases;
/// The "repeat_states" flag determines, if the light state is repeated or not /// The "repeat_states" flag determines, if the light state is repeated or not
bool repeat_states{false}; bool repeat_states;
}; };
/// Definition of time value context as either absolute or relative /// Definition of time value context as either absolute or relative
...@@ -272,11 +302,15 @@ struct FollowTrajectoryControlStrategy : public ControlStrategy ...@@ -272,11 +302,15 @@ struct FollowTrajectoryControlStrategy : public ControlStrategy
units::time::second_t offset{0.0}; units::time::second_t offset{0.0};
}; };
FollowTrajectoryControlStrategy() /// @brief Constructs a FollowTrajectoryControlStrategy as a ControlStrategy with predefined values
{ ///
movement_domain = MovementDomain::kBoth; /// @param[in] trajectory Chain of points describing a trajectory
type = ControlStrategyType::kFollowTrajectory; /// @param[in] timeReference Time information provided within the trajectory
} explicit FollowTrajectoryControlStrategy(Trajectory trajectory = {},
std::optional<TrajectoryTimeReference> timeReference = std::nullopt)
: ControlStrategy{MovementDomain::kBoth, ControlStrategyType::kFollowTrajectory},
trajectory{std::move(trajectory)},
timeReference{timeReference} {}
/// Trajectory definition /// Trajectory definition
Trajectory trajectory; Trajectory trajectory;
...@@ -288,18 +322,25 @@ struct FollowTrajectoryControlStrategy : public ControlStrategy ...@@ -288,18 +322,25 @@ struct FollowTrajectoryControlStrategy : public ControlStrategy
/// Describes the transition between an entity's current lane and its target lane. /// Describes the transition between an entity's current lane and its target lane.
struct PerformLaneChangeControlStrategy : public ControlStrategy struct PerformLaneChangeControlStrategy : public ControlStrategy
{ {
PerformLaneChangeControlStrategy() /// @brief Constructs a PerformLaneChangeControlStrategy as a ControlStrategy with predefined values
{ ///
movement_domain = MovementDomain::kLateral; /// @param[in] target_lane_id ID of the target lane the entity will change to
type = ControlStrategyType::kPerformLaneChange; /// @param[in] target_lane_offset Lane offset to be reached at the target lane
} /// @param[in] transition_dynamics Shape/time of lane change action
explicit PerformLaneChangeControlStrategy(mantle_api::LaneId target_lane_id = {},
units::length::meter_t target_lane_offset = {},
TransitionDynamics transition_dynamics = {})
: ControlStrategy{MovementDomain::kLateral, ControlStrategyType::kPerformLaneChange},
target_lane_id{target_lane_id},
target_lane_offset{target_lane_offset},
transition_dynamics{transition_dynamics} {}
/// ID of the target lane the entity will change to /// ID of the target lane the entity will change to
mantle_api::LaneId target_lane_id{0}; mantle_api::LaneId target_lane_id;
/// Lane offset to be reached at the target lane (the action will end there) /// Lane offset to be reached at the target lane (the action will end there)
units::length::meter_t target_lane_offset{0.0}; units::length::meter_t target_lane_offset;
/// Shape/time of lane change action /// Shape/time of lane change action
TransitionDynamics transition_dynamics{}; TransitionDynamics transition_dynamics;
}; };
} // namespace mantle_api } // namespace mantle_api
......
...@@ -46,18 +46,36 @@ enum class EntityType ...@@ -46,18 +46,36 @@ enum class EntityType
/// Basic properties that describe scenario entities. /// Basic properties that describe scenario entities.
struct EntityProperties struct EntityProperties
{ {
/// @brief Constructs EntityProperties from its members
///
/// @param[in] bounding_box The three dimensional bounding box that encloses the entity
/// @param[in] type Type of the entity object (e.g. vehicle, pedestrian)
/// @param[in] model Definition of the model of the entity
/// @param[in] properties Additional properties as name value pairs
/// @param[in] mass The mass of the entity in kg
explicit EntityProperties(BoundingBox bounding_box = {},
EntityType type = EntityType::kOther,
std::string model = {},
std::map<std::string, std::string> properties = {},
units::mass::kilogram_t mass = {})
: bounding_box{bounding_box},
type{type},
model{std::move(model)},
properties{std::move(properties)},
mass{mass} {}
virtual ~EntityProperties() = default; virtual ~EntityProperties() = default;
/// The three dimensional bounding box that encloses the entity /// The three dimensional bounding box that encloses the entity
BoundingBox bounding_box{Vec3<units::length::meter_t>{}, Dimension3{}}; BoundingBox bounding_box;
/// Type of the entity object (e.g. vehicle, pedestrian) /// Type of the entity object (e.g. vehicle, pedestrian)
EntityType type{EntityType::kOther}; EntityType type;
/// Definition of the model of the entity /// Definition of the model of the entity
std::string model{}; std::string model;
/// Additional properties as name value pairs /// Additional properties as name value pairs
std::map<std::string, std::string> properties{}; std::map<std::string, std::string> properties;
/// The mass of the entity in kg /// The mass of the entity in kg
units::mass::kilogram_t mass{}; units::mass::kilogram_t mass;
}; };
/// @brief Equality comparison for EntityProperties. /// @brief Equality comparison for EntityProperties.
......
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2021-2023, Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * Copyright (c) 2021-2024, Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2024, Mercedes-Benz Tech Innovation GmbH * Copyright (c) 2024, Mercedes-Benz Tech Innovation GmbH
* *
* This program and the accompanying materials are made * This program and the accompanying materials are made
...@@ -32,13 +32,28 @@ namespace mantle_api ...@@ -32,13 +32,28 @@ namespace mantle_api
/// Base definition for creating a new controller for an entity /// Base definition for creating a new controller for an entity
struct IControllerConfig struct IControllerConfig
{ {
/// @brief Constructs a IControllerConfig from its members
///
/// @param[in] name Name of the controller. Might be ignored by the environment.
/// @param[in] map_query_service Pointer to the map query service
/// @param[in] control_strategies List of active control strategies
/// @param[in] route_definition Specifies the route behavior for the control stratgies
explicit IControllerConfig(std::string name = {},
ILaneLocationQueryService* map_query_service = nullptr,
std::vector<std::shared_ptr<mantle_api::ControlStrategy>> control_strategies = {},
RouteDefinition route_definition = {})
: name{std::move(name)},
map_query_service{map_query_service},
control_strategies{std::move(control_strategies)},
route_definition{std::move(route_definition)} {}
/// @brief default destructor /// @brief default destructor
virtual ~IControllerConfig() = default; virtual ~IControllerConfig() = default;
/// @brief Name of the controller. Might be ignored by the environment. /// @brief Name of the controller. Might be ignored by the environment.
std::string name; std::string name;
/// Pointer to the map query service /// Pointer to the map query service
/// @todo: Check why map_query_service is part of the interface because it is not set from engine side but only in the environment on calling AddController() /// @todo: Check why map_query_service is part of the interface because it is not set from engine side but only in the environment on calling AddController()
ILaneLocationQueryService* map_query_service{}; ILaneLocationQueryService* map_query_service;
/// List of active control strategies /// List of active control strategies
std::vector<std::shared_ptr<mantle_api::ControlStrategy>> control_strategies; std::vector<std::shared_ptr<mantle_api::ControlStrategy>> control_strategies;
/// Specifies the route behavior for the control stratgies /// Specifies the route behavior for the control stratgies
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment