4 #include <SimoxUtility/algorithm/get_map_keys_values.h>
5 #include <SimoxUtility/algorithm/advanced.h>
7 #include <RobotAPI/interface/units/RobotUnit/RobotUnitInterface.h>
32 const RobotUnitDataStreaming::TimeStep&
data,
33 const RobotUnitDataStreaming::DataStreamingDescription& description)
35 arondto::Proprioception dto;
36 dto.iterationID =
data.iterationId;
38 for (
const auto& [dataEntryName, dataEntry] : description.entries)
47 arondto::Proprioception& dto,
48 const std::string& entryName,
53 const std::set<size_t> acceptedSizes{3, 4, 5};
55 <<
"Data entry name could not be parsed (exected 3 or 4 or 5 components between '.'): "
56 <<
"\n- split: '" <<
split <<
"'";
58 const std::string& category =
split.at(0);
59 const std::string& name =
split.at(1);
60 const std::string& field =
split.at(2);
63 if (name ==
"Platform")
66 processPlatformEntry(dto.platform, field,
value);
71 processForceTorqueEntry(dto.forceTorque,
split,
value);
76 bool processed = processJointEntry(dto.joints,
split,
value);
80 const std::vector<std::string> comps{simox::alg::advanced(
split.begin(), 1),
split.end()};
81 const std::string key = simox::alg::join(comps,
".");
83 switch (
value.entry.type)
85 case RobotUnitDataStreaming::NodeTypeFloat:
86 dto.extraFloats[key] = getValueAs<float>(
value);
88 case RobotUnitDataStreaming::NodeTypeLong:
89 dto.extraLongs[key] = getValueAs<long>(
value);
91 case RobotUnitDataStreaming::NodeTypeBool:
92 dto.extraBools[key] = getValueAs<bool>(
value);
94 case RobotUnitDataStreaming::NodeTypeInt:
95 dto.extraInts[key] = getValueAs<int>(
value);
97 case RobotUnitDataStreaming::NodeTypeShort:
98 dto.extraShorts[key] = getValueAs<Ice::Short>(
value);
100 case RobotUnitDataStreaming::NodeTypeByte:
101 dto.extraBytes[key] = getValueAs<Ice::Byte>(
value);
104 ARMARX_DEBUG <<
"Cannot handle extra field '" << key <<
"' of type "
114 void Armar6Converter::processPlatformEntry(
115 prop::arondto::Platform& dto,
116 const std::string& fieldName,
123 else if (
auto getter =
findByPrefix(fieldName, tools->platformPoseGetters))
125 if (Eigen::Vector3f* dst = getter(dto))
127 if (
auto setter =
findBySuffix(fieldName, tools->vector3fSetters))
129 setter(*dst, getValueAs<float>(
value));
136 dto.extra[fieldName] = getValueAs<float>(
value);
141 void Armar6Converter::processForceTorqueEntry(
142 std::map<std::string, prop::arondto::ForceTorque>& fts,
143 const std::vector<std::string>&
split,
144 const ConverterValue&
value)
146 const std::string& name =
split.at(1);
151 auto it = tools->sidePrefixMap.find(splitName.at(1));
152 ARMARX_CHECK(it != tools->sidePrefixMap.end()) << splitName.at(1);
154 const std::string& side = it->second;
155 processForceTorqueEntry(fts[side],
split,
value);
159 void Armar6Converter::processForceTorqueEntry(
160 prop::arondto::ForceTorque& dto,
161 const std::vector<std::string>&
split,
162 const ConverterValue&
value)
164 const std::string& fieldName =
split.at(2);
165 if (
auto getter =
findByPrefix(fieldName, tools->ftGetters))
167 if (Eigen::Vector3f* dst = getter(dto))
169 if (
auto setter =
findBySuffix(fieldName, tools->vector3fSetters))
171 setter(*dst, getValueAs<float>(
value));
178 std::string key =
split.size() == 4
179 ? (fieldName +
"." +
split.at(3))
182 switch (
value.entry.type)
184 case RobotUnitDataStreaming::NodeTypeFloat:
185 dto.extra[key] = getValueAs<float>(
value);
187 case RobotUnitDataStreaming::NodeTypeInt:
188 dto.extra[key] = getValueAs<int>(
value);
190 case RobotUnitDataStreaming::NodeTypeLong:
191 dto.extra[key] = getValueAs<long>(
value);
194 ARMARX_DEBUG <<
"Cannot handle extra field '" << key <<
"' of type "
202 bool Armar6Converter::processJointEntry(
204 const std::vector<std::string>&
split,
205 const ConverterValue&
value)
207 const std::string& jointName =
split.at(1);
208 const std::string& fieldName =
split.at(2);
212 if (
auto getter =
findByPrefix(fieldName, tools->jointGetters))
214 if (std::map<std::string, float>* map = getter(dto))
216 (*map)[jointName] = getValueAs<float>(
value);
221 const std::string tempSuffix =
"Temperature";
225 const std::string name =
split.at(2).substr(0,
split.at(2).size() - tempSuffix.size());
226 dto.temperature[
split.at(1)][name] = getValueAs<float>(
value);
229 else if (
auto it = tools->jointSetters.find(fieldName); it != tools->jointSetters.end())