RobotReader.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @author Fabian Reister ( fabian dot reister at kit dot edu )
17 * @date 2021
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
24#include <mutex>
25#include <optional>
26#include <vector>
27
34
36{
37 /**
38 * @brief The RobotReader class.
39 *
40 * The purpose of this class is to synchronize the armem data structure armem::Robot
41 * with the memory.
42 */
43 class RobotReader : virtual public ReaderInterface
44 {
45 public:
46 RobotReader() = default;
48 virtual ~RobotReader() = default;
49
50 virtual void connect(armem::client::MemoryNameSystem& memoryNameSystem);
51
53
54 [[nodiscard]] bool synchronize(Robot& obj, const armem::Time& timestamp) const override;
55
56 std::optional<Robot> get(const std::string& name,
57 const armem::Time& timestamp) const override;
59 const armem::Time& timestamp) const override;
60
61 std::optional<description::RobotDescription>
62 queryDescription(const std::string& name, const armem::Time& timestamp) const;
63
64 std::vector<description::RobotDescription>
66
67 std::optional<RobotState> queryState(const std::string& robotName,
68 const armem::Time& timestamp) const;
69
70 std::optional<RobotState> queryJointState(const std::string& robotName,
71 const armem::Time& timestamp) const;
72
73 std::optional<armarx::armem::arondto::Proprioception>
74 queryProprioception(const std::string& robotName, const armem::Time& timestamp) const;
75
76 using JointTrajectory = std::map<armem::Time, RobotState::JointMap>;
77
78 JointTrajectory queryJointStates(const std::string& robotName,
79 const armem::Time& begin,
80 const armem::Time& end) const;
81
82 std::optional<RobotState::Pose> queryGlobalPose(const std::string& robotName,
83 const armem::Time& timestamp) const;
84
85 std::optional<PlatformState> queryPlatformState(const std::string& robotName,
86 const armem::Time& timestamp) const;
87
88 void setSyncTimeout(const armem::Duration& duration);
89 void setSleepAfterSyncFailure(const armem::Duration& duration);
90
91 enum class Hand
92 {
95 };
96
97 std::optional<std::map<Hand, proprioception::ForceTorque>>
98 queryForceTorque(const std::string& robotName, const armem::Time& timestamp) const;
99
100 std::optional<
101 std::map<RobotReader::Hand, std::map<armem::Time, proprioception::ForceTorque>>>
102 queryForceTorques(const std::string& robotName,
103 const armem::Time& start,
104 const armem::Time& end) const;
105
106
107 std::optional<std::map<Hand, exteroception::ToF>>
108 queryToF(const std::string& robotName, const armem::Time& timestamp) const;
109
110 /**
111 * @brief retrieve the robot's pose in the odometry frame.
112 *
113 * This pose is an integration of the robot's platform velocity and undergoes a significant drift.
114 *
115 * @param description
116 * @param timestamp
117 * @return std::optional<RobotState::Pose>
118 */
119 std::optional<::armarx::armem::robot_state::localization::Transform>
120 queryOdometryPose(const std::string& robotName, const armem::Time& timestamp) const;
121
122 protected:
123 // by default, no timeout mechanism
126
127 private:
128 std::optional<RobotState> getRobotState(const armarx::armem::wm::Memory& memory,
129 const std::string& name) const;
130
131 std::optional<description::RobotDescription>
132 getRobotDescription(const armarx::armem::wm::Memory& memory, const std::string& name) const;
133
134 std::vector<description::RobotDescription>
135 getRobotDescriptions(const armarx::armem::wm::Memory& memory) const;
136
137 std::optional<armarx::armem::arondto::Proprioception>
138 getRobotProprioception(const armarx::armem::wm::Memory& memory,
139 const std::string& name) const;
140
141 JointTrajectory getRobotJointStates(const armarx::armem::wm::Memory& memory,
142 const std::string& name) const;
143
144 std::optional<PlatformState> getRobotPlatformState(const armarx::armem::wm::Memory& memory,
145 const std::string& name) const;
146
147 std::map<RobotReader::Hand, proprioception::ForceTorque>
148 getForceTorque(const armarx::armem::wm::Memory& memory, const std::string& name) const;
149
150
151 std::map<RobotReader::Hand, std::map<armem::Time, proprioception::ForceTorque>>
152 getForceTorques(const armarx::armem::wm::Memory& memory, const std::string& name) const;
153
154 std::map<RobotReader::Hand, exteroception::ToF>
155 getToF(const armarx::armem::wm::Memory& memory, const std::string& name) const;
156
157 struct Properties
158 {
159 } properties;
160
161 const std::string propertyPrefix = "mem.robot_state.";
162
163 armem::client::Reader memoryReader;
164 mutable std::mutex memoryReaderMutex;
165
167 };
168
169} // namespace armarx::armem::robot_state
std::string timestamp()
The memory name system (MNS) client.
Reads data from a memory server.
Definition Reader.h:25
std::optional< armarx::armem::arondto::Proprioception > queryProprioception(const std::string &robotName, const armem::Time &timestamp) const
std::map< armem::Time, RobotState::JointMap > JointTrajectory
Definition RobotReader.h:76
std::vector< description::RobotDescription > queryDescriptions(const armem::Time &timestamp) const
std::optional<::armarx::armem::robot_state::localization::Transform > queryOdometryPose(const std::string &robotName, const armem::Time &timestamp) const
retrieve the robot's pose in the odometry frame.
virtual void connect(armem::client::MemoryNameSystem &memoryNameSystem)
bool synchronize(Robot &obj, const armem::Time &timestamp) const override
std::optional< RobotState > queryState(const std::string &robotName, const armem::Time &timestamp) 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 &timestamp) 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
std::optional< description::RobotDescription > queryDescription(const std::string &name, const armem::Time &timestamp) const
std::optional< PlatformState > queryPlatformState(const std::string &robotName, const armem::Time &timestamp) const
std::optional< std::map< Hand, proprioception::ForceTorque > > queryForceTorque(const std::string &robotName, const armem::Time &timestamp) const
std::optional< RobotState > queryJointState(const std::string &robotName, const armem::Time &timestamp) const
virtual void registerPropertyDefinitions(::armarx::PropertyDefinitionsPtr &def)
std::optional< RobotState::Pose > queryGlobalPose(const std::string &robotName, const armem::Time &timestamp) const
std::optional< Robot > get(const std::string &name, const armem::Time &timestamp) const override
Client-side working memory.
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition Duration.cpp:24
Brief description of class memory.
Definition memory.h:39
armarx::core::time::DateTime Time
armarx::core::time::Duration Duration
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.