From 2d1a5c16354719516af4a1598038438e96607673 Mon Sep 17 00:00:00 2001 From: Jupp Tscheak <jupp.tscheak@daimler.com> Date: Mon, 9 Aug 2021 14:45:36 +0200 Subject: [PATCH] Reintroduced type "Time" that should be used in the API to specify durations or time points. Type "Time" is now an alias to "units::time::millisecond_t". The conversion functions as provided by "time_utils.h" are still present and revised accordingly." Signed-off-by: Jupp Tscheak <jupp.tscheak@daimler.com> --- .../MantleAPI/Common/simulation_time.h | 6 +-- MantleAPI/include/MantleAPI/Common/spline.h | 5 ++- .../include/MantleAPI/Common/time_utils.h | 44 +++++++++++++++++++ .../EnvironmentalConditions/date_time.h | 4 +- .../MantleAPI/Execution/scenario_info.h | 4 +- 5 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 MantleAPI/include/MantleAPI/Common/time_utils.h diff --git a/MantleAPI/include/MantleAPI/Common/simulation_time.h b/MantleAPI/include/MantleAPI/Common/simulation_time.h index 5026b821..66e9d859 100644 --- a/MantleAPI/include/MantleAPI/Common/simulation_time.h +++ b/MantleAPI/include/MantleAPI/Common/simulation_time.h @@ -15,15 +15,15 @@ #ifndef MANTLEAPI_COMMON_SIMULATION_TIME_H #define MANTLEAPI_COMMON_SIMULATION_TIME_H -#include <units.h> +#include <MantleAPI/Common/time_utils.h> namespace mantle_api { struct SimulationTime { - units::time::second_t current_sim_time{0}; - units::time::second_t last_delta_time{0}; + Time current_sim_time{0}; + Time last_delta_time{0}; }; } // namespace mantle_api diff --git a/MantleAPI/include/MantleAPI/Common/spline.h b/MantleAPI/include/MantleAPI/Common/spline.h index c391217c..352afa20 100644 --- a/MantleAPI/include/MantleAPI/Common/spline.h +++ b/MantleAPI/include/MantleAPI/Common/spline.h @@ -17,6 +17,7 @@ #define MANTLEAPI_COMMON_SPLINE_H #include <MantleAPI/Common/floating_point_helper.h> +#include <MantleAPI/Common/time_utils.h> #include <MantleAPI/Common/vector.h> #include <units.h> @@ -36,8 +37,8 @@ struct SplineSegment struct SplineSection { - units::time::second_t start_time{0}; - units::time::second_t end_time{0}; + Time start_time{0}; + Time end_time{0}; /// @brief Represents the polynomial. /// /// The array stores in format \f$[a_3, a_2, a_1, a_0]\f$ for a polynomial in form diff --git a/MantleAPI/include/MantleAPI/Common/time_utils.h b/MantleAPI/include/MantleAPI/Common/time_utils.h new file mode 100644 index 00000000..17e54f6e --- /dev/null +++ b/MantleAPI/include/MantleAPI/Common/time_utils.h @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2021, Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ + +//----------------------------------------------------------------------------- +/** @file time_utils.h */ +//----------------------------------------------------------------------------- + +#ifndef MANTLEAPI_COMMON_TIME_UTILS_H +#define MANTLEAPI_COMMON_TIME_UTILS_H + +#include <units.h> + +namespace mantle_api +{ +using Time = units::time::millisecond_t; + +/// @brief Converts input in [s] to @ref Time. +/// @tparam T Input type, eg. `double`. +/// @param duration Input value +/// @return Duration representing the given input in units of @ref Time. +template <typename T> +inline Time SecondsToTime(T duration) +{ + return units::convert<units::time::seconds, units::time::milliseconds>(duration); +} + +/// @brief Converts input @ref Time to [s]. +/// @param time Time +/// @return Duration in seconds representing the passed in @ref Time. +inline double TimeToSeconds(const Time& time) +{ + return units::time::second_t{time}.value(); +} + +} // namespace mantle_api + +#endif // MANTLEAPI_COMMON_TIME_UTILS_H diff --git a/MantleAPI/include/MantleAPI/EnvironmentalConditions/date_time.h b/MantleAPI/include/MantleAPI/EnvironmentalConditions/date_time.h index b5ff692c..6f9dbccb 100644 --- a/MantleAPI/include/MantleAPI/EnvironmentalConditions/date_time.h +++ b/MantleAPI/include/MantleAPI/EnvironmentalConditions/date_time.h @@ -15,7 +15,7 @@ #ifndef MANTLEAPI_ENVIRONMENTALCONDITIONS_DATETIME_H #define MANTLEAPI_ENVIRONMENTALCONDITIONS_DATETIME_H -#include <units.h> +#include <MantleAPI/Common/time_utils.h> namespace mantle_api { @@ -23,7 +23,7 @@ namespace mantle_api // TODO: Delete this struct and use Time directly in Get/SetDateTime once the move to the MantleAPI is complete struct [[deprecated]] DateTime { - units::time::second_t date_time{0}; + Time date_time{0}; }; } // namespace mantle_api diff --git a/MantleAPI/include/MantleAPI/Execution/scenario_info.h b/MantleAPI/include/MantleAPI/Execution/scenario_info.h index 216ef4ed..72f0cede 100644 --- a/MantleAPI/include/MantleAPI/Execution/scenario_info.h +++ b/MantleAPI/include/MantleAPI/Execution/scenario_info.h @@ -15,7 +15,7 @@ #ifndef MANTLEAPI_EXECUTION_SCENARIOINFO_H #define MANTLEAPI_EXECUTION_SCENARIOINFO_H -#include <units.h> +#include <MantleAPI/Common/time_utils.h> #include <map> #include <string> @@ -25,7 +25,7 @@ namespace mantle_api struct ScenarioInfo { - units::time::second_t scenario_timeout_duration; + Time scenario_timeout_duration; std::string description; std::map<std::string, std::string> additional_information; }; -- GitLab