diff --git a/MantleAPI/include/MantleAPI/Common/simulation_time.h b/MantleAPI/include/MantleAPI/Common/simulation_time.h index 5026b821aba1112f354c92435d364f1117fea3ea..66e9d8596610518c587ab4fb4ef0615275bdea56 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 c391217c36a06c8110f7ccdb6a2fb057146ee6ad..352afa205752639d80faef7482a0ea298a47ce86 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 0000000000000000000000000000000000000000..17e54f6ec7ba522ddfcea732f603a51c5a9d3b88 --- /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 b5ff692c51ba3c4bb82f266e1abd41f554395f70..6f9dbccbbac51e6b931c52e0d3e6ba17af650758 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 216ef4ed673db294bbe403ec86da83898495edbe..72f0cedee20f3bc757e1fe75d96de9d80558eab4 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; };