ConverterTools.cpp
Go to the documentation of this file.
1 #include "ConverterTools.h"
2 
3 #include <SimoxUtility/algorithm/get_map_keys_values.h>
4 #include <SimoxUtility/algorithm/advanced.h>
5 
8 
9 
11 {
12 
13  std::optional<std::string>
14  exteroception::findByPrefix(const std::string& key, const std::set<std::string>& prefixes)
15  {
16  for (const auto& prefix : prefixes)
17  {
18  if (simox::alg::starts_with(key, prefix))
19  {
20  return prefix;
21  }
22  }
23  return std::nullopt;
24  }
25 }
26 
27 
29 {
31  {
32  {
33  vector3fSetters["X"] = [](Eigen::Vector3f & v, float f)
34  {
35  v.x() = f;
36  };
37  vector3fSetters["Y"] = [](Eigen::Vector3f & v, float f)
38  {
39  v.y() = f;
40  };
41  vector3fSetters["Z"] = [](Eigen::Vector3f & v, float f)
42  {
43  v.z() = f;
44  };
45  vector3fSetters["x"] = vector3fSetters["X"];
46  vector3fSetters["y"] = vector3fSetters["Y"];
47  vector3fSetters["z"] = vector3fSetters["Z"];
48  vector3fSetters["Rotation"] = vector3fSetters["Z"];
49  }
50  {
51  platformPoseGetters["acceleration"] = [](prop::arondto::Platform & p)
52  {
53  return &p.acceleration;
54  };
55  platformPoseGetters["relativePosition"] = [](prop::arondto::Platform & p)
56  {
57  return &p.relativePosition;
58  };
59  platformPoseGetters["velocity"] = [](prop::arondto::Platform & p)
60  {
61  return &p.velocity;
62  };
63  platformIgnored.insert("absolutePosition");
64  }
65  {
66  ftGetters["gravCompF"] = [](prop::arondto::ForceTorque & ft)
67  {
68  return &ft.gravityCompensationForce;
69  };
70  ftGetters["gravCompT"] = [](prop::arondto::ForceTorque & ft)
71  {
72  return &ft.gravityCompensationTorque;
73  };
74  ftGetters["f"] = [](prop::arondto::ForceTorque & ft)
75  {
76  return &ft.force;
77  };
78  ftGetters["t"] = [](prop::arondto::ForceTorque & ft)
79  {
80  return &ft.torque;
81  };
82  }
83  {
84  jointGetters["acceleration"] = [](prop::arondto::Joints & j)
85  {
86  return &j.acceleration;
87  };
88  jointGetters["gravityTorque"] = [](prop::arondto::Joints & j)
89  {
90  return &j.gravityTorque;
91  };
92  jointGetters["inertiaTorque"] = [](prop::arondto::Joints & j)
93  {
94  return &j.inertiaTorque;
95  };
96  jointGetters["inverseDynamicsTorque"] = [](prop::arondto::Joints & j)
97  {
98  return &j.inverseDynamicsTorque;
99  };
100  jointGetters["position"] = [](prop::arondto::Joints & j)
101  {
102  return &j.position;
103  };
104  jointGetters["torque"] = [](prop::arondto::Joints & j)
105  {
106  return &j.torque;
107  };
108  jointGetters["velocity"] = [](prop::arondto::Joints & j)
109  {
110  return &j.velocity;
111  };
112  }
113  {
114 
115 #define ADD_SCALAR_SETTER(container, name, type) \
116  container [ #name ] = []( \
117  prop::arondto::Joints & dto, \
118  const std::vector<std::string>& split, \
119  const ConverterValue & value) \
120  { \
121  dto. name [split.at(1)] = getValueAs< type >(value); \
122  }
123 
124  ADD_SCALAR_SETTER(jointSetters, position, float);
125  ADD_SCALAR_SETTER(jointSetters, velocity, float);
126  ADD_SCALAR_SETTER(jointSetters, acceleration, float);
127 
128  ADD_SCALAR_SETTER(jointSetters, relativePosition, float);
129  ADD_SCALAR_SETTER(jointSetters, filteredVelocity, float);
130 
131  ADD_SCALAR_SETTER(jointSetters, currentTarget, float);
132  ADD_SCALAR_SETTER(jointSetters, positionTarget, float);
133  ADD_SCALAR_SETTER(jointSetters, velocityTarget, float);
134 
135  ADD_SCALAR_SETTER(jointSetters, torque, float);
136  ADD_SCALAR_SETTER(jointSetters, inertiaTorque, float);
137  ADD_SCALAR_SETTER(jointSetters, gravityTorque, float);
138  ADD_SCALAR_SETTER(jointSetters, gravityCompensatedTorque, float);
139  ADD_SCALAR_SETTER(jointSetters, inverseDynamicsTorque, float);
140  ADD_SCALAR_SETTER(jointSetters, torqueTicks, int);
141 
142  ADD_SCALAR_SETTER(jointSetters, positionTarget, float);
143  ADD_SCALAR_SETTER(jointSetters, currentTarget, float);
144  ADD_SCALAR_SETTER(jointSetters, positionTarget, float);
145 
146  // "temperature" handled below
147  // ADD_SCALAR_SETTER(jointSetters, temperature, float);
148 
149  ADD_SCALAR_SETTER(jointSetters, motorCurrent, float);
150  ADD_SCALAR_SETTER(jointSetters, maxTargetCurrent, float);
151 
152  ADD_SCALAR_SETTER(jointSetters, sensorBoardUpdateRate, float);
153  ADD_SCALAR_SETTER(jointSetters, I2CUpdateRate, float);
154 
155  ADD_SCALAR_SETTER(jointSetters, JointStatusEmergencyStop, bool);
156  ADD_SCALAR_SETTER(jointSetters, JointStatusEnabled, bool);
157  ADD_SCALAR_SETTER(jointSetters, JointStatusError, int);
158  ADD_SCALAR_SETTER(jointSetters, JointStatusOperation, int);
159 
160 
161 #define ADD_VECTOR3_SETTER(container, name, type) \
162  container [ #name ] = [this]( \
163  prop::arondto::Joints & dto, \
164  const std::vector<std::string>& split, \
165  const ConverterValue & value) \
166  { \
167  auto& vec = dto. name [split.at(1)]; \
168  auto& setter = this->vector3fSetters.at(split.at(3)); \
169  setter(vec, getValueAs< type >(value)); \
170  }
171 
172  ADD_VECTOR3_SETTER(jointSetters, angularVelocity, float);
173  ADD_VECTOR3_SETTER(jointSetters, linearAcceleration, float);
174 
175  // ADD_GETTER(jointVectorGetters, orientation, float);
176  }
177  }
178 
179 }
armarx::human::pose::model::k4a_bt_body_32::Joints
Joints
Joints with index as defined in the body model.
Definition: k4a_bt_body_32.h:39
ADD_VECTOR3_SETTER
#define ADD_VECTOR3_SETTER(container, name, type)
armarx::armem::server::robot_state::exteroception::findByPrefix
std::optional< std::string > findByPrefix(const std::string &key, const std::set< std::string > &prefixes)
Search.
Definition: ConverterTools.cpp:14
ConverterTools.h
armarx::starts_with
bool starts_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:43
armarx::armem::server::robot_state::exteroception::ConverterTools::platformIgnored
std::set< std::string > platformIgnored
Definition: ConverterTools.h:94
Dict.h
armarx::armem::server::robot_state::exteroception::ConverterTools::vector3fSetters
std::map< std::string, std::function< void(Eigen::Vector3f &, float)> > vector3fSetters
Definition: ConverterTools.h:85
armarx::armem::server::robot_state
Definition: RobotStateMemory.cpp:40
RobotUnitDataStreamingReceiver.h
armarx::armem::server::robot_state::exteroception::ConverterTools::ftGetters
std::map< std::string, std::function< Eigen::Vector3f *(prop::arondto::ForceTorque &)> > ftGetters
Definition: ConverterTools.h:96
armarx::armem::server::robot_state::exteroception::ConverterTools::ConverterTools
ConverterTools()
Definition: ConverterTools.cpp:30
armarx::armem::server::robot_state::exteroception::ConverterTools::platformPoseGetters
std::map< std::string, std::function< Eigen::Vector3f *(prop::arondto::Platform &)> > platformPoseGetters
Definition: ConverterTools.h:93
armarx::armem::server::robot_state::exteroception::ConverterTools::jointSetters
std::map< std::string, JointSetter > jointSetters
Definition: ConverterTools.h:91
armarx::armem::server::robot_state::exteroception
Definition: ArmarDEConverter.cpp:18
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
ADD_SCALAR_SETTER
#define ADD_SCALAR_SETTER(container, name, type)
armarx::armem::server::robot_state::exteroception::ConverterTools::jointGetters
std::map< std::string, std::function< std::map< std::string, float > *(prop::arondto::Joints &)> > jointGetters
Definition: ConverterTools.h:87