24 #include <SimoxUtility/math/convert/mat3f_to_rpy.h>
27 #include <RobotAPI/libraries/armem_robot_state/aron/Proprioception.aron.generated.h>
28 #include <RobotAPI/libraries/armem_robot_state/aron/Transform.aron.generated.h>
29 #include <RobotAPI/libraries/armem_robot_state/aron/RobotDescription.aron.generated.h>
38 std::string prefix =
"mem.";
39 defs->optional(properties.frequency, prefix +
"updateFrequency",
"The frequency in Hz to check for updates and send them to the memory.");
40 defs->optional(properties.memoryNameSystemName, prefix +
"memoryNameSystemName",
"The name of the MemoryNameSystem.");
41 defs->optional(properties.robotStateMemoryName, prefix +
"memoryName",
"The name of the RobotStateMemory.");
44 defs->topic<KinematicUnitListener>(
"RealRobotState", prefix +
"KinematicUnitName");
45 defs->topic<PlatformUnitListener>(
"Armar6PlatformUnit", prefix +
"PlatformUnitName");
52 return "LegacyRobotStateMemoryAdapter";
55 void LegacyRobotStateMemoryAdapter::checkUpdateAndSendToMemory()
57 std::lock_guard l(updateMutex);
66 arondto::Proprioception prop;
67 for (
const auto& [k,
v] : update.jointAngles)
69 prop.joints.position[k] =
v;
71 for (
const auto& [k,
v] : update.jointAccelerations)
73 prop.joints.acceleration[k] =
v;
75 for (
const auto& [k,
v] : update.jointCurrents)
77 prop.joints.motorCurrent[k] =
v;
79 for (
const auto& [k,
v] : update.jointTorques)
81 prop.joints.torque[k] =
v;
83 for (
const auto& [k,
v] : update.jointVelocities)
85 prop.joints.velocity[k] =
v;
89 prop.platform.acceleration = Eigen::Vector3f::Zero();
90 prop.platform.relativePosition = Eigen::Vector3f(update.platformPose.x,
91 update.platformPose.y,
92 update.platformPose.rotationAroundZ);
93 prop.platform.velocity = Eigen::Vector3f(std::get<0>(update.platformVelocity),
94 std::get<1>(update.platformVelocity),
95 std::get<2>(update.platformVelocity));
98 entityUpdate.
entityID = propEntityID;
109 if (!updateResult.success)
123 tf.translation().x() = (update.platformPose.x);
124 tf.translation().y() = (update.platformPose.y);
125 tf.linear() = Eigen::AngleAxisf((update.platformPose.rotationAroundZ), Eigen::Vector3f::UnitZ()).toRotationMatrix();
140 if (!updateResult.success)
148 updateChanged =
true;
151 void LegacyRobotStateMemoryAdapter::updateTimestamps(
long ts)
155 _timestampUpdateFirstModifiedInUs = IceUtil::Time::now().toMicroSeconds();
157 updateChanged =
false;
168 std::lock_guard l(updateMutex);
169 update.jointAngles = m;
170 updateTimestamps(ts);
176 std::lock_guard l(updateMutex);
177 update.jointVelocities = m;
178 updateTimestamps(ts);
184 std::lock_guard l(updateMutex);
185 update.jointTorques = m;
186 updateTimestamps(ts);
192 std::lock_guard l(updateMutex);
193 update.jointAccelerations = m;
194 updateTimestamps(ts);
200 std::lock_guard l(updateMutex);
201 update.jointCurrents = m;
202 updateTimestamps(ts);
228 const Eigen::Isometry3f global_T_robot(transformStamped.transform);
229 const float yaw = simox::math::mat3f_to_rpy(global_T_robot.linear()).z();
231 armarx::PlatformPose p;
232 p.x = global_T_robot.translation().x();
233 p.y = global_T_robot.translation().y();
234 p.rotationAroundZ = yaw;
235 p.timestampInMicroSeconds = transformStamped.header.timestampInMicroSeconds;
238 std::lock_guard l(updateMutex);
239 update.platformPose = p;
240 updateTimestamps(p.timestampInMicroSeconds);
248 auto now = IceUtil::Time::now().toMicroSeconds();
250 std::lock_guard l(updateMutex);
251 update.platformVelocity = {f1, f2, f3};
252 updateTimestamps(now);
257 auto now = IceUtil::Time::now().toMicroSeconds();
259 std::lock_guard l(updateMutex);
260 update.platformOdometryPose = {f1, f2, f3};
261 updateTimestamps(now);
266 void LegacyRobotStateMemoryAdapter::commitArmar3RobotDescription()
269 armem::arondto::RobotDescription desc;
270 desc.name =
"Armar3";
272 desc.xml.package =
"RobotAPI";
273 desc.xml.path =
"robots/Armar3/ArmarIII.xml";
276 auto& entityUpdate =
c.add();
278 entityUpdate.confidence = 1.0;
281 entityUpdate.entityID.providerSegmentName =
"Armar3";
282 entityUpdate.entityID.entityName =
"Armar3";
284 entityUpdate.instancesData = { desc.toAron() };
286 auto res = memoryWriter.
commit(
c);
287 if (!res.allSuccess())
289 ARMARX_WARNING <<
"Could not send data to memory." << res.allErrorMessages();
298 const int minFrequency = 1;
299 const int maxFrequency = 100;
300 properties.frequency =
std::clamp(properties.frequency, minFrequency, maxFrequency);
301 const int fInMS = (1000 / properties.frequency);
310 auto mns =
client::MemoryNameSystem(getProxy<mns::MemoryNameSystemInterfacePrx>(properties.memoryNameSystemName),
this);
313 ARMARX_IMPORTANT <<
"Waiting for memory '" << properties.robotStateMemoryName <<
"' ...";
314 propEntityID.
memoryName = properties.robotStateMemoryName;
317 memoryWriter = mns.useWriter(properties.robotStateMemoryName);
326 commitArmar3RobotDescription();
328 runningTask->start();