-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMotorMetaInfo.cpp
54 lines (45 loc) · 1.14 KB
/
MotorMetaInfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "MotorMetaInfo.h"
#include <cmath>
namespace dynamixel::meta {
auto getMotorInfos() -> std::vector<MotorInfo> const& {
static auto data = std::vector<MotorInfo>{};
static bool firstRun{true};
if (firstRun) {
firstRun = false;
meta::forAllLayoutTypes([&](auto const& _info) {
using Info = std::decay_t<decltype(_info)>;
auto& defaults = Info::getDefaults();
for (auto [id, d] : defaults) {
MotorInfo info;
info.modelNumber = d.modelNumber;
info.layout = d.layout;
info.shortName = d.shortName;
info.motorNames = d.motorNames;
data.push_back(info);
}
});
}
return data;
}
auto getMotorInfo(uint16_t _modelNumber) -> MotorInfo const* {
for (auto const& motorInfo : getMotorInfos()) {
if (motorInfo.modelNumber == _modelNumber) {
return &motorInfo;
}
}
return nullptr;
}
auto getMotorInfo(std::string const& _name) -> MotorInfo const* {
for (auto const& motorInfo : getMotorInfos()) {
if (motorInfo.shortName == _name) {
return &motorInfo;
}
for (auto const& _other : motorInfo.motorNames) {
if (_other == _name) {
return &motorInfo;
}
}
}
return nullptr;
}
}