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
36namespace 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:
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
163namespace 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
std::string timestamp()
ManagedIceObject(ManagedIceObject const &other)
SimpleDiffIK::Result calculateRobotDiffIK(const std::string &id, const Eigen::Matrix4f &targetPose, const SimpleDiffIK::Parameters &params={})
void setRobotRNSAndNode(const std::string &id, const std::string &rnsName, const std::string &nodeName)
RobotStateComponentPlugin::RobotData getRobotData(const std::string &id) const
VirtualRobot::RobotPtr addOrGetRobot(const std::string &id, Ts &&... ts)
bool synchronizeLocalClone(const VirtualRobot::RobotPtr &robot) const
const RobotStateComponentPlugin & getRobotStateComponentPlugin() const
armarx::plugins::RobotStateComponentPlugin RobotStateComponentPlugin
SimpleDiffIK::Reachability calculateRobotReachability(const std::string &id, const std::vector< Eigen::Matrix4f > targets, const Eigen::VectorXf &initialJV, const SimpleDiffIK::Parameters &params={})
VirtualRobot::RobotPtr addRobot(const std::string &id, const VirtualRobot::RobotPtr &robot, const VirtualRobot::RobotNodeSetPtr &rns={}, const VirtualRobot::RobotNodePtr &node={})
const RobotStateComponentInterfacePrx & getRobotStateComponent() const
VirtualRobot::RobotPtr getRobot(const std::string &id) const
Brief description of class RobotAPIComponentPlugins.
Eigen::Matrix4f transformFromTo(const std::string &from, const std::string &to, const VirtualRobot::RobotPtr &rob)
void setRobotRNSAndNode(const std::string &id, const std::string &rnsName, const std::string &nodeName)
RobotData getRobotData(const std::string &id) const
bool synchronizeLocalClone(const VirtualRobot::RobotPtr &robot) const
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override
VirtualRobot::RobotPtr addRobot(const std::string &id, const VirtualRobot::RobotPtr &robot, const VirtualRobot::RobotNodeSetPtr &rns={}, const VirtualRobot::RobotNodePtr &node={})
const RobotStateComponentInterfacePrx & getRobotStateComponent() const
VirtualRobot::RobotPtr getRobot(const std::string &id) const
SimpleDiffIK::Reachability calculateRobotReachability(const std::string &id, const std::vector< Eigen::Matrix4f > &targets, const Eigen::VectorXf &initialJV, const SimpleDiffIK::Parameters &params={}) const
SimpleDiffIK::Result calculateRobotDiffIK(const std::string &id, const Eigen::Matrix4f &targetPose, const SimpleDiffIK::Parameters &params={}) const
void setRobotStateComponent(const RobotStateComponentInterfacePrx &rsc)
Brief description of class targets.
Definition targets.h:39
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
std::shared_ptr< class RobotNameHelper > RobotNameHelperPtr
SimpleDiffIK::Reachability calculateRobotReachability(const std::vector< Eigen::Matrix4f > &targets, const Eigen::VectorXf &initialJV, const SimpleDiffIK::Parameters &params={}) const
SimpleDiffIK::Result calculateRobotDiffIK(const Eigen::Matrix4f &targetPose, const SimpleDiffIK::Parameters &params={}) const