Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
units_extensions.hpp
Go to the documentation of this file.
1// Copyright 2023 Leidos
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef CARMA_COOPERATIVE_PERCEPTION__UNITS_EXTENSIONS_HPP_
16#define CARMA_COOPERATIVE_PERCEPTION__UNITS_EXTENSIONS_HPP_
17
18#include <units.h>
19
20#include <ratio>
21
23{
24template <typename T>
25constexpr auto remove_units(const T & value)
26{
27 return units::unit_cast<typename T::underlying_type>(value);
28}
29
30} // namespace carma_cooperative_perception
31
32/*
33 * The nholthaus/units library does not include an exhaustive list of units, so
34 * this is how we can add missing/new ones. See the following for more information:
35 * - https://github.com/nholthaus/units?tab=readme-ov-file#defining-new-units
36 * - https://github.com/nholthaus/units?tab=readme-ov-file#unit-definition-macros
37 */
38namespace units
39{
40// These are not our macros, so we should not worry about linting them.
41// clang-tidy added support for ignoring system macros in release 14.0.0 (see the release notes
42// here: https://releases.llvm.org/14.0.0/tools/clang/tools/extra/docs/ReleaseNotes.html), but
43// ament_clang_tidy for ROS 2 Foxy specifically looks for clang-tidy-6.0. Note also that
44// clang-tidy release 14.0.0 adds NOLINTBEGIN...NOLINTEND, so we can remove the individual NOLINT
45// calls in the future.
46
47UNIT_ADD( // NOLINT
48 acceleration, centi_meters_per_second_squared, centimeters_per_second_squared, // NOLINT
49 centi_mps_sq, // NOLINT
50 unit<std::centi, meters_per_second_squared>) // NOLINT
51
52UNIT_ADD( // NOLINT
54 unit<std::ratio_multiply<std::ratio<2>, std::centi>, standard_gravity>) // NOLINT
55
56UNIT_ADD( // NOLINT
57 angular_velocity, centi_degrees_per_second, centi_degrees_per_second, centi_deg_per_s, // NOLINT
58 unit<std::centi, degrees_per_second>) // NOLINT
59
60UNIT_ADD( // NOLINT
62 unit<std::ratio_multiply<std::deci, std::micro>, degrees>) // NOLINT
63
64UNIT_ADD( // NOLINT
65 length, deca_centimeters, deca_centimeters, deca_cm, unit<std::ratio<10>, centimeters>) // NOLINT
66
67UNIT_ADD( // NOLINT
69 unit<std::ratio_multiply<std::ratio<1, 8>, std::deci>, degrees>) // NOLINT
70
71UNIT_ADD( // NOLINT
72 velocity, two_milli_meters_per_second, two_milli_meters_per_second, two_milli_mps, // NOLINT
73 unit<std::ratio_multiply<std::ratio<2>, std::milli>, meters_per_second>) // NOLINT
74
75UNIT_ADD( // NOLINT
77 unit<std::ratio_multiply<std::ratio<2>, std::centi>, meters_per_second>) // NOLINT
78
79} // namespace units
80
81#endif // CARMA_COOPERATIVE_PERCEPTION__UNITS_EXTENSIONS_HPP_
constexpr auto remove_units(const T &value)
unit< std::ratio_multiply< std::ratio< 2 >, std::centi >, standard_gravity > unit< std::ratio_multiply< std::deci, std::micro >, degrees > eighth_ddeg
unit< std::ratio_multiply< std::ratio< 2 >, std::centi >, standard_gravity > unit< std::ratio_multiply< std::deci, std::micro >, degrees > eighth_deci_degrees
unit< std::ratio_multiply< std::ratio< 2 >, std::centi >, standard_gravity > unit< std::ratio_multiply< std::deci, std::micro >, degrees > unit< std::ratio_multiply< std::ratio< 1, 8 >, std::deci >, degrees > two_centi_meters_per_second
unit< std::ratio_multiply< std::ratio< 2 >, std::centi >, standard_gravity > unit< std::ratio_multiply< std::deci, std::micro >, degrees > unit< std::ratio_multiply< std::ratio< 1, 8 >, std::deci >, degrees > two_centi_mps
two_centi_standard_gravities
unit< std::ratio_multiply< std::ratio< 2 >, std::centi >, standard_gravity > deci_udeg
unit< std::ratio_multiply< std::ratio< 2 >, std::centi >, standard_gravity > deci_micro_degrees
UNIT_ADD(acceleration, centi_meters_per_second_squared, centimeters_per_second_squared, centi_mps_sq, unit< std::centi, meters_per_second_squared >) UNIT_ADD(acceleration