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 robot::ReaderInterface
44  {
45  public:
46  RobotReader() = default;
47  RobotReader(const RobotReader&);
48  virtual ~RobotReader() = default;
49 
50  virtual void connect(armem::client::MemoryNameSystem& memoryNameSystem);
51 
53 
54  [[nodiscard]] bool synchronize(robot::Robot& obj,
55  const armem::Time& timestamp) const override;
56 
57  std::optional<robot::Robot> get(const std::string& name,
58  const armem::Time& timestamp) const override;
59  robot::Robot get(const robot::RobotDescription& description,
60  const armem::Time& timestamp) const override;
61 
62  std::optional<robot::RobotDescription> queryDescription(const std::string& name,
63  const armem::Time& timestamp) const;
64 
65  std::vector<robot::RobotDescription> queryDescriptions(const armem::Time& timestamp) const;
66 
67  std::optional<robot::RobotState> queryState(const robot::RobotDescription& description,
68  const armem::Time& timestamp) const;
69 
70  std::optional<armarx::armem::arondto::Proprioception>
72  const armem::Time& timestamp) const;
73 
74  using JointTrajectory = std::map<armem::Time, robot::RobotState::JointMap>;
75 
77  const armem::Time& begin,
78  const armem::Time& end) const;
79 
80  std::optional<robot::RobotState::Pose>
81  queryGlobalPose(const robot::RobotDescription& description,
82  const armem::Time& timestamp) const;
83 
84  std::optional<robot::PlatformState>
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  {
93  Left,
94  Right
95  };
96 
97  std::optional<std::map<Hand, robot::ForceTorque>>
98  queryForceTorque(const robot::RobotDescription& description,
99  const armem::Time& timestamp) const;
100 
101  std::optional<std::map<RobotReader::Hand, std::map<armem::Time, robot::ForceTorque>>>
102  queryForceTorques(const robot::RobotDescription& description,
103  const armem::Time& start,
104  const armem::Time& end) const;
105 
106 
107  std::optional<std::map<Hand, robot::ToFArray>>
108  queryToF(const robot::RobotDescription& description, 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<robot::RobotState::Pose>
118  */
119  std::optional<::armarx::armem::robot_state::Transform>
120  queryOdometryPose(const robot::RobotDescription& description,
121  const armem::Time& timestamp) const;
122 
123  protected:
124  // by default, no timeout mechanism
127 
128  private:
129  std::optional<robot::RobotState> getRobotState(const armarx::armem::wm::Memory& memory,
130  const std::string& name) const;
131 
132  std::optional<robot::RobotDescription>
133  getRobotDescription(const armarx::armem::wm::Memory& memory, const std::string& name) const;
134 
135  std::vector<robot::RobotDescription>
136  getRobotDescriptions(const armarx::armem::wm::Memory& memory) const;
137 
138  std::optional<armarx::armem::arondto::Proprioception>
139  getRobotProprioception(const armarx::armem::wm::Memory& memory,
140  const std::string& name) const;
141 
142  JointTrajectory getRobotJointStates(const armarx::armem::wm::Memory& memory,
143  const std::string& name) const;
144 
145  std::optional<robot::PlatformState>
146  getRobotPlatformState(const armarx::armem::wm::Memory& memory,
147  const std::string& name) const;
148 
149  std::map<RobotReader::Hand, robot::ForceTorque>
150  getForceTorque(const armarx::armem::wm::Memory& memory, const std::string& name) const;
151 
152 
153  std::map<RobotReader::Hand, std::map<armem::Time, robot::ForceTorque>>
154  getForceTorques(const armarx::armem::wm::Memory& memory, const std::string& name) const;
155 
156  std::map<RobotReader::Hand, robot::ToFArray> getToF(const armarx::armem::wm::Memory& memory,
157  const std::string& name) const;
158 
159  struct Properties
160  {
161  } properties;
162 
163  const std::string propertyPrefix = "mem.robot_state.";
164 
165  armem::client::Reader memoryReader;
166  mutable std::mutex memoryReaderMutex;
167 
169  };
170 
171 } // namespace armarx::armem::robot_state
armarx::armem::robot_state::RobotReader::queryForceTorque
std::optional< std::map< Hand, robot::ForceTorque > > queryForceTorque(const robot::RobotDescription &description, const armem::Time &timestamp) const
Definition: RobotReader.cpp:511
armarx::armem::client::Reader
Reads data from a memory server.
Definition: Reader.h:24
armarx::armem::robot_state::RobotReader::queryProprioception
std::optional< armarx::armem::arondto::Proprioception > queryProprioception(const robot::RobotDescription &description, const armem::Time &timestamp) const
Definition: RobotReader.cpp:240
Reader.h
armarx::armem::robot_state::RobotReader::queryGlobalPose
std::optional< robot::RobotState::Pose > queryGlobalPose(const robot::RobotDescription &description, const armem::Time &timestamp) const
Definition: RobotReader.cpp:365
armarx::armem::robot_state::RobotReader::synchronize
bool synchronize(robot::Robot &obj, const armem::Time &timestamp) const override
Definition: RobotReader.cpp:108
TransformReader.h
armarx::armem::robot_state::RobotReader::setSyncTimeout
void setSyncTimeout(const armem::Duration &duration)
Definition: RobotReader.cpp:95
armarx::armem::robot::Robot
Definition: types.h:68
armarx::armem::robot_state::RobotReader::registerPropertyDefinitions
virtual void registerPropertyDefinitions(::armarx::PropertyDefinitionsPtr &def)
Definition: RobotReader.cpp:43
armarx::armem::robot_state::RobotReader::Hand
Hand
Definition: RobotReader.h:91
armarx::armem::robot_state::RobotReader::Hand::Right
@ Right
interfaces.h
armarx::armem::robot_state::RobotReader::queryDescription
std::optional< robot::RobotDescription > queryDescription(const std::string &name, const armem::Time &timestamp) const
Definition: RobotReader.cpp:138
armarx::armem::robot_state
Definition: RobotStatePredictionClient.cpp:42
armarx::armem::robot_state::RobotReader::connect
virtual void connect(armem::client::MemoryNameSystem &memoryNameSystem)
Definition: RobotReader.cpp:49
armarx::armem::robot_state::RobotReader::queryOdometryPose
std::optional<::armarx::armem::robot_state::Transform > queryOdometryPose(const robot::RobotDescription &description, const armem::Time &timestamp) const
retrieve the robot's pose in the odometry frame.
Definition: RobotReader.cpp:213
armarx::memory
Brief description of class memory.
Definition: memory.h:39
armarx::armem::robot::RobotDescription
Definition: types.h:17
armarx::armem::robot_state::RobotReader::JointTrajectory
std::map< armem::Time, robot::RobotState::JointMap > JointTrajectory
Definition: RobotReader.h:74
armarx::armem::robot_state::RobotReader::Hand::Left
@ Left
armarx::armem::robot_state::RobotReader::setSleepAfterSyncFailure
void setSleepAfterSyncFailure(const armem::Duration &duration)
Definition: RobotReader.cpp:101
armarx::armem::robot_state::RobotReader::get
std::optional< robot::Robot > get(const std::string &name, const armem::Time &timestamp) const override
Definition: RobotReader.cpp:68
armarx::armem::wm::Memory
Client-side working memory.
Definition: memory_definitions.h:133
armarx::armem::robot_state::RobotReader::queryPlatformState
std::optional< robot::PlatformState > queryPlatformState(const robot::RobotDescription &description, const armem::Time &timestamp) const
Definition: RobotReader.cpp:323
armarx::armem::robot_state::RobotReader
The RobotReader class.
Definition: RobotReader.h:43
armarx::armem::client::robot_state::localization::TransformReader
Brief description of class ExampleClient.
Definition: TransformReader.h:43
armarx::armem::robot_state::RobotReader::queryToF
std::optional< std::map< Hand, robot::ToFArray > > queryToF(const robot::RobotDescription &description, const armem::Time &timestamp) const
Definition: RobotReader.cpp:595
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::armem::robot_state::RobotReader::~RobotReader
virtual ~RobotReader()=default
armarx::armem::robot_state::RobotReader::queryJointStates
JointTrajectory queryJointStates(const robot::RobotDescription &description, const armem::Time &begin, const armem::Time &end) const
Definition: RobotReader.cpp:282
IceUtil::Handle< class PropertyDefinitionContainer >
types.h
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:17
Time.h
armarx::armem::robot_state::RobotReader::queryDescriptions
std::vector< robot::RobotDescription > queryDescriptions(const armem::Time &timestamp) const
Definition: RobotReader.cpp:837
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:69
armarx::armem::robot_state::RobotReader::queryState
std::optional< robot::RobotState > queryState(const robot::RobotDescription &description, const armem::Time &timestamp) const
Definition: RobotReader.cpp:186
MemoryNameSystem.h
armarx::core::time::Duration::MicroSeconds
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition: Duration.cpp:27
armarx::armem::robot::ReaderInterface
Definition: interfaces.h:10
armarx::armem::robot_state::RobotReader::RobotReader
RobotReader()=default
armarx::armem::robot_state::RobotReader::sleepAfterFailure
armem::Duration sleepAfterFailure
Definition: RobotReader.h:126
armarx::armem::robot_state::RobotReader::queryForceTorques
std::optional< std::map< RobotReader::Hand, std::map< armem::Time, robot::ForceTorque > > > queryForceTorques(const robot::RobotDescription &description, const armem::Time &start, const armem::Time &end) const
Definition: RobotReader.cpp:553
armarx::armem::robot_state::RobotReader::syncTimeout
armem::Duration syncTimeout
Definition: RobotReader.h:125