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;
47  RobotReader(const RobotReader&);
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;
58  Robot get(const description::RobotDescription& description,
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>
65  queryDescriptions(const armem::Time& timestamp) const;
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  {
93  Left,
94  Right
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
armarx::armem::robot_state::RobotReader::queryGlobalPose
std::optional< RobotState::Pose > queryGlobalPose(const std::string &robotName, const armem::Time &timestamp) const
Definition: RobotReader.cpp:378
armarx::armem::robot_state::RobotReader::queryJointState
std::optional< RobotState > queryJointState(const std::string &robotName, const armem::Time &timestamp) const
Definition: RobotReader.cpp:206
armarx::armem::client::Reader
Reads data from a memory server.
Definition: Reader.h:24
Reader.h
armarx::armem::robot_state::RobotReader::queryPlatformState
std::optional< PlatformState > queryPlatformState(const std::string &robotName, const armem::Time &timestamp) const
Definition: RobotReader.cpp:336
armarx::armem::robot_state::description::RobotDescription
Definition: types.h:44
TransformReader.h
armarx::armem::robot_state::RobotReader::setSyncTimeout
void setSyncTimeout(const armem::Duration &duration)
Definition: RobotReader.cpp:95
armarx::armem::robot_state::Robot
Definition: types.h:126
armarx::armem::robot_state::RobotReader::registerPropertyDefinitions
virtual void registerPropertyDefinitions(::armarx::PropertyDefinitionsPtr &def)
Definition: RobotReader.cpp:42
armarx::armem::robot_state::RobotReader::Hand
Hand
Definition: RobotReader.h:91
armarx::armem::robot_state::RobotReader::Hand::Right
@ Right
armarx::armem::robot_state
Definition: RobotStatePredictionClient.cpp:42
armarx::armem::robot_state::RobotReader::connect
virtual void connect(armem::client::MemoryNameSystem &memoryNameSystem)
Definition: RobotReader.cpp:48
armarx::memory
Brief description of class memory.
Definition: memory.h:39
armarx::armem::robot_state::RobotReader::queryForceTorques
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
Definition: RobotReader.cpp:566
armarx::armem::robot_state::client::localization::TransformReader
Brief description of class ExampleClient.
Definition: TransformReader.h:43
armarx::armem::robot_state::RobotReader::Hand::Left
@ Left
armarx::armem::robot_state::RobotReader::queryForceTorque
std::optional< std::map< Hand, proprioception::ForceTorque > > queryForceTorque(const std::string &robotName, const armem::Time &timestamp) const
Definition: RobotReader.cpp:524
armarx::armem::robot_state::RobotReader::setSleepAfterSyncFailure
void setSleepAfterSyncFailure(const armem::Duration &duration)
Definition: RobotReader.cpp:101
armarx::armem::wm::Memory
Client-side working memory.
Definition: memory_definitions.h:133
armarx::armem::robot_state::RobotReader::queryDescription
std::optional< description::RobotDescription > queryDescription(const std::string &name, const armem::Time &timestamp) const
Definition: RobotReader.cpp:138
armarx::armem::robot_state::RobotReader
The RobotReader class.
Definition: RobotReader.h:43
types.h
armarx::armem::robot_state::RobotReader::synchronize
bool synchronize(Robot &obj, const armem::Time &timestamp) const override
Definition: RobotReader.cpp:108
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::armem::robot_state::RobotReader::queryJointStates
JointTrajectory queryJointStates(const std::string &robotName, const armem::Time &begin, const armem::Time &end) const
Definition: RobotReader.cpp:295
armarx::armem::robot_state::RobotReader::~RobotReader
virtual ~RobotReader()=default
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::armem::robot_state::RobotReader::queryProprioception
std::optional< armarx::armem::arondto::Proprioception > queryProprioception(const std::string &robotName, const armem::Time &timestamp) const
Definition: RobotReader.cpp:253
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:17
armarx::armem::robot_state::ReaderInterface
Definition: ReaderInterface.h:10
armarx::armem::robot_state::RobotReader::queryDescriptions
std::vector< description::RobotDescription > queryDescriptions(const armem::Time &timestamp) const
Definition: RobotReader.cpp:850
armarx::armem::robot_state::RobotReader::get
std::optional< Robot > get(const std::string &name, const armem::Time &timestamp) const override
Definition: RobotReader.cpp:67
Time.h
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:69
armarx::armem::robot_state::RobotReader::queryToF
std::optional< std::map< Hand, exteroception::ToF > > queryToF(const std::string &robotName, const armem::Time &timestamp) const
Definition: RobotReader.cpp:608
armarx::armem::robot_state::RobotReader::JointTrajectory
std::map< armem::Time, RobotState::JointMap > JointTrajectory
Definition: RobotReader.h:76
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_state::RobotReader::queryState
std::optional< RobotState > queryState(const std::string &robotName, const armem::Time &timestamp) const
Definition: RobotReader.cpp:186
armarx::armem::robot_state::RobotReader::RobotReader
RobotReader()=default
armarx::armem::robot_state::RobotReader::sleepAfterFailure
armem::Duration sleepAfterFailure
Definition: RobotReader.h:125
armarx::armem::robot_state::RobotReader::queryOdometryPose
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.
Definition: RobotReader.cpp:226
armarx::armem::robot_state::RobotReader::syncTimeout
armem::Duration syncTimeout
Definition: RobotReader.h:124
ReaderInterface.h