tutrc_harurobo_lib
読み取り中…
検索中…
一致する文字列を見つけられません
utility.hpp
[詳解]
1#pragma once
2
3#include <algorithm>
4#include <cmath>
5#include <type_traits>
6
7#include "cmsis_os2.h"
8
9#ifndef M_PI
10#define M_PI 3.14159265358979323846
11#endif
12
13namespace tutrc_harurobo_lib {
14
15template <class T>
16constexpr std::underlying_type_t<T> to_underlying(T value) noexcept {
17 return static_cast<std::underlying_type_t<T>>(value);
18}
19
20template <class T> constexpr T clamp(T x, T a, T b) {
21 return std::min(std::max(x, a), b);
22}
23
24template <class T> constexpr T normalize_angle(T x) {
25 x = std::fmod(x, 2 * M_PI);
26 if (x < 0) {
27 x += 2 * M_PI;
28 }
29 return x;
30}
31
33public:
34 ScopedLock(osMutexId_t mutex) : mutex_(mutex) {}
35
36 ~ScopedLock() { osMutexRelease(mutex_); }
37
38 bool acquire(uint32_t timeout) {
39 return osMutexAcquire(mutex_, timeout) == osOK;
40 }
41
42private:
43 osMutexId_t mutex_;
44};
45
46} // namespace tutrc_harurobo_lib
Definition utility.hpp:32
ScopedLock(osMutexId_t mutex)
Definition utility.hpp:34
~ScopedLock()
Definition utility.hpp:36
bool acquire(uint32_t timeout)
Definition utility.hpp:38
Definition bno055.hpp:10
constexpr T clamp(T x, T a, T b)
Definition utility.hpp:20
constexpr std::underlying_type_t< T > to_underlying(T value) noexcept
Definition utility.hpp:16
constexpr T normalize_angle(T x)
Definition utility.hpp:24
#define M_PI
Definition utility.hpp:10