diff --git a/wpimath/src/main/native/include/units/angular_jerk.h b/wpimath/src/main/native/include/units/angular_jerk.h new file mode 100644 index 0000000000..b58bc1643c --- /dev/null +++ b/wpimath/src/main/native/include/units/angular_jerk.h @@ -0,0 +1,34 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +#pragma once + +#include "units/angle.h" +#include "units/base.h" +#include "units/time.h" + +namespace units { +/** + * @namespace units::angular_jerk + * @brief namespace for unit types and containers representing angular + * jerk values + * @details The SI unit for angular jerk is + * `radians_per_second_cubed`, and the corresponding `base_unit` + * category is`angular_jerk_unit`. + * @anchor angularJerkContainers + * @sa See unit_t for more information on unit type containers. + */ +UNIT_ADD(angular_jerk, radians_per_second_cubed, radians_per_second_cubed, + rad_per_s_cu, unit, units::category::angular_jerk_unit>) +UNIT_ADD(angular_jerk, degrees_per_second_cubed, degrees_per_second_cubed, + deg_per_s_cu, + compound_unit>>) +UNIT_ADD(angular_jerk, turns_per_second_cubed, turns_per_second_cubed, + tr_per_s_cu, + compound_unit>>) + +UNIT_ADD_CATEGORY_TRAIT(angular_jerk) + +using namespace angular_jerk; +} // namespace units diff --git a/wpimath/src/main/native/include/units/base.h b/wpimath/src/main/native/include/units/base.h index 3c939f3556..34cd59e419 100644 --- a/wpimath/src/main/native/include/units/base.h +++ b/wpimath/src/main/native/include/units/base.h @@ -821,6 +821,7 @@ namespace units typedef base_unit, std::ratio<0>, std::ratio<-1>, std::ratio<1>> angular_velocity_unit; ///< Represents an SI derived unit of angular velocity typedef base_unit, std::ratio<0>, std::ratio<-2>> acceleration_unit; ///< Represents an SI derived unit of acceleration typedef base_unit, std::ratio<0>, std::ratio<-2>, std::ratio<1>> angular_acceleration_unit; ///< Represents an SI derived unit of angular acceleration + typedef base_unit, std::ratio<0>, std::ratio<-3>, std::ratio<1>> angular_jerk_unit; ///< Represents an SI derived unit of angular jerk typedef base_unit, std::ratio<1>, std::ratio<-2>> force_unit; ///< Represents an SI derived unit of force typedef base_unit, std::ratio<1>, std::ratio<-2>> pressure_unit; ///< Represents an SI derived unit of pressure typedef base_unit, std::ratio<0>, std::ratio<1>, std::ratio<0>, std::ratio<1>> charge_unit; ///< Represents an SI derived unit of charge diff --git a/wpimath/src/test/native/cpp/UnitsTest.cpp b/wpimath/src/test/native/cpp/UnitsTest.cpp index 2584afed76..1464dcdeb5 100644 --- a/wpimath/src/test/native/cpp/UnitsTest.cpp +++ b/wpimath/src/test/native/cpp/UnitsTest.cpp @@ -12,6 +12,7 @@ #include "units/acceleration.h" #include "units/angle.h" #include "units/angular_acceleration.h" +#include "units/angular_jerk.h" #include "units/angular_velocity.h" #include "units/area.h" #include "units/capacitance.h" @@ -52,6 +53,7 @@ using namespace units::acceleration; using namespace units::angle; using namespace units::angular_acceleration; +using namespace units::angular_jerk; using namespace units::angular_velocity; using namespace units::area; using namespace units::capacitance; @@ -2003,6 +2005,23 @@ TEST_F(UnitConversion, angular_velocity) { EXPECT_NEAR(1.537e-16, test, 5.0e-20); } +TEST_F(UnitConversion, angular_jerk) { + double test; + bool same; + + same = + std::is_same_v, category::angular_jerk_unit>>; + EXPECT_TRUE(same); + same = traits::is_convertible_unit_v; + EXPECT_TRUE(same); + + test = convert(1.0); + EXPECT_NEAR(0.0174533, test, 5.0e-8); + test = convert(1.0); + EXPECT_NEAR(6.283185307, test, 5.0e-6); +} + TEST_F(UnitConversion, acceleration) { double test;