diff --git a/include/MantleAPI/Traffic/control_strategy.h b/include/MantleAPI/Traffic/control_strategy.h index 7ad57f98510ab9ba5fda0dbb0cc0e798ea96dada..d66b688c9e717d2292f17ea67a41e939c73bac3f 100644 --- a/include/MantleAPI/Traffic/control_strategy.h +++ b/include/MantleAPI/Traffic/control_strategy.h @@ -24,6 +24,7 @@ #include <MantleAPI/Traffic/traffic_light_properties.h> #include <MantleAPI/Traffic/vehicle_light_properties.h> +#include <utility> // std::move #include <vector> namespace mantle_api @@ -59,12 +60,20 @@ enum class ControlStrategyType /// The runtime mapping of an private action instance to the simulator core. 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; // 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 - ControlStrategyType type{ControlStrategyType::kUndefined}; ///< Type of the control strategy + MovementDomain movement_domain; ///< Movement domain of the control strategy + ControlStrategyType type; ///< Type of the control strategy }; /// @brief Equality comparison for ControlStrategy. @@ -90,53 +99,61 @@ constexpr bool operator!=(const ControlStrategy& lhs, const ControlStrategy& rhs /// Controls an entity to keeps current velocity struct KeepVelocityControlStrategy : public ControlStrategy { + /// @brief Constructs a KeepVelocityControlStrategy as a ControlStrategy with predefined values KeepVelocityControlStrategy() - { - movement_domain = MovementDomain::kLongitudinal; - type = ControlStrategyType::kKeepVelocity; - } + : ControlStrategy{MovementDomain::kLongitudinal, ControlStrategyType::kKeepVelocity} {} // Doesn't need configuration attributes. Controller keeps current velocity on adding entity or update }; /// Controls an entity to keeps current lane offset struct KeepLaneOffsetControlStrategy : public ControlStrategy { + /// @brief Constructs a KeepLaneOffsetControlStrategy as a ControlStrategy with predefined values KeepLaneOffsetControlStrategy() - { - movement_domain = MovementDomain::kLateral; - type = ControlStrategyType::kKeepLaneOffset; - } + : ControlStrategy{MovementDomain::kLateral, ControlStrategyType::kKeepLaneOffset} {} // 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 struct FollowHeadingSplineControlStrategy : public ControlStrategy { - FollowHeadingSplineControlStrategy() - { - movement_domain = MovementDomain::kLateral; - type = ControlStrategyType::kFollowHeadingSpline; - } + /// @brief Constructs a FollowHeadingSplineControlStrategy + /// as a ControlStrategy with predefined values + /// + /// @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 std::vector<mantle_api::SplineSection<units::angle::radian>> heading_splines; /// 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 struct FollowVelocitySplineControlStrategy : public ControlStrategy { - FollowVelocitySplineControlStrategy() - { - movement_domain = MovementDomain::kLongitudinal; - type = ControlStrategyType::kFollowVelocitySpline; - } + /// @brief Constructs a FollowVelocitySplineControlStrategy + /// as a ControlStrategy with predefined values + /// + /// @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 std::vector<mantle_api::SplineSection<units::velocity::meters_per_second>> velocity_splines; /// 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. @@ -164,11 +181,14 @@ constexpr bool operator!=(const FollowVelocitySplineControlStrategy& lhs, /// Controls an entity to follow a lateral offset from spline struct FollowLateralOffsetSplineControlStrategy : public ControlStrategy { - FollowLateralOffsetSplineControlStrategy() - { - movement_domain = MovementDomain::kLateral; - type = ControlStrategyType::kFollowLateralOffsetSpline; - } + /// @brief Constructs a FollowLateralOffsetSplineControlStrategy + /// as a ControlStrategy with predefined values + /// + /// @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 std::vector<mantle_api::SplineSection<units::length::meter>> lateral_offset_splines; @@ -207,14 +227,19 @@ struct TransitionDynamics /// Controls the transition to a defined lane offset of an entity struct AcquireLaneOffsetControlStrategy : public ControlStrategy { - AcquireLaneOffsetControlStrategy() - { - movement_domain = MovementDomain::kLateral; - type = ControlStrategyType::kAcquireLaneOffset; - } + /// @brief Constructs a AcquireLaneOffsetControlStrategy + /// as a ControlStrategy with predefined values + /// + /// @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 - units::length::meter_t offset{}; + units::length::meter_t offset; /// Specifies the dynamics of a value transition TransitionDynamics transition_dynamics; }; @@ -235,16 +260,21 @@ struct VehicleLightStatesControlStrategy : public ControlStrategy /// Controls the transition of a current light state to the target light state struct TrafficLightStateControlStrategy : public ControlStrategy { - TrafficLightStateControlStrategy() - { - type = ControlStrategyType::kUpdateTrafficLightStates; - movement_domain = MovementDomain::kNone; - } + /// @brief Constructs a TrafficLightStateControlStrategy + /// as a ControlStrategy with predefined values + /// + /// @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 - 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 - bool repeat_states{false}; + bool repeat_states; }; /// Definition of time value context as either absolute or relative @@ -272,11 +302,15 @@ struct FollowTrajectoryControlStrategy : public ControlStrategy units::time::second_t offset{0.0}; }; - FollowTrajectoryControlStrategy() - { - movement_domain = MovementDomain::kBoth; - type = ControlStrategyType::kFollowTrajectory; - } + /// @brief Constructs a FollowTrajectoryControlStrategy as a ControlStrategy with predefined values + /// + /// @param[in] trajectory Chain of points describing a trajectory + /// @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 trajectory; @@ -288,18 +322,25 @@ struct FollowTrajectoryControlStrategy : public ControlStrategy /// Describes the transition between an entity's current lane and its target lane. struct PerformLaneChangeControlStrategy : public ControlStrategy { - PerformLaneChangeControlStrategy() - { - movement_domain = MovementDomain::kLateral; - type = ControlStrategyType::kPerformLaneChange; - } + /// @brief Constructs a PerformLaneChangeControlStrategy as a ControlStrategy with predefined values + /// + /// @param[in] target_lane_id ID of the target lane the entity will change to + /// @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 - 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) - units::length::meter_t target_lane_offset{0.0}; + units::length::meter_t target_lane_offset; /// Shape/time of lane change action - TransitionDynamics transition_dynamics{}; + TransitionDynamics transition_dynamics; }; } // namespace mantle_api diff --git a/include/MantleAPI/Traffic/entity_properties.h b/include/MantleAPI/Traffic/entity_properties.h index 780e9b1d2fac4075e3afe6761e2f81c4b60cf705..b275452d4b184187fc019166f546a0d023bc1d57 100644 --- a/include/MantleAPI/Traffic/entity_properties.h +++ b/include/MantleAPI/Traffic/entity_properties.h @@ -46,18 +46,36 @@ enum class EntityType /// Basic properties that describe scenario entities. 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; /// 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) - EntityType type{EntityType::kOther}; + EntityType type; /// Definition of the model of the entity - std::string model{}; + std::string model; /// 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 - units::mass::kilogram_t mass{}; + units::mass::kilogram_t mass; }; /// @brief Equality comparison for EntityProperties. diff --git a/include/MantleAPI/Traffic/i_controller_config.h b/include/MantleAPI/Traffic/i_controller_config.h index 8ba999f08dddff1a81def7a978d3521bcabf7267..c3f765ffc73e53f963d7a435b853c17f39b0f593 100644 --- a/include/MantleAPI/Traffic/i_controller_config.h +++ b/include/MantleAPI/Traffic/i_controller_config.h @@ -1,5 +1,5 @@ /******************************************************************************* - * 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 * * This program and the accompanying materials are made @@ -32,13 +32,28 @@ namespace mantle_api /// Base definition for creating a new controller for an entity 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 virtual ~IControllerConfig() = default; /// @brief Name of the controller. Might be ignored by the environment. std::string name; /// 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() - ILaneLocationQueryService* map_query_service{}; + ILaneLocationQueryService* map_query_service; /// List of active control strategies std::vector<std::shared_ptr<mantle_api::ControlStrategy>> control_strategies; /// Specifies the route behavior for the control stratgies