22#include <RobotAPI/libraries/armem_robot_state/aron/Exteroception.aron.generated.h>
23#include <RobotAPI/libraries/armem_robot_state/aron/Proprioception.aron.generated.h>
24#include <RobotAPI/libraries/armem_robot_state/aron/Robot.aron.generated.h>
30namespace fs = ::std::filesystem;
35 properties(r.properties),
36 propertyPrefix(r.propertyPrefix),
37 memoryReader(r.memoryReader),
38 transformReader(r.transformReader)
45 transformReader.registerPropertyDefinitions(def);
51 transformReader.connect(memoryNameSystem);
60 memoryReader = transformReader.getMemoryReader();
132 ARMARX_INFO <<
"Retrying to query robot state after failure";
136 robot.
config = std::move(*state);
141 std::optional<description::RobotDescription>
160 if (not memoryReader)
162 ARMARX_WARNING <<
"Memory reader is null. Did you forget to call "
163 "RobotReader::connect() in onConnectComponent()?";
169 std::scoped_lock l(memoryReaderMutex);
179 return getRobotDescription(qResult.
memory, name);
189 std::optional<RobotState>
199 ARMARX_VERBOSE <<
"Failed to query global pose for robot " << robotName;
202 robotState->globalPose = *globalPose;
208 std::optional<RobotState>
215 ARMARX_VERBOSE <<
"Failed to query proprioception for robot '" << robotName <<
"'.";
221 .globalPose = RobotState::Pose::Identity(),
222 .jointMap = jointMap,
226 std::optional<::armarx::armem::robot_state::localization::Transform>
238 const auto result = transformReader.lookupTransform(
query);
243 return result.transform;
252 std::optional<armarx::armem::arondto::Proprioception>
261 ARMARX_DEBUG <<
"Querying robot description for robot: " << robotName;
273 std::scoped_lock l(memoryReaderMutex);
284 return getRobotProprioception(qResult.
memory, robotName);
301 ARMARX_DEBUG <<
"Querying robot joint states for robot: `" << robotName
302 <<
"` on time interval [" << begin <<
"," << end <<
"]";
314 std::scoped_lock l(memoryReaderMutex);
325 return getRobotJointStates(qResult.
memory, robotName);
335 std::optional<PlatformState>
344 ARMARX_DEBUG <<
"Querying robot description for robot: " << robotName;
356 std::scoped_lock l(memoryReaderMutex);
367 return getRobotPlatformState(qResult.
memory, robotName);
377 std::optional<RobotState::Pose>
389 return result.transform.transform;
399 std::optional<RobotState>
401 const std::string& name)
const
406 .getProviderSegment(name);
410 if (providerSegment.
empty())
426 if (instance ==
nullptr)
437 template <
typename AronClass>
438 std::optional<AronClass>
446 return AronClass::FromAron(item.
data());
454 std::optional<armarx::armem::arondto::Proprioception>
456 const std::string& name)
const
463 std::optional<armarx::armem::arondto::Proprioception> proprioception;
478 return proprioception;
482 RobotReader::getRobotJointStates(
const armarx::armem::wm::Memory& memory,
483 const std::string& name)
const
489 const armem::wm::CoreSegment& coreSegment = memory
494 [&jointTrajectory](
const wm::Entity& entity)
497 [&](
const auto& snapshot)
499 if (not snapshot.hasInstance(0))
504 const auto& entityInstance = snapshot.getInstance(0);
506 const auto proprioception =
510 const armarx::armem::prop::arondto::Joints& joints = proprioception->joints;
512 jointTrajectory.emplace(entityInstance.id().timestamp, joints.position);
516 ARMARX_INFO <<
"Joint trajectory with " << jointTrajectory.size() <<
" elements";
518 return jointTrajectory;
522 std::optional<std::map<RobotReader::Hand, proprioception::ForceTorque>>
529 ARMARX_DEBUG <<
"Querying force torques description for robot: " << robotName;
541 std::scoped_lock l(memoryReaderMutex);
552 return getForceTorque(qResult.
memory, robotName);
563 std::optional<std::map<RobotReader::Hand, std::map<armem::Time, proprioception::ForceTorque>>>
572 ARMARX_DEBUG <<
"Querying force torques description for robot: " << robotName;
584 std::scoped_lock l(memoryReaderMutex);
595 return getForceTorques(qResult.
memory, robotName);
605 std::optional<std::map<RobotReader::Hand, exteroception::ToF>>
611 ARMARX_DEBUG <<
"Querying ToF data for robot: " << robotName;
623 std::scoped_lock l(memoryReaderMutex);
634 return getToF(qResult.
memory, robotName);
644 std::optional<PlatformState>
646 const std::string& name)
const
648 std::optional<PlatformState> platformState;
665 const auto proprioception =
669 platformState = PlatformState();
670 fromAron(proprioception->platform, platformState.value());
673 return platformState;
689 throw LocalException(
"Unknown hand name `" + name +
"`!");
692 std::map<RobotReader::Hand, proprioception::ForceTorque>
694 const std::string& name)
const
696 std::map<RobotReader::Hand, proprioception::ForceTorque> forceTorques;
713 const auto proprioception =
717 for (
const auto& [handName, dtoFt] : proprioception->forceTorque)
719 proprioception::ForceTorque forceTorque;
723 forceTorques.emplace(hand, forceTorque);
730 std::map<RobotReader::Hand, std::map<armem::Time, proprioception::ForceTorque>>
731 RobotReader::getForceTorques(
const armarx::armem::wm::Memory& memory,
732 const std::string& name)
const
734 std::map<RobotReader::Hand, std::map<armem::Time, proprioception::ForceTorque>>
738 const armem::wm::CoreSegment& coreSegment = memory
745 const auto proprioception =
750 for (
const auto& [handName, dtoFt] : proprioception->forceTorque)
752 proprioception::ForceTorque forceTorque;
756 forceTorques[
hand].emplace(entityInstance.
id().
timestamp, forceTorque);
763 std::map<RobotReader::Hand, exteroception::ToF>
764 RobotReader::getToF(
const armarx::armem::wm::Memory& memory,
const std::string& name)
const
766 std::map<RobotReader::Hand, exteroception::ToF> tofs;
769 const armem::wm::CoreSegment& coreSegment = memory
774 [&tofs](
const wm::Entity& entity)
784 const auto exteroception =
789 for (
const auto& [handName, dtoFt] : exteroception->tof)
791 ARMARX_DEBUG <<
"Processing ToF element for hand `" << handName <<
"`";
793 exteroception::ToF tof;
797 tofs.emplace(hand, tof);
804 std::optional<description::RobotDescription>
805 RobotReader::getRobotDescription(
const armarx::armem::wm::Memory& memory,
806 const std::string& name)
const
809 const armem::wm::ProviderSegment& providerSegment = memory
811 .getProviderSegment(name);
814 const armem::wm::EntityInstance* instance =
nullptr;
817 if (instance ==
nullptr)
819 ARMARX_VERBOSE <<
"No entity snapshots found in provider segment `" << name <<
"`";
826 std::vector<description::RobotDescription>
827 RobotReader::getRobotDescriptions(
const armarx::armem::wm::Memory& memory)
const
829 const armem::wm::CoreSegment& coreSegment =
832 std::vector<description::RobotDescription> descriptions;
837 if (
const std::optional<description::RobotDescription> desc =
840 descriptions.push_back(desc.value());
847 std::vector<description::RobotDescription>
865 if (not memoryReader)
867 ARMARX_WARNING <<
"Memory reader is null. Did you forget to call "
868 "RobotReader::connect() in onConnectComponent()?";
874 std::scoped_lock l(memoryReaderMutex);
884 return getRobotDescriptions(qResult.
memory);
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
static DateTime Now()
Current time on the virtual clock.
static void WaitFor(const Duration &duration)
Wait for a certain duration on the virtual clock.
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
bool forEachSnapshot(SnapshotFunctionT &&func)
const DataT & data() const
CoreSegmentT & getCoreSegment(const std::string &name)
The memory name system (MNS) client.
The query::Builder class provides a fluent-style specification of hierarchical queries.
QueryInput buildQueryInput() const
CoreSegmentSelector & coreSegments()
Start specifying core segments.
CoreSegmentSelector & withName(const std::string &name) override
ProviderSegmentSelector & providerSegments()
Start specifying provider segments.
EntitySelector & all() override
SnapshotSelector & snapshots()
Start specifying entity snapshots.
ProviderSegmentSelector & withName(const std::string &name) override
EntitySelector & entities()
Start specifying entities.
ProviderSegmentSelector & all() override
SnapshotSelector & beforeOrAtTime(Time timestamp)
SnapshotSelector & timeRange(Time min, Time max)
Indicates that a query to the Memory Name System failed.
std::optional< armarx::armem::arondto::Proprioception > queryProprioception(const std::string &robotName, const armem::Time ×tamp) const
std::map< armem::Time, RobotState::JointMap > JointTrajectory
std::vector< description::RobotDescription > queryDescriptions(const armem::Time ×tamp) const
std::optional<::armarx::armem::robot_state::localization::Transform > queryOdometryPose(const std::string &robotName, const armem::Time ×tamp) const
retrieve the robot's pose in the odometry frame.
virtual void connect(armem::client::MemoryNameSystem &memoryNameSystem)
bool synchronize(Robot &obj, const armem::Time ×tamp) const override
std::optional< RobotState > queryState(const std::string &robotName, const armem::Time ×tamp) const
std::optional< std::map< RobotReader::Hand, std::map< armem::Time, proprioception::ForceTorque > > > queryForceTorques(const std::string &robotName, const armem::Time &start, const armem::Time &end) const
std::optional< std::map< Hand, exteroception::ToF > > queryToF(const std::string &robotName, const armem::Time ×tamp) const
void setSleepAfterSyncFailure(const armem::Duration &duration)
void setSyncTimeout(const armem::Duration &duration)
JointTrajectory queryJointStates(const std::string &robotName, const armem::Time &begin, const armem::Time &end) const
armem::Duration syncTimeout
std::optional< description::RobotDescription > queryDescription(const std::string &name, const armem::Time ×tamp) const
std::optional< PlatformState > queryPlatformState(const std::string &robotName, const armem::Time ×tamp) const
std::optional< std::map< Hand, proprioception::ForceTorque > > queryForceTorque(const std::string &robotName, const armem::Time ×tamp) const
std::optional< RobotState > queryJointState(const std::string &robotName, const armem::Time ×tamp) const
virtual void registerPropertyDefinitions(::armarx::PropertyDefinitionsPtr &def)
std::optional< RobotState::Pose > queryGlobalPose(const std::string &robotName, const armem::Time ×tamp) const
armem::Duration sleepAfterFailure
std::optional< Robot > get(const std::string &name, const armem::Time ×tamp) const override
Client-side working memory core segment.
Client-side working entity instance.
Client-side working memory.
Client-side working memory provider segment.
A base class for aron exceptions.
std::int64_t toMicroSeconds() const
Returns the amount of microseconds.
Brief description of class memory.
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_CHECK_NONNEGATIVE(number)
Check whether number is nonnegative (>= 0).
#define ARMARX_INFO
The normal logging level.
#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.
#define ARMARX_VERBOSE
The logging level for verbose information.
const std::string descriptionCoreSegment
const std::string memoryName
const std::string robotRootNodeName
const std::string proprioceptionCoreSegment
const std::string exteroceptionCoreSegment
std::optional< description::RobotDescription > convertRobotDescription(const armem::wm::EntityInstance &instance)
std::optional< RobotState > convertRobotState(const armem::wm::EntityInstance &instance)
void fromAron(const arondto::ObjectInstance &dto, RobotState &bo)
RobotReader::Hand fromHandName(const std::string &name)
std::optional< AronClass > tryCast(const wm::EntityInstance &item)
armem::wm::EntityInstance EntityInstance
armarx::core::time::DateTime Time
armarx::core::time::Duration Duration
aron::cpp::AronGeneratedClass AronGeneratedClass
std::string GetHandledExceptionString()
std::string const OdometryFrame
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
bool forEachInstance(InstanceFunctionT &&func)
bool forEachEntity(FunctionT &&func)
auto & getLatestSnapshot(int snapshotIndex=0)
Retrieve the latest entity snapshot.
wm::Memory memory
The slice of the memory that matched the query.
description::RobotDescription description