VirtualRobotReader.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 <string>
25 
26 #include <VirtualRobot/VirtualRobot.h>
27 #include <VirtualRobot/XML/RobotIO.h>
28 
30 
31 #include "RobotReader.h"
32 
34 {
35  /**
36  * @brief The VirtualRobotReader class.
37  *robot
38  * The aim of this class is to obtain a virtual robot instance and synchronize it
39  * with the data (joint positions, global pose, ...) stored in the working memory.
40  *
41  * This is only a lightweight wrapper of @see RobotReader for Simox's VirtualRobot class.
42  */
43  class VirtualRobotReader : virtual public RobotReader
44  {
45  public:
47 
48  ~VirtualRobotReader() override = default;
49 
50  /**
51  * @brief Synchronize both the platform pose and the joint values of a virtual robot,
52  * according to the robot state memory for a certain point in time.
53  * @param robot whose platform pose and joint values to modify
54  * @param timestamp for which to synchronize
55  * @return whether synchronization was successful
56  */
57  [[nodiscard]] bool synchronizeRobot(VirtualRobot::Robot& robot,
58  const armem::Time& timestamp) const;
59 
60  /**
61  * @brief Synchronize only the joint values of a virtual robot,
62  * according to the robot state memory for a certain point in time.
63  * @param robot whose joint values to modify
64  * @param timestamp for which to synchronize
65  * @return whether synchronization was successful
66  */
67  [[nodiscard]] bool synchronizeRobotJoints(VirtualRobot::Robot& robot,
68  const armem::Time& timestamp) const;
69 
70  /**
71  * @brief Synchronize only the platform pose of a virtual robot,
72  * according to the robot state memory for a certain point in time.
73  * @param robot whose platform pose and joint values to modify
74  * @param timestamp for which to synchronize
75  * @return whether synchronization was successful
76  */
77  [[nodiscard]] bool synchronizeRobotPose(VirtualRobot::Robot& robot,
78  const armem::Time& timestamp) const;
79 
80  [[nodiscard]] VirtualRobot::RobotPtr
81  getRobot(const std::string& name,
83  const VirtualRobot::RobotIO::RobotDescription& loadMode =
84  VirtualRobot::RobotIO::RobotDescription::eStructure);
85 
86  [[deprecated(
87  "Use getRobot() and synchronizeRobot() instead. This method does two things "
88  "(getRobot() and synchronizeRobot()) and is not recommended as we cannot differentiate "
89  "failure cases, e.g. we might be able to obtain the robot model but cannot synchronize "
90  "it. Also, if `blocking` is enabled, this method will block indefinitely if the robot "
91  "is not available.")]]
92  [[nodiscard]] VirtualRobot::RobotPtr
93  getSynchronizedRobot(const std::string& name,
94  const VirtualRobot::RobotIO::RobotDescription& loadMode =
95  VirtualRobot::RobotIO::RobotDescription::eStructure,
96  bool blocking = true);
97 
98  [[deprecated(
99  "Use getRobot() and synchronizeRobot() instead. This method does two things "
100  "(getRobot() and synchronizeRobot()) and is not recommended as we cannot differentiate "
101  "failure cases, e.g. we might be able to obtain the robot model but cannot synchronize "
102  "it. Also, if `blocking` is enabled, this method will block indefinitely if the robot "
103  "is not available.")]]
104  [[nodiscard]] VirtualRobot::RobotPtr
105  getSynchronizedRobot(const std::string& name,
106  const armem::Time& timestamp,
107  const VirtualRobot::RobotIO::RobotDescription& loadMode =
108  VirtualRobot::RobotIO::RobotDescription::eStructure,
109  bool blocking = true);
110 
111  /**
112  @brief In contrast to getRobot(), this function will retry to query the robot until it exists.
113  */
114  [[nodiscard]] VirtualRobot::RobotPtr
115  getRobotWaiting(const std::string& name,
117  const VirtualRobot::RobotIO::RobotDescription& loadMode =
118  VirtualRobot::RobotIO::RobotDescription::eStructure);
119 
120  private:
121  [[nodiscard]] VirtualRobot::RobotPtr
122  _getSynchronizedRobot(const std::string& name,
124  const VirtualRobot::RobotIO::RobotDescription& loadMode =
125  VirtualRobot::RobotIO::RobotDescription::eStructure,
126  bool blocking = true);
127  };
128 
129 } // namespace armarx::armem::robot_state
armarx::armem::robot_state::VirtualRobotReader
The VirtualRobotReader class.
Definition: VirtualRobotReader.h:43
armarx::armem::robot_state::VirtualRobotReader::getRobot
VirtualRobot::RobotPtr getRobot(const std::string &name, const armem::Time &timestamp=armem::Time::Invalid(), const VirtualRobot::RobotIO::RobotDescription &loadMode=VirtualRobot::RobotIO::RobotDescription::eStructure)
Definition: VirtualRobotReader.cpp:79
armarx::armem::robot_state::VirtualRobotReader::~VirtualRobotReader
~VirtualRobotReader() override=default
forward_declarations.h
armarx::armem::robot_state
Definition: RobotStatePredictionClient.cpp:41
armarx::armem::robot_state::VirtualRobotReader::synchronizeRobot
bool synchronizeRobot(VirtualRobot::Robot &robot, const armem::Time &timestamp) const
Synchronize both the platform pose and the joint values of a virtual robot, according to the robot st...
Definition: VirtualRobotReader.cpp:26
armarx::armem::robot_state::VirtualRobotReader::synchronizeRobotPose
bool synchronizeRobotPose(VirtualRobot::Robot &robot, const armem::Time &timestamp) const
Synchronize only the platform pose of a virtual robot, according to the robot state memory for a cert...
Definition: VirtualRobotReader.cpp:61
armarx::armem::human::Robot
@ Robot
Definition: util.h:17
armarx::armem::robot_state::VirtualRobotReader::getRobotWaiting
VirtualRobot::RobotPtr getRobotWaiting(const std::string &name, const armem::Time &timestamp=armem::Time::Invalid(), const VirtualRobot::RobotIO::RobotDescription &loadMode=VirtualRobot::RobotIO::RobotDescription::eStructure)
In contrast to getRobot(), this function will retry to query the robot until it exists.
Definition: VirtualRobotReader.cpp:110
timestamp
std::string timestamp()
Definition: CartographerAdapter.cpp:85
armarx::armem::robot_state::VirtualRobotReader::synchronizeRobotJoints
bool synchronizeRobotJoints(VirtualRobot::Robot &robot, const armem::Time &timestamp) const
Synchronize only the joint values of a virtual robot, according to the robot state memory for a certa...
Definition: VirtualRobotReader.cpp:44
RobotReader.h
armarx::armem::robot_state::VirtualRobotReader::getSynchronizedRobot
VirtualRobot::RobotPtr getSynchronizedRobot(const std::string &name, const VirtualRobot::RobotIO::RobotDescription &loadMode=VirtualRobot::RobotIO::RobotDescription::eStructure, bool blocking=true)
armarx::armem::robot_state::RobotReader
The RobotReader class.
Definition: RobotReader.h:43
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::armem::robot_state::RobotReader::RobotReader
RobotReader()=default
armarx::core::time::DateTime::Invalid
static DateTime Invalid()
Definition: DateTime.cpp:57
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19