RobotStateComponentPlugin.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  * @package RobotAPI::ArmarXObjects::RobotAPIComponentPlugins
17  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * @date 2019
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <mutex>
26 
27 #include <VirtualRobot/VirtualRobot.h>
28 #include <VirtualRobot/XML/RobotIO.h>
29 
31 
32 #include <RobotAPI/interface/core/RobotState.h>
35 
36 namespace armarx::plugins
37 {
38  /**
39  * @defgroup Library-RobotAPIComponentPlugins RobotAPIComponentPlugins
40  * @ingroup RobotAPI
41  * A description of the library RobotAPIComponentPlugins.
42  */
43 
44  /**
45  * @class RobotStateComponentPlugin
46  * @ingroup Library-RobotAPIComponentPlugins
47  * @brief Brief description of class RobotAPIComponentPlugins.
48  *
49  * Detailed description of class RobotAPIComponentPlugins.
50  */
52  {
53  public:
54  struct RobotData;
55  using ComponentPlugin::ComponentPlugin;
56 
57  void setRobotStateComponentName(const std::string& name);
59  const std::string& getRobotStateComponentName() const;
60  void deactivate();
61  //get / add
62  public:
63  bool hasRobot(const std::string& id) const;
64 
65  VirtualRobot::RobotPtr addRobot(const std::string& id,
66  const VirtualRobot::RobotPtr& robot,
67  const VirtualRobot::RobotNodeSetPtr& rns = {},
68  const VirtualRobot::RobotNodePtr& node = {});
69  VirtualRobot::RobotPtr addRobot(const std::string& id,
70  const VirtualRobot::RobotPtr& robot,
71  const std::string& rnsName,
72  const std::string& nodeName = "");
73  VirtualRobot::RobotPtr addRobot(const std::string& id,
74  VirtualRobot::RobotIO::RobotDescription loadMode,
75  const std::string& rnsName = "",
76  const std::string& nodeName = "");
77  VirtualRobot::RobotPtr addRobot(const std::string& id,
78  const std::string& filename,
79  const Ice::StringSeq packages,
80  VirtualRobot::RobotIO::RobotDescription loadMode,
81  const std::string& rnsName = "",
82  const std::string& nodeName = "");
83 
84  VirtualRobot::RobotPtr getRobot(const std::string& id) const;
85  RobotData getRobotData(const std::string& id) const;
86  void setRobotRNSAndNode(const std::string& id,
87  const std::string& rnsName,
88  const std::string& nodeName);
89 
90  //querry
91  public:
94  Eigen::Matrix4f transformFromTo(const std::string& from,
95  const std::string& to,
96  const VirtualRobot::RobotPtr& rob);
97 
98  //sync
99  public:
100  bool synchronizeLocalClone(const VirtualRobot::RobotPtr& robot) const;
101  bool synchronizeLocalClone(const VirtualRobot::RobotPtr& robot, Ice::Long timestamp) const;
103  const RobotStateConfig& state) const;
104 
105  bool synchronizeLocalClone(const RobotData& rdata) const;
106  bool synchronizeLocalClone(const RobotData& rdata, Ice::Long timestamp) const;
107  bool synchronizeLocalClone(const RobotData& rdata, const RobotStateConfig& state) const;
108 
109  bool synchronizeLocalClone(const std::string& id) const;
110  bool synchronizeLocalClone(const std::string& id, Ice::Long timestamp) const;
111  bool synchronizeLocalClone(const std::string& id, const RobotStateConfig& state) const;
112 
113  //diffik
114  public:
116  calculateRobotDiffIK(const std::string& id,
117  const Eigen::Matrix4f& targetPose,
118  const SimpleDiffIK::Parameters& params = {}) const;
120  calculateRobotReachability(const std::string& id,
121  const std::vector<Eigen::Matrix4f>& targets,
122  const Eigen::VectorXf& initialJV,
123  const SimpleDiffIK::Parameters& params = {}) const;
124 
125  //hooks
126  protected:
127  void preOnInitComponent() override;
128  void preOnConnectComponent() override;
129  void postOnDisconnectComponent() override;
130  void postCreatePropertyDefinitions(PropertyDefinitionsPtr& properties) override;
131 
132  //structs
133  public:
134  struct RobotData
135  {
137  VirtualRobot::RobotNodeSetPtr rns;
138  VirtualRobot::RobotNodePtr node;
139 
141  calculateRobotDiffIK(const Eigen::Matrix4f& targetPose,
142  const SimpleDiffIK::Parameters& params = {}) const;
144  calculateRobotReachability(const std::vector<Eigen::Matrix4f>& targets,
145  const Eigen::VectorXf& initialJV,
146  const SimpleDiffIK::Parameters& params = {}) const;
147  };
148 
149  //data
150  private:
151  static constexpr auto _propertyName = "RemoteStateComponentName";
152  std::string _robotStateComponentName;
153  RobotStateComponentInterfacePrx _robotStateComponent;
154  mutable std::recursive_mutex _robotsMutex;
155  std::map<std::string, RobotData> _robots;
156  RobotNameHelperPtr _nameHelper;
157  bool _deactivated = false;
158  };
159 } // namespace armarx::plugins
160 
162 
163 namespace armarx
164 {
166  {
167  public:
169 
170  private:
171  RobotStateComponentPlugin* _robotStateComponentPlugin{nullptr};
172 
173  public:
175 
178 
180 
182  //get / add
183  public:
184  bool hasRobot(const std::string& id) const;
185 
186  VirtualRobot::RobotPtr addRobot(const std::string& id,
187  const VirtualRobot::RobotPtr& robot,
188  const VirtualRobot::RobotNodeSetPtr& rns = {},
189  const VirtualRobot::RobotNodePtr& node = {});
190  VirtualRobot::RobotPtr addRobot(const std::string& id,
191  const VirtualRobot::RobotPtr& robot,
192  const std::string& rnsName,
193  const std::string& nodeName = "");
194  VirtualRobot::RobotPtr addRobot(const std::string& id,
195  VirtualRobot::RobotIO::RobotDescription loadMode,
196  const std::string& rnsName = "",
197  const std::string& nodeName = "");
198  VirtualRobot::RobotPtr addRobot(const std::string& id,
199  const std::string& filename,
200  const Ice::StringSeq packages,
201  VirtualRobot::RobotIO::RobotDescription loadMode,
202  const std::string& rnsName = "",
203  const std::string& nodeName = "");
204 
205  template <class... Ts>
207  addOrGetRobot(const std::string& id, Ts&&... ts)
208  {
209  if (hasRobot(id))
210  {
211  return getRobot(id);
212  }
213  return addRobot(id, std::forward<Ts>(ts)...);
214  }
215 
216  VirtualRobot::RobotPtr getRobot(const std::string& id) const;
217  RobotStateComponentPlugin::RobotData getRobotData(const std::string& id) const;
218  void setRobotRNSAndNode(const std::string& id,
219  const std::string& rnsName,
220  const std::string& nodeName);
221 
223 
224  //sync
225  public:
226  bool synchronizeLocalClone(const VirtualRobot::RobotPtr& robot) const;
227  bool synchronizeLocalClone(const VirtualRobot::RobotPtr& robot, Ice::Long timestamp) const;
229  const RobotStateConfig& state) const;
230 
231  bool synchronizeLocalClone(const RobotStateComponentPlugin::RobotData& rdata) const;
232  bool synchronizeLocalClone(const RobotStateComponentPlugin::RobotData& rdata,
233  Ice::Long timestamp) const;
234  bool synchronizeLocalClone(const RobotStateComponentPlugin::RobotData& rdata,
235  const RobotStateConfig& state) const;
236 
237  bool synchronizeLocalClone(const std::string& id) const;
238  bool synchronizeLocalClone(const std::string& id, Ice::Long timestamp) const;
239  bool synchronizeLocalClone(const std::string& id, const RobotStateConfig& state) const;
240 
241  //diffik
242  public:
243  SimpleDiffIK::Result calculateRobotDiffIK(const std::string& id,
244  const Eigen::Matrix4f& targetPose,
245  const SimpleDiffIK::Parameters& params = {});
246  SimpleDiffIK::Reachability
247  calculateRobotReachability(const std::string& id,
248  const std::vector<Eigen::Matrix4f> targets,
249  const Eigen::VectorXf& initialJV,
250  const SimpleDiffIK::Parameters& params = {});
251  };
252 } // namespace armarx
armarx::RobotStateComponentPluginUser::calculateRobotDiffIK
SimpleDiffIK::Result calculateRobotDiffIK(const std::string &id, const Eigen::Matrix4f &targetPose, const SimpleDiffIK::Parameters &params={})
Definition: RobotStateComponentPlugin.cpp:533
armarx::plugins::RobotStateComponentPlugin::RobotData::robot
VirtualRobot::RobotPtr robot
Definition: RobotStateComponentPlugin.h:136
armarx::SimpleDiffIK::Parameters
Definition: SimpleDiffIK.h:39
armarx::RobotStateComponentPluginUser::getRobotNameHelper
RobotNameHelperPtr getRobotNameHelper() const
Definition: RobotStateComponentPlugin.cpp:393
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::SimpleDiffIK::Reachability
Definition: SimpleDiffIK.h:83
armarx::RobotStateComponentPluginUser::getRobotData
RobotStateComponentPlugin::RobotData getRobotData(const std::string &id) const
Definition: RobotStateComponentPlugin.cpp:450
armarx::plugins::RobotStateComponentPlugin::postOnDisconnectComponent
void postOnDisconnectComponent() override
Definition: RobotStateComponentPlugin.cpp:298
armarx::plugins::RobotStateComponentPlugin::RobotData::calculateRobotDiffIK
SimpleDiffIK::Result calculateRobotDiffIK(const Eigen::Matrix4f &targetPose, const SimpleDiffIK::Parameters &params={}) const
Definition: RobotStateComponentPlugin.cpp:315
armarx::plugins::RobotStateComponentPlugin::getRobotStateComponentName
const std::string & getRobotStateComponentName() const
Definition: RobotStateComponentPlugin.cpp:344
armarx::skills::gui::Parameters
aron::data::DictPtr Parameters
Definition: SkillManagerWrapper.h:21
armarx::RobotStateComponentPluginUser::setRobotRNSAndNode
void setRobotRNSAndNode(const std::string &id, const std::string &rnsName, const std::string &nodeName)
Definition: RobotStateComponentPlugin.cpp:456
armarx::RobotStateComponentPluginUser::getRobotStateComponent
const RobotStateComponentInterfacePrx & getRobotStateComponent() const
Definition: RobotStateComponentPlugin.cpp:387
armarx::plugins::RobotStateComponentPlugin::setRobotStateComponentName
void setRobotStateComponentName(const std::string &name)
Definition: RobotStateComponentPlugin.cpp:336
armarx::plugins::RobotStateComponentPlugin::setRobotRNSAndNode
void setRobotRNSAndNode(const std::string &id, const std::string &rnsName, const std::string &nodeName)
Definition: RobotStateComponentPlugin.cpp:156
armarx::RobotStateComponentPluginUser::addRobot
VirtualRobot::RobotPtr addRobot(const std::string &id, const VirtualRobot::RobotPtr &robot, const VirtualRobot::RobotNodeSetPtr &rns={}, const VirtualRobot::RobotNodePtr &node={})
Definition: RobotStateComponentPlugin.cpp:405
armarx::RobotStateComponentPluginUser::synchronizeLocalClone
bool synchronizeLocalClone(const VirtualRobot::RobotPtr &robot) const
Definition: RobotStateComponentPlugin.cpp:470
armarx::plugins::RobotStateComponentPlugin::setRobotStateComponent
void setRobotStateComponent(const RobotStateComponentInterfacePrx &rsc)
Definition: RobotStateComponentPlugin.cpp:44
armarx::plugins::RobotStateComponentPlugin::RobotData::node
VirtualRobot::RobotNodePtr node
Definition: RobotStateComponentPlugin.h:138
armarx::plugins::RobotStateComponentPlugin::RobotData::rns
VirtualRobot::RobotNodeSetPtr rns
Definition: RobotStateComponentPlugin.h:137
armarx::plugins::RobotStateComponentPlugin::hasRobot
bool hasRobot(const std::string &id) const
Definition: RobotStateComponentPlugin.cpp:52
armarx::plugins::RobotStateComponentPlugin::synchronizeLocalClone
bool synchronizeLocalClone(const VirtualRobot::RobotPtr &robot) const
Definition: RobotStateComponentPlugin.cpp:191
armarx::plugins::RobotStateComponentPlugin::getRobotData
RobotData getRobotData(const std::string &id) const
Definition: RobotStateComponentPlugin.cpp:148
armarx::plugins::RobotStateComponentPlugin::getRobotNameHelper
RobotNameHelperPtr getRobotNameHelper() const
Definition: RobotStateComponentPlugin.cpp:37
ManagedIceObject.h
armarx::plugins::RobotStateComponentPlugin::transformFromTo
Eigen::Matrix4f transformFromTo(const std::string &from, const std::string &to, const VirtualRobot::RobotPtr &rob)
Definition: RobotStateComponentPlugin.cpp:356
armarx::RobotNameHelperPtr
std::shared_ptr< class RobotNameHelper > RobotNameHelperPtr
Definition: RobotNameHelper.h:32
armarx::plugins::RobotStateComponentPlugin::getRobot
VirtualRobot::RobotPtr getRobot(const std::string &id) const
Definition: RobotStateComponentPlugin.cpp:142
armarx::plugins
This file is part of ArmarX.
Definition: DebugObserverComponentPlugin.cpp:27
armarx::ComponentPlugin
Definition: ComponentPlugin.h:37
armarx::plugins::RobotStateComponentPlugin::calculateRobotReachability
SimpleDiffIK::Reachability calculateRobotReachability(const std::string &id, const std::vector< Eigen::Matrix4f > &targets, const Eigen::VectorXf &initialJV, const SimpleDiffIK::Parameters &params={}) const
Definition: RobotStateComponentPlugin.cpp:260
armarx::RobotStateComponentPluginUser::hasRobot
bool hasRobot(const std::string &id) const
Definition: RobotStateComponentPlugin.cpp:399
armarx::RobotStateComponentPluginUser::getRobotStateComponentPlugin
const RobotStateComponentPlugin & getRobotStateComponentPlugin() const
Definition: RobotStateComponentPlugin.cpp:375
armarx::plugins::RobotStateComponentPlugin::postCreatePropertyDefinitions
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override
Definition: RobotStateComponentPlugin.cpp:304
armarx::RobotStateComponentPluginUser::RobotStateComponentPluginUser
RobotStateComponentPluginUser()
Definition: RobotStateComponentPlugin.cpp:369
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:918
SimpleDiffIK.h
armarx::plugins::RobotStateComponentPlugin::RobotData
Definition: RobotStateComponentPlugin.h:134
filename
std::string filename
Definition: VisualizationRobot.cpp:86
armarx::plugins::RobotStateComponentPlugin::addRobot
VirtualRobot::RobotPtr addRobot(const std::string &id, const VirtualRobot::RobotPtr &robot, const VirtualRobot::RobotNodeSetPtr &rns={}, const VirtualRobot::RobotNodePtr &node={})
Definition: RobotStateComponentPlugin.cpp:59
armarx::RobotStateComponentPluginUser::RobotStateComponentPlugin
armarx::plugins::RobotStateComponentPlugin RobotStateComponentPlugin
Definition: RobotStateComponentPlugin.h:168
armarx::RobotStateComponentPluginUser::calculateRobotReachability
SimpleDiffIK::Reachability calculateRobotReachability(const std::string &id, const std::vector< Eigen::Matrix4f > targets, const Eigen::VectorXf &initialJV, const SimpleDiffIK::Parameters &params={})
Definition: RobotStateComponentPlugin.cpp:541
armarx::RobotStateComponentPluginUser::addOrGetRobot
VirtualRobot::RobotPtr addOrGetRobot(const std::string &id, Ts &&... ts)
Definition: RobotStateComponentPlugin.h:207
armarx::plugins::RobotStateComponentPlugin::getRobotStateComponent
const RobotStateComponentInterfacePrx & getRobotStateComponent() const
Definition: RobotStateComponentPlugin.cpp:185
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:162
armarx::SimpleDiffIK::Result
Definition: SimpleDiffIK.h:70
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::plugins::RobotStateComponentPlugin::preOnInitComponent
void preOnInitComponent() override
Definition: RobotStateComponentPlugin.cpp:270
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::plugins::RobotStateComponentPlugin::RobotData::calculateRobotReachability
SimpleDiffIK::Reachability calculateRobotReachability(const std::vector< Eigen::Matrix4f > &targets, const Eigen::VectorXf &initialJV, const SimpleDiffIK::Parameters &params={}) const
Definition: RobotStateComponentPlugin.cpp:325
armarx::plugins::RobotStateComponentPlugin::deactivate
void deactivate()
Definition: RobotStateComponentPlugin.cpp:350
armarx::plugins::RobotStateComponentPlugin
Brief description of class RobotAPIComponentPlugins.
Definition: RobotStateComponentPlugin.h:51
armarx::RobotStateComponentPluginUser::getRobot
VirtualRobot::RobotPtr getRobot(const std::string &id) const
Definition: RobotStateComponentPlugin.cpp:444
ComponentPlugin.h
armarx::plugins::RobotStateComponentPlugin::preOnConnectComponent
void preOnConnectComponent() override
Definition: RobotStateComponentPlugin.cpp:285
armarx::plugins::RobotStateComponentPlugin::calculateRobotDiffIK
SimpleDiffIK::Result calculateRobotDiffIK(const std::string &id, const Eigen::Matrix4f &targetPose, const SimpleDiffIK::Parameters &params={}) const
Definition: RobotStateComponentPlugin.cpp:252
armarx::RobotStateComponentPluginUser
Definition: RobotStateComponentPlugin.h:165
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
RobotNameHelper.h
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19