Sygaldry
Loading...
Searching...
No Matches
sygac-mimu.hpp
1#pragma once
2/*
3Copyright 2023 Travis J. West, https://traviswest.ca, Input Devices and Music
4Interaction Laboratory (IDMIL), Centre for Interdisciplinary Research in Music
5Media and Technology (CIRMMT), McGill University, Montréal, Canada, and Univ.
6Lille, Inria, CNRS, Centrale Lille, UMR 9189 CRIStAL, F-59000 Lille, France
7
8SPDX-License-Identifier: MIT
9*/
10
11#include <utility>
12#include "sygac-components.hpp"
13
14namespace sygaldry {
18
22
23#define try_spelling(SPELLING)\
24if constexpr (requires {mimu_data.SPELLING;}) return mimu_data.SPELLING; /* member acces */ \
25else if constexpr (requires {mimu_data.SPELLING();}) return mimu_data.SPELLING(); /* member function */ \
26else if constexpr (requires {mimu_data->SPELLING;}) return mimu_data->SPELLING; /* member through pointer */ \
27else if constexpr (requires {mimu_data->SPELLING();}) return mimu_data->SPELLING() /* member function through pointer */
28
30auto& accl_of(auto& mimu_data)
31{
32 try_spelling(accelerometer);
33 else try_spelling(acceleration);
34 else try_spelling(accel);
35 else try_spelling(accl);
36 else try_spelling(acc);
37 else try_spelling(a);
38 else return 0; // mimu_data is not MIMU data!
39}
40
42auto& gyro_of(auto& mimu_data)
43{
44 try_spelling(gyroscope);
45 else try_spelling(angular_rate);
46 else try_spelling(gyro);
47 else try_spelling(g);
48 else return 0; // mimu_data is not MIMU data!
49}
50
52auto& magn_of(auto& mimu_data)
53{
54 try_spelling(magnetometer);
55 else try_spelling(magnetic_field);
56 else try_spelling(magn);
57 else try_spelling(mag);
58 else try_spelling(m);
59 else return 0; // mimu_data is not MIMU data!
60}
61
63auto& vecx_of(auto& mimu_data) // this arg has to be called `mimu_data` to work with the macro
64{
65 try_spelling(x);
66 else if constexpr (requires {mimu_data[0];}) return mimu_data[0];
67 else return 0; // mimu_data is not MIMU data!
68}
69
71auto& vecy_of(auto& mimu_data)
72{
73 try_spelling(y);
74 else if constexpr (requires {mimu_data[1];}) return mimu_data[1];
75 else return 0; // mimu_data is not MIMU data!
76}
77
79auto& vecz_of(auto& mimu_data)
80{
81 try_spelling(z);
82 else if constexpr (requires {mimu_data[2];}) return mimu_data[2];
83 else return 0; // mimu_data is not MIMU data!
84}
85
86#undef try_spelling
88template<typename T> using accl_t
89 = std::remove_cvref_t<decltype(accl_of(std::declval<std::remove_cvref_t<T>&>()))>;
91template<typename T> using gyro_t
92 = std::remove_cvref_t<decltype(gyro_of(std::declval<std::remove_cvref_t<T>&>()))>;
94template<typename T> using magn_t
95 = std::remove_cvref_t<decltype(magn_of(std::declval<std::remove_cvref_t<T>&>()))>;
97template<typename T> using vecx_t
98 = std::remove_cvref_t<decltype(vecx_of(std::declval<std::remove_cvref_t<T>&>()))>;
100template<typename T> using vecy_t
101 = std::remove_cvref_t<decltype(vecy_of(std::declval<std::remove_cvref_t<T>&>()))>;
103template<typename T> using vecz_t
104 = std::remove_cvref_t<decltype(vecz_of(std::declval<std::remove_cvref_t<T>&>()))>;
106template<typename T> concept not_void = not std::same_as<void, T>;
107
109template<typename T> concept vec3_like
113 && std::same_as<vecx_t<T>, vecy_t<T>>
114 && std::same_as<vecy_t<T>, vecz_t<T>>
115 ;
117template<typename T> concept has_accl = not_void<accl_t<T>> && vec3_like<accl_t<T>>;
118
120template<typename T> concept has_gyro = not_void<gyro_t<T>> && vec3_like<gyro_t<T>>;
121
123template<typename T> concept has_magn = not_void<magn_t<T>> && vec3_like<magn_t<T>>;
124
126template<typename T>
128
130template<typename T>
136 ;
137
139auto& accl_of(MimuComponent auto& mimu) { return accl_of(mimu.outputs); }
141auto& gyro_of(MimuComponent auto& mimu) { return gyro_of(mimu.outputs); }
143auto& magn_of(MimuComponent auto& mimu) { return magn_of(mimu.outputs); }
144
146auto accl_x(auto& mimu) { return vecx_of(accl_of(mimu)); }
148auto accl_y(auto& mimu) { return vecy_of(accl_of(mimu)); }
150auto accl_z(auto& mimu) { return vecz_of(accl_of(mimu)); }
151
153auto gyro_x(auto& mimu) { return vecx_of(gyro_of(mimu)); }
155auto gyro_y(auto& mimu) { return vecy_of(gyro_of(mimu)); }
157auto gyro_z(auto& mimu) { return vecz_of(gyro_of(mimu)); }
158
160auto magn_x(auto& mimu) { return vecx_of(magn_of(mimu)); }
162auto magn_y(auto& mimu) { return vecy_of(magn_of(mimu)); }
164auto magn_z(auto& mimu) { return vecz_of(magn_of(mimu)); }
165
168}
Definition sygac-endpoints.hpp:97
Check that the type T has an outputs struct that is a MIMU data structure whose vectors satisfy the c...
Definition sygac-mimu.hpp:132
Check that the type T has accelerometer, gyroscope, and magnetometer data at one of the expected inte...
Definition sygac-mimu.hpp:127
Check that the type T has accelerometer vector data at one of the expected interfaces.
Definition sygac-mimu.hpp:117
Check that the type T has gyroscope vector data at one of the expected interfaces.
Definition sygac-mimu.hpp:120
Check that the type T has magnetometer vector data at one of the expected interfaces.
Definition sygac-mimu.hpp:123
Check that type T is not void. Used in the definition of MimuDataStruct.
Definition sygac-mimu.hpp:106
Check that type T seems to be a MIMU data vector. Used in the definition of MimuDataStruct.
Definition sygac-mimu.hpp:110
std::remove_cvref_t< decltype(accl_of(std::declval< std::remove_cvref_t< T > & >()))> accl_t
Access the type of the accelerometer data of a presumed MIMU data structure.
Definition sygac-mimu.hpp:89
std::remove_cvref_t< decltype(vecy_of(std::declval< std::remove_cvref_t< T > & >()))> vecy_t
Access the type of the y component of a presumed MIMU data vector.
Definition sygac-mimu.hpp:101
auto & vecz_of(auto &mimu_data)
Access the third vector component of a presumed MIMU data vector.
Definition sygac-mimu.hpp:79
auto gyro_y(auto &mimu)
Access the second vector component of the gyroscope data of a MIMU data structure or MIMU component.
Definition sygac-mimu.hpp:155
auto accl_z(auto &mimu)
Access the third vector component of the accelerometer data of a MIMU data structure or MIMU componen...
Definition sygac-mimu.hpp:150
std::remove_cvref_t< decltype(vecx_of(std::declval< std::remove_cvref_t< T > & >()))> vecx_t
Access the type of the x component of a presumed MIMU data vector.
Definition sygac-mimu.hpp:98
auto & vecy_of(auto &mimu_data)
Access the second vector component of a presumed MIMU data vector.
Definition sygac-mimu.hpp:71
auto accl_y(auto &mimu)
Access the second vector component of the accelerometer data of a MIMU data structure or MIMU compone...
Definition sygac-mimu.hpp:148
auto & magn_of(auto &mimu_data)
Access the magnetometer data of a presumed MIMU data structure.
Definition sygac-mimu.hpp:52
std::remove_cvref_t< decltype(vecz_of(std::declval< std::remove_cvref_t< T > & >()))> vecz_t
Access the type of the z component of a presumed MIMU data vector.
Definition sygac-mimu.hpp:104
auto & accl_of(auto &mimu_data)
Access the accelerometer data of a presumed MIMU data structure.
Definition sygac-mimu.hpp:30
auto magn_z(auto &mimu)
Access the third vector component of the magnetometer data of a MIMU data structure or MIMU component...
Definition sygac-mimu.hpp:164
auto gyro_z(auto &mimu)
Access the third vector component of the gyroscope data of a MIMU data structure or MIMU component.
Definition sygac-mimu.hpp:157
auto magn_y(auto &mimu)
Access the second vector component of the magnetometer data of a MIMU data structure or MIMU componen...
Definition sygac-mimu.hpp:162
auto gyro_x(auto &mimu)
Access the first vector component of the gyroscope data of a MIMU data structure or MIMU component.
Definition sygac-mimu.hpp:153
auto & gyro_of(auto &mimu_data)
Access the gyroscope data of a presumed MIMU data structure.
Definition sygac-mimu.hpp:42
auto accl_x(auto &mimu)
Access the first vector component of the accelerometer data of a MIMU data structure or MIMU componen...
Definition sygac-mimu.hpp:146
std::remove_cvref_t< decltype(gyro_of(std::declval< std::remove_cvref_t< T > & >()))> gyro_t
Access the type of the gyroscope data of a presumed MIMU data structure.
Definition sygac-mimu.hpp:92
auto & vecx_of(auto &mimu_data)
Access the first vector component of a presumed MIMU data vector.
Definition sygac-mimu.hpp:63
std::remove_cvref_t< decltype(magn_of(std::declval< std::remove_cvref_t< T > & >()))> magn_t
Access the type of the magnetometer data of a presumed MIMU data structure.
Definition sygac-mimu.hpp:95
auto magn_x(auto &mimu)
Access the first vector component of the magnetometer data of a MIMU data structure or MIMU component...
Definition sygac-mimu.hpp:160