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 /**
74 * @param referencedTime If given, receives the time the returned data actually refers to,
75 * which is the newest snapshot at or before `timestamp` and may be
76 * arbitrarily older than it.
77 */
78 std::optional<armarx::armem::arondto::Proprioception>
79 queryProprioception(const std::string& robotName,
81 armem::Time* referencedTime = nullptr) const;
82
83 using JointTrajectory = std::map<armem::Time, RobotState::JointMap>;
84
85 JointTrajectory queryJointStates(const std::string& robotName,
86 const armem::Time& begin,
87 const armem::Time& end) const;
88
89 std::optional<RobotState::Pose> queryGlobalPose(const std::string& robotName,
90 const armem::Time& timestamp) const;
91
92 std::optional<PlatformState> queryPlatformState(const std::string& robotName,
93 const armem::Time& timestamp) const;
94
95 void setSyncTimeout(const armem::Duration& duration);
96 void setSleepAfterSyncFailure(const armem::Duration& duration);
97
98 enum class Hand
99 {
102 };
103
104 std::optional<std::map<Hand, proprioception::ForceTorque>>
105 queryForceTorque(const std::string& robotName, const armem::Time& timestamp) const;
106
107 std::optional<
108 std::map<RobotReader::Hand, std::map<armem::Time, proprioception::ForceTorque>>>
109 queryForceTorques(const std::string& robotName,
110 const armem::Time& start,
111 const armem::Time& end) const;
112
113
114 std::optional<std::map<Hand, exteroception::ToF>>
115 queryToF(const std::string& robotName, const armem::Time& timestamp) const;
116
117 /**
118 * @brief retrieve the robot's pose in the odometry frame.
119 *
120 * This pose is an integration of the robot's platform velocity and undergoes a significant drift.
121 *
122 * @param description
123 * @param timestamp
124 * @return std::optional<RobotState::Pose>
125 */
126 std::optional<::armarx::armem::robot_state::localization::Transform>
127 queryOdometryPose(const std::string& robotName, const armem::Time& timestamp) const;
128
129 protected:
130 // by default, no timeout mechanism
133
134 private:
135 std::optional<RobotState> getRobotState(const armarx::armem::wm::Memory& memory,
136 const std::string& name) const;
137
138 std::optional<description::RobotDescription>
139 getRobotDescription(const armarx::armem::wm::Memory& memory, const std::string& name) const;
140
141 std::vector<description::RobotDescription>
142 getRobotDescriptions(const armarx::armem::wm::Memory& memory) const;
143
144 protected:
145 /// Protected rather than private so the referenced-time reporting can be exercised
146 /// directly: everything above it needs a live memory server, this needs only a wm::Memory.
147 std::optional<armarx::armem::arondto::Proprioception>
149 const std::string& name,
150 armem::Time* referencedTime = nullptr) const;
151
152 private:
153
154 JointTrajectory getRobotJointStates(const armarx::armem::wm::Memory& memory,
155 const std::string& name) const;
156
157 std::optional<PlatformState> getRobotPlatformState(const armarx::armem::wm::Memory& memory,
158 const std::string& name) const;
159
160 std::map<RobotReader::Hand, proprioception::ForceTorque>
161 getForceTorque(const armarx::armem::wm::Memory& memory, const std::string& name) const;
162
163
164 std::map<RobotReader::Hand, std::map<armem::Time, proprioception::ForceTorque>>
165 getForceTorques(const armarx::armem::wm::Memory& memory, const std::string& name) const;
166
167 std::map<RobotReader::Hand, exteroception::ToF>
168 getToF(const armarx::armem::wm::Memory& memory, const std::string& name) const;
169
170 struct Properties
171 {
172 } properties;
173
174 const std::string propertyPrefix = "mem.robot_state.";
175
176 armem::client::Reader memoryReader;
177 mutable std::mutex memoryReaderMutex;
178
180 };
181
182} // 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::map< armem::Time, RobotState::JointMap > JointTrajectory
Definition RobotReader.h:83
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< 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 &timestamp) const
std::optional< PlatformState > queryPlatformState(const std::string &robotName, const armem::Time &timestamp) const
std::optional< armarx::armem::arondto::Proprioception > queryProprioception(const std::string &robotName, const armem::Time &timestamp, armem::Time *referencedTime=nullptr) 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.