25 #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/RobotDescription.aron.generated.h>
29 #include <RobotAPI/libraries/armem_robot_state/aron/Transform.aron.generated.h>
41 std::string prefix =
"mem.";
42 defs->optional(properties.frequency,
43 prefix +
"updateFrequency",
44 "The frequency in Hz to check for updates and send them to the memory.");
45 defs->optional(properties.memoryNameSystemName,
46 prefix +
"memoryNameSystemName",
47 "The name of the MemoryNameSystem.");
48 defs->optional(properties.robotStateMemoryName,
49 prefix +
"memoryName",
50 "The name of the RobotStateMemory.");
53 defs->topic<KinematicUnitListener>(
"RealRobotState", prefix +
"KinematicUnitName");
54 defs->topic<PlatformUnitListener>(
"Armar6PlatformUnit", prefix +
"PlatformUnitName");
61 return "LegacyRobotStateMemoryAdapter";
65 LegacyRobotStateMemoryAdapter::checkUpdateAndSendToMemory()
67 std::lock_guard l(updateMutex);
72 <<
"Try to send data to robotStateMemory but data has not changed.";
77 arondto::Proprioception prop;
78 for (
const auto& [k,
v] : update.jointAngles)
80 prop.joints.position[k] =
v;
82 for (
const auto& [k,
v] : update.jointAccelerations)
84 prop.joints.acceleration[k] =
v;
86 for (
const auto& [k,
v] : update.jointCurrents)
88 prop.joints.motorCurrent[k] =
v;
90 for (
const auto& [k,
v] : update.jointTorques)
92 prop.joints.torque[k] =
v;
94 for (
const auto& [k,
v] : update.jointVelocities)
96 prop.joints.velocity[k] =
v;
100 prop.platform.acceleration = Eigen::Vector3f::Zero();
101 prop.platform.relativePosition =
102 Eigen::Vector3f(update.platformPose.x,
103 update.platformPose.y,
104 update.platformPose.rotationAroundZ);
105 prop.platform.velocity = Eigen::Vector3f(std::get<0>(update.platformVelocity),
106 std::get<1>(update.platformVelocity),
107 std::get<2>(update.platformVelocity));
110 entityUpdate.
entityID = propEntityID;
112 _timestampUpdateFirstModifiedInUs));
119 if (!updateResult.success)
134 tf.translation().x() = (update.platformPose.x);
135 tf.translation().y() = (update.platformPose.y);
137 Eigen::AngleAxisf((update.platformPose.rotationAroundZ), Eigen::Vector3f::UnitZ())
151 if (!updateResult.success)
159 updateChanged =
true;
163 LegacyRobotStateMemoryAdapter::updateTimestamps(
long ts)
167 _timestampUpdateFirstModifiedInUs = IceUtil::Time::now().toMicroSeconds();
169 updateChanged =
false;
187 std::lock_guard l(updateMutex);
188 update.jointAngles = m;
189 updateTimestamps(ts);
199 std::lock_guard l(updateMutex);
200 update.jointVelocities = m;
201 updateTimestamps(ts);
211 std::lock_guard l(updateMutex);
212 update.jointTorques = m;
213 updateTimestamps(ts);
223 std::lock_guard l(updateMutex);
224 update.jointAccelerations = m;
225 updateTimestamps(ts);
235 std::lock_guard l(updateMutex);
236 update.jointCurrents = m;
237 updateTimestamps(ts);
266 const ::armarx::TransformStamped& transformStamped,
267 const ::Ice::Current&)
272 const Eigen::Isometry3f global_T_robot(transformStamped.transform);
273 const float yaw = simox::math::mat3f_to_rpy(global_T_robot.linear()).z();
275 armarx::PlatformPose p;
276 p.x = global_T_robot.translation().x();
277 p.y = global_T_robot.translation().y();
278 p.rotationAroundZ = yaw;
279 p.timestampInMicroSeconds = transformStamped.header.timestampInMicroSeconds;
282 std::lock_guard l(updateMutex);
283 update.platformPose = p;
284 updateTimestamps(p.timestampInMicroSeconds);
295 auto now = IceUtil::Time::now().toMicroSeconds();
297 std::lock_guard l(updateMutex);
298 update.platformVelocity = {f1, f2, f3};
299 updateTimestamps(now);
309 auto now = IceUtil::Time::now().toMicroSeconds();
311 std::lock_guard l(updateMutex);
312 update.platformOdometryPose = {f1, f2, f3};
313 updateTimestamps(now);
317 LegacyRobotStateMemoryAdapter::commitArmar3RobotDescription()
320 armem::arondto::RobotDescription desc;
321 desc.name =
"Armar3";
323 desc.xml.package =
"RobotAPI";
324 desc.xml.path =
"robots/Armar3/ArmarIII.xml";
327 auto& entityUpdate =
c.add();
329 entityUpdate.confidence = 1.0;
331 entityUpdate.entityID.coreSegmentName =
333 entityUpdate.entityID.providerSegmentName =
"Armar3";
334 entityUpdate.entityID.entityName =
"Armar3";
336 entityUpdate.instancesData = {desc.toAron()};
338 auto res = memoryWriter.
commit(
c);
339 if (!res.allSuccess())
341 ARMARX_WARNING <<
"Could not send data to memory." << res.allErrorMessages();
350 const int minFrequency = 1;
351 const int maxFrequency = 100;
352 properties.frequency =
std::clamp(properties.frequency, minFrequency, maxFrequency);
353 const int fInMS = (1000 / properties.frequency);
357 this, &LegacyRobotStateMemoryAdapter::checkUpdateAndSendToMemory, fInMS);
364 getProxy<mns::MemoryNameSystemInterfacePrx>(properties.memoryNameSystemName),
this);
367 ARMARX_IMPORTANT <<
"Waiting for memory '" << properties.robotStateMemoryName <<
"' ...";
368 propEntityID.
memoryName = properties.robotStateMemoryName;
371 memoryWriter = mns.useWriter(properties.robotStateMemoryName);
380 commitArmar3RobotDescription();
382 runningTask->start();