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";
140 robot.
config = std::move(*state);
145 std::optional<description::RobotDescription>
164 if (not memoryReader)
166 ARMARX_WARNING <<
"Memory reader is null. Did you forget to call "
167 "RobotReader::connect() in onConnectComponent()?";
173 std::scoped_lock l(memoryReaderMutex);
183 return getRobotDescription(qResult.
memory, name);
193 std::optional<RobotState>
203 ARMARX_VERBOSE <<
"Failed to query global pose for robot " << robotName;
206 robotState->globalPose = *globalPose;
212 std::optional<RobotState>
222 ARMARX_VERBOSE <<
"Failed to query proprioception for robot '" << robotName <<
"'.";
230 return RobotState{.timestamp = referencedTime,
231 .globalPose = RobotState::Pose::Identity(),
232 .jointMap = jointMap,
236 std::optional<::armarx::armem::robot_state::localization::Transform>
248 const auto result = transformReader.lookupTransform(
query);
253 return result.transform;
262 std::optional<armarx::armem::arondto::Proprioception>
272 ARMARX_DEBUG <<
"Querying robot description for robot: " << robotName;
284 std::scoped_lock l(memoryReaderMutex);
312 ARMARX_DEBUG <<
"Querying robot joint states for robot: `" << robotName
313 <<
"` on time interval [" << begin <<
"," << end <<
"]";
325 std::scoped_lock l(memoryReaderMutex);
336 return getRobotJointStates(qResult.
memory, robotName);
346 std::optional<PlatformState>
355 ARMARX_DEBUG <<
"Querying robot description for robot: " << robotName;
367 std::scoped_lock l(memoryReaderMutex);
378 return getRobotPlatformState(qResult.
memory, robotName);
388 std::optional<RobotState::Pose>
400 return result.transform.transform;
410 std::optional<RobotState>
412 const std::string& name)
const
417 .getProviderSegment(name);
421 if (providerSegment.
empty())
437 if (instance ==
nullptr)
448 template <
typename AronClass>
449 std::optional<AronClass>
457 return AronClass::FromAron(item.
data());
465 std::optional<armarx::armem::arondto::Proprioception>
467 const std::string& name,
475 std::optional<armarx::armem::arondto::Proprioception>
proprioception;
481 if (not snapshot.hasInstance(0))
486 const auto& entityInstance = snapshot.getInstance(0);
492 *referencedTime = entityInstance.metadata().referencedTime;
501 const std::string& name)
const
515 [&](
const auto& snapshot)
517 if (not snapshot.hasInstance(0))
522 const auto& entityInstance = snapshot.getInstance(0);
524 const auto proprioception =
528 const armarx::armem::prop::arondto::Joints& joints = proprioception->joints;
530 jointTrajectory.emplace(entityInstance.id().timestamp, joints.position);
534 ARMARX_INFO <<
"Joint trajectory with " << jointTrajectory.size() <<
" elements";
536 return jointTrajectory;
540 std::optional<std::map<RobotReader::Hand, proprioception::ForceTorque>>
547 ARMARX_DEBUG <<
"Querying force torques description for robot: " << robotName;
559 std::scoped_lock l(memoryReaderMutex);
570 return getForceTorque(qResult.
memory, robotName);
581 std::optional<std::map<RobotReader::Hand, std::map<armem::Time, proprioception::ForceTorque>>>
590 ARMARX_DEBUG <<
"Querying force torques description for robot: " << robotName;
602 std::scoped_lock l(memoryReaderMutex);
613 return getForceTorques(qResult.
memory, robotName);
623 std::optional<std::map<RobotReader::Hand, exteroception::ToF>>
629 ARMARX_DEBUG <<
"Querying ToF data for robot: " << robotName;
641 std::scoped_lock l(memoryReaderMutex);
652 return getToF(qResult.
memory, robotName);
662 std::optional<PlatformState>
664 const std::string& name)
const
666 std::optional<PlatformState> platformState;
683 const auto proprioception =
687 platformState = PlatformState();
688 fromAron(proprioception->platform, platformState.value());
691 return platformState;
707 throw LocalException(
"Unknown hand name `" + name +
"`!");
710 std::map<RobotReader::Hand, proprioception::ForceTorque>
712 const std::string& name)
const
714 std::map<RobotReader::Hand, proprioception::ForceTorque> forceTorques;
731 const auto proprioception =
735 for (
const auto& [handName, dtoFt] : proprioception->forceTorque)
737 proprioception::ForceTorque forceTorque;
741 forceTorques.emplace(hand, forceTorque);
748 std::map<RobotReader::Hand, std::map<armem::Time, proprioception::ForceTorque>>
749 RobotReader::getForceTorques(
const armarx::armem::wm::Memory& memory,
750 const std::string& name)
const
752 std::map<RobotReader::Hand, std::map<armem::Time, proprioception::ForceTorque>>
756 const armem::wm::CoreSegment& coreSegment = memory
763 const auto proprioception =
768 for (
const auto& [handName, dtoFt] : proprioception->forceTorque)
770 proprioception::ForceTorque forceTorque;
774 forceTorques[
hand].emplace(entityInstance.
id().
timestamp, forceTorque);
781 std::map<RobotReader::Hand, exteroception::ToF>
782 RobotReader::getToF(
const armarx::armem::wm::Memory& memory,
const std::string& name)
const
784 std::map<RobotReader::Hand, exteroception::ToF> tofs;
787 const armem::wm::CoreSegment& coreSegment = memory
792 [&tofs](
const wm::Entity& entity)
802 const auto exteroception =
807 for (
const auto& [handName, dtoFt] : exteroception->tof)
809 ARMARX_DEBUG <<
"Processing ToF element for hand `" << handName <<
"`";
811 exteroception::ToF tof;
815 tofs.emplace(hand, tof);
822 std::optional<description::RobotDescription>
823 RobotReader::getRobotDescription(
const armarx::armem::wm::Memory& memory,
824 const std::string& name)
const
827 const armem::wm::ProviderSegment& providerSegment = memory
829 .getProviderSegment(name);
832 const armem::wm::EntityInstance* instance =
nullptr;
835 if (instance ==
nullptr)
837 ARMARX_VERBOSE <<
"No entity snapshots found in provider segment `" << name <<
"`";
844 std::vector<description::RobotDescription>
845 RobotReader::getRobotDescriptions(
const armarx::armem::wm::Memory& memory)
const
847 const armem::wm::CoreSegment& coreSegment =
850 std::vector<description::RobotDescription> descriptions;
855 if (
const std::optional<description::RobotDescription> desc =
858 descriptions.push_back(desc.value());
865 std::vector<description::RobotDescription>
883 if (not memoryReader)
885 ARMARX_WARNING <<
"Memory reader is null. Did you forget to call "
886 "RobotReader::connect() in onConnectComponent()?";
892 std::scoped_lock l(memoryReaderMutex);
902 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::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< armarx::armem::arondto::Proprioception > getRobotProprioception(const armarx::armem::wm::Memory &memory, const std::string &name, armem::Time *referencedTime=nullptr) const
Protected rather than private so the referenced-time reporting can be exercised directly: everything ...
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< armarx::armem::arondto::Proprioception > queryProprioception(const std::string &robotName, const armem::Time ×tamp, armem::Time *referencedTime=nullptr) 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