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));
109 armem::EntityUpdate entityUpdate;
110 entityUpdate.
entityID = propEntityID;
112 _timestampUpdateFirstModifiedInUs));
117 armem::EntityUpdateResult updateResult = memoryWriter.commit(entityUpdate);
119 if (!updateResult.success)
133 Eigen::Isometry3f tf = Eigen::Isometry3f::Identity();
134 tf.translation().x() = (update.platformPose.x);
135 tf.translation().y() = (update.platformPose.y);
137 Eigen::AngleAxisf((update.platformPose.rotationAroundZ), Eigen::Vector3f::UnitZ())
142 armem::EntityUpdate locUpdate;
149 armem::EntityUpdateResult updateResult = memoryWriter.commit(locUpdate);
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);
367 ARMARX_IMPORTANT <<
"Waiting for memory '" << properties.robotStateMemoryName <<
"' ...";
368 propEntityID.memoryName = properties.robotStateMemoryName;
371 memoryWriter =
mns.useWriter(properties.robotStateMemoryName);
380 commitArmar3RobotDescription();
382 runningTask->start();
Default component property definition container.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
The periodic task executes one thread method repeatedly using the time period specified in the constr...
void reportJointAccelerations(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
void onInitComponent() override
void reportJointStatuses(const NameStatusMap &, Ice::Long, bool, const Ice::Current &) override
void reportGlobalRobotPose(const ::armarx::TransformStamped &, const ::Ice::Current &=::Ice::emptyCurrent) override
void onDisconnectComponent() override
void reportJointCurrents(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void reportControlModeChanged(const NameControlModeMap &, Ice::Long, bool, const Ice::Current &) override
void reportJointMotorTemperatures(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
void onConnectComponent() override
void reportPlatformOdometryPose(Ice::Float, Ice::Float, Ice::Float, const Ice::Current &) override
void reportJointAngles(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
void reportJointVelocities(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
void onExitComponent() override
void reportPlatformVelocity(Ice::Float, Ice::Float, Ice::Float, const Ice::Current &) override
std::string getDefaultName() const override
void reportJointTorques(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
The memory name system (MNS) client.
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Base class for all exceptions thrown by the armem library.
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
const std::string descriptionCoreSegment
const std::string memoryName
const std::string robotRootNodeName
armarx::core::time::DateTime Time
double v(double t, double v0, double a0, double j)
std::string const OdometryFrame
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT > >
Convenience function (with less typing) to transform a container of type InputT into the same contain...
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
A bundle of updates to be sent to the memory.
MemoryID entityID
The entity's ID.
Time referencedTime
Time when this entity update was created (e.g.
std::vector< aron::data::DictPtr > instancesData
The entity data.