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>
35 "LegacyRobotStateMemoryAdapter");
46 std::string prefix =
"mem.";
47 defs->optional(properties.frequency,
48 prefix +
"updateFrequency",
49 "The frequency in Hz to check for updates and send them to the memory.");
50 defs->optional(properties.memoryNameSystemName,
51 prefix +
"memoryNameSystemName",
52 "The name of the MemoryNameSystem.");
53 defs->optional(properties.robotStateMemoryName,
54 prefix +
"memoryName",
55 "The name of the RobotStateMemory.");
58 defs->topic<KinematicUnitListener>(
"RealRobotState", prefix +
"KinematicUnitName");
59 defs->topic<PlatformUnitListener>(
"Armar6PlatformUnit", prefix +
"PlatformUnitName");
66 return "LegacyRobotStateMemoryAdapter";
70 LegacyRobotStateMemoryAdapter::checkUpdateAndSendToMemory()
72 std::lock_guard l(updateMutex);
77 <<
"Try to send data to robotStateMemory but data has not changed.";
82 arondto::Proprioception prop;
83 for (
const auto& [k, v] : update.jointAngles)
85 prop.joints.position[k] = v;
87 for (
const auto& [k, v] : update.jointAccelerations)
89 prop.joints.acceleration[k] = v;
91 for (
const auto& [k, v] : update.jointCurrents)
93 prop.joints.motorCurrent[k] =
v;
95 for (
const auto& [k, v] : update.jointTorques)
97 prop.joints.torque[k] =
v;
99 for (
const auto& [k, v] : update.jointVelocities)
101 prop.joints.velocity[k] =
v;
105 prop.platform.acceleration = Eigen::Vector3f::Zero();
106 prop.platform.relativePosition =
107 Eigen::Vector3f(update.platformPose.x,
108 update.platformPose.y,
109 update.platformPose.rotationAroundZ);
110 prop.platform.velocity = Eigen::Vector3f(std::get<0>(update.platformVelocity),
111 std::get<1>(update.platformVelocity),
112 std::get<2>(update.platformVelocity));
114 armem::EntityUpdate entityUpdate;
115 entityUpdate.
entityID = propEntityID;
117 _timestampUpdateFirstModifiedInUs));
122 armem::EntityUpdateResult updateResult = memoryWriter.commit(entityUpdate);
124 if (!updateResult.success)
138 Eigen::Isometry3f tf = Eigen::Isometry3f::Identity();
139 tf.translation().x() = (update.platformPose.x);
140 tf.translation().y() = (update.platformPose.y);
142 Eigen::AngleAxisf((update.platformPose.rotationAroundZ), Eigen::Vector3f::UnitZ())
147 armem::EntityUpdate locUpdate;
154 armem::EntityUpdateResult updateResult = memoryWriter.commit(locUpdate);
156 if (!updateResult.success)
164 updateChanged =
true;
168 LegacyRobotStateMemoryAdapter::updateTimestamps(
long ts)
172 _timestampUpdateFirstModifiedInUs = IceUtil::Time::now().toMicroSeconds();
174 updateChanged =
false;
192 std::lock_guard l(updateMutex);
193 update.jointAngles = m;
194 updateTimestamps(ts);
204 std::lock_guard l(updateMutex);
205 update.jointVelocities = m;
206 updateTimestamps(ts);
216 std::lock_guard l(updateMutex);
217 update.jointTorques = m;
218 updateTimestamps(ts);
228 std::lock_guard l(updateMutex);
229 update.jointAccelerations = m;
230 updateTimestamps(ts);
240 std::lock_guard l(updateMutex);
241 update.jointCurrents = m;
242 updateTimestamps(ts);
271 const ::armarx::TransformStamped& transformStamped,
272 const ::Ice::Current&)
277 const Eigen::Isometry3f global_T_robot(transformStamped.transform);
278 const float yaw = simox::math::mat3f_to_rpy(global_T_robot.linear()).z();
280 armarx::PlatformPose p;
281 p.x = global_T_robot.translation().x();
282 p.y = global_T_robot.translation().y();
283 p.rotationAroundZ = yaw;
284 p.timestampInMicroSeconds = transformStamped.header.timestampInMicroSeconds;
287 std::lock_guard l(updateMutex);
288 update.platformPose = p;
289 updateTimestamps(p.timestampInMicroSeconds);
300 auto now = IceUtil::Time::now().toMicroSeconds();
302 std::lock_guard l(updateMutex);
303 update.platformVelocity = {f1, f2, f3};
304 updateTimestamps(now);
314 auto now = IceUtil::Time::now().toMicroSeconds();
316 std::lock_guard l(updateMutex);
317 update.platformOdometryPose = {f1, f2, f3};
318 updateTimestamps(now);
322 LegacyRobotStateMemoryAdapter::commitArmar3RobotDescription()
325 armem::arondto::RobotDescription desc;
326 desc.name =
"Armar3";
328 desc.xml.package =
"RobotAPI";
329 desc.xml.path =
"robots/Armar3/ArmarIII.xml";
332 auto& entityUpdate =
c.add();
334 entityUpdate.confidence = 1.0;
336 entityUpdate.entityID.coreSegmentName =
338 entityUpdate.entityID.providerSegmentName =
"Armar3";
339 entityUpdate.entityID.entityName =
"Armar3";
341 entityUpdate.instancesData = {desc.toAron()};
343 auto res = memoryWriter.
commit(
c);
344 if (!res.allSuccess())
346 ARMARX_WARNING <<
"Could not send data to memory." << res.allErrorMessages();
355 const int minFrequency = 1;
356 const int maxFrequency = 100;
357 properties.frequency = std::clamp(properties.frequency, minFrequency, maxFrequency);
358 const int fInMS = (1000 / properties.frequency);
362 this, &LegacyRobotStateMemoryAdapter::checkUpdateAndSendToMemory, fInMS);
372 ARMARX_IMPORTANT <<
"Waiting for memory '" << properties.robotStateMemoryName <<
"' ...";
373 propEntityID.memoryName = properties.robotStateMemoryName;
376 memoryWriter =
mns.useWriter(properties.robotStateMemoryName);
385 commitArmar3RobotDescription();
387 runningTask->start();
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
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.