ControlTargetBase.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::ControlTargetBase
17 * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18 * @date 2017
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <map>
26#include <memory>
27#include <string>
28
29#include <Ice/Handle.h>
30#include <IceUtil/Time.h>
31
35
36namespace armarx
37{
38 typedef ::IceInternal::Handle<class VariantBase> VariantBasePtr;
39
40 /**
41 * @class ControlTargetBase
42 * @ingroup Library-RobotUnit
43 * @brief Brief description of class JointControlTargetBase.
44 *
45 * Detailed description of class ControlTargetBase.
46 */
48 {
49 public:
50 ////use this class as parameter to functions that only should be called by control devices
51 class ControlDeviceAccessToken
52 {
53 friend class ControlDevice;
54 ControlDeviceAccessToken() = default;
55 };
56
57 template <class DerivedClass>
59
60 virtual ~ControlTargetBase() = default;
61
62 virtual std::string getControlTargetType(bool withoutNamespaceSpecifier = false) const = 0;
63 virtual const std::string& getControlMode() const = 0;
64 virtual void reset() = 0;
65 virtual bool isValid() const = 0;
66
67 template <class T>
68 bool
69 isA() const
70 {
71 return asA<T>();
72 }
73
74 template <class T>
75 const T*
76 asA() const
77 {
78 return dynamic_cast<const T*>(this);
79 }
80
81 template <class T>
82 T*
84 {
85 return dynamic_cast<T*>(this);
86 }
87
88 //logging functions
89 /// @brief used to send the data to the DebugObserverTopic and to other Components (e.g. GUI widgets)
90 virtual std::map<std::string, VariantBasePtr>
91 toVariants(const IceUtil::Time& timestamp) const = 0;
92
93 virtual std::size_t getNumberOfDataFields() const = 0;
94 virtual std::vector<std::string> getDataFieldNames() const = 0;
95 virtual void getDataFieldAs(std::size_t i, bool& out) const = 0;
96 virtual void getDataFieldAs(std::size_t i, Ice::Byte& out) const = 0;
97 virtual void getDataFieldAs(std::size_t i, Ice::Short& out) const = 0;
98 virtual void getDataFieldAs(std::size_t i, Ice::Int& out) const = 0;
99 virtual void getDataFieldAs(std::size_t i, Ice::Long& out) const = 0;
100 virtual void getDataFieldAs(std::size_t i, Ice::Float& out) const = 0;
101 virtual void getDataFieldAs(std::size_t i, Ice::Double& out) const = 0;
102 virtual void getDataFieldAs(std::size_t i, std::string& out) const = 0;
103 virtual const std::type_info& getDataFieldType(std::size_t i) const = 0;
104
105 //management functions
106 template <
107 class T,
108 class = typename std::enable_if<std::is_base_of<ControlTargetBase, T>::value>::type>
109 void
110 _copyTo(std::unique_ptr<T>& target) const
111 {
112 _copyTo(target.get());
113 }
114
115 ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK(ControlTargetHasGetClassMemberInfo,
116 GetClassMemberInfo,
117 ControlTargetInfo<T> (*)(void));
118
120 };
121
122#define DETAIL_ControlTargetBase_DEFAULT_METHOD_IMPLEMENTATION \
123 ARMARX_PLACEMENT_CONSTRUCTION_HELPER \
124 using ControlTargetBase = ::armarx::ControlTargetBase; \
125 using VariantBasePtr = ::armarx::VariantBasePtr; \
126 std::string getControlTargetType(bool withoutNamespaceSpecifier = false) const override \
127 { \
128 return armarx::GetTypeString(*this, withoutNamespaceSpecifier); \
129 } \
130 void _check_for_static_GetClassMemberInfo_overload() \
131 { \
132 static_assert( \
133 ControlTargetHasGetClassMemberInfo<std::decay<decltype(*this)>::type>::value, \
134 "This class has to implement GetClassMemberInfo() returning " \
135 "an instance of ControlTargetInfo<THIS_CLASS_TYPE>"); \
136 } \
137 std::map<std::string, VariantBasePtr> toVariants(const IceUtil::Time& timestamp) \
138 const override \
139 { \
140 return ControlTargetInfo<std::decay<decltype(*this)>::type>::ToVariants(timestamp, this); \
141 } \
142 std::size_t getNumberOfDataFields() const override \
143 { \
144 return ControlTargetInfo<std::decay<decltype(*this)>::type>::GetNumberOfDataFields(); \
145 } \
146 void getDataFieldAs(std::size_t i, bool& out) const override \
147 { \
148 ControlTargetInfo<std::decay<decltype(*this)>::type>::GetDataFieldAs(this, i, out); \
149 } \
150 void getDataFieldAs(std::size_t i, Ice::Byte& out) const override \
151 { \
152 ControlTargetInfo<std::decay<decltype(*this)>::type>::GetDataFieldAs(this, i, out); \
153 } \
154 void getDataFieldAs(std::size_t i, Ice::Short& out) const override \
155 { \
156 ControlTargetInfo<std::decay<decltype(*this)>::type>::GetDataFieldAs(this, i, out); \
157 } \
158 void getDataFieldAs(std::size_t i, Ice::Int& out) const override \
159 { \
160 ControlTargetInfo<std::decay<decltype(*this)>::type>::GetDataFieldAs(this, i, out); \
161 } \
162 void getDataFieldAs(std::size_t i, Ice::Long& out) const override \
163 { \
164 ControlTargetInfo<std::decay<decltype(*this)>::type>::GetDataFieldAs(this, i, out); \
165 } \
166 void getDataFieldAs(std::size_t i, Ice::Float& out) const override \
167 { \
168 ControlTargetInfo<std::decay<decltype(*this)>::type>::GetDataFieldAs(this, i, out); \
169 } \
170 void getDataFieldAs(std::size_t i, Ice::Double& out) const override \
171 { \
172 ControlTargetInfo<std::decay<decltype(*this)>::type>::GetDataFieldAs(this, i, out); \
173 } \
174 void getDataFieldAs(std::size_t i, std::string& out) const override \
175 { \
176 ControlTargetInfo<std::decay<decltype(*this)>::type>::GetDataFieldAs(this, i, out); \
177 } \
178 const std::type_info& getDataFieldType(std::size_t i) const override \
179 { \
180 return ControlTargetInfo<std::decay<decltype(*this)>::type>::GetDataFieldType(i); \
181 } \
182 std::vector<std::string> getDataFieldNames() const override \
183 { \
184 return ControlTargetInfo<std::decay<decltype(*this)>::type>::GetDataFieldNames(); \
185 }
186
187#define make_DummyControlTarget(Suffix, ControlMode) \
188 class DummyControlTarget##Suffix : public ControlTargetBase \
189 { \
190 public: \
191 virtual const std::string& \
192 getControlMode() const override \
193 { \
194 return ControlMode; \
195 } \
196 virtual void \
197 reset() override \
198 { \
199 } \
200 virtual bool \
201 isValid() const override \
202 { \
203 return true; \
204 } \
205 DETAIL_ControlTargetBase_DEFAULT_METHOD_IMPLEMENTATION static ControlTargetInfo< \
206 DummyControlTarget##Suffix> \
207 GetClassMemberInfo() \
208 { \
209 return ControlTargetInfo<DummyControlTarget##Suffix>{}; \
210 } \
211 }
212 make_DummyControlTarget(EmergencyStop, ControlModes::EmergencyStop);
213 make_DummyControlTarget(StopMovement, ControlModes::StopMovement);
214#undef make_DummyControlTarget
215} // namespace armarx
std::string timestamp()
#define make_DummyControlTarget(Suffix, ControlMode)
#define ARMARX_PLACEMENT_CONSTRUCTION_HELPER_BASE(CommonBaseType)
Brief description of class JointControlTargetBase.
virtual void getDataFieldAs(std::size_t i, Ice::Double &out) const =0
virtual void getDataFieldAs(std::size_t i, Ice::Long &out) const =0
ARMARX_META_MAKE_HAS_MEMBER_FNC_CHECK(ControlTargetHasGetClassMemberInfo, GetClassMemberInfo, ControlTargetInfo< T >(*)(void))
virtual const std::type_info & getDataFieldType(std::size_t i) const =0
virtual ~ControlTargetBase()=default
virtual void reset()=0
virtual void getDataFieldAs(std::size_t i, std::string &out) const =0
virtual const std::string & getControlMode() const =0
virtual std::map< std::string, VariantBasePtr > toVariants(const IceUtil::Time &timestamp) const =0
used to send the data to the DebugObserverTopic and to other Components (e.g. GUI widgets)
virtual std::size_t getNumberOfDataFields() const =0
virtual std::string getControlTargetType(bool withoutNamespaceSpecifier=false) const =0
virtual void getDataFieldAs(std::size_t i, bool &out) const =0
virtual bool isValid() const =0
virtual void getDataFieldAs(std::size_t i, Ice::Byte &out) const =0
virtual void getDataFieldAs(std::size_t i, Ice::Float &out) const =0
virtual std::vector< std::string > getDataFieldNames() const =0
introspection::ClassMemberInfo< ControlTargetBase, DerivedClass > ControlTargetInfo
virtual void getDataFieldAs(std::size_t i, Ice::Short &out) const =0
virtual void getDataFieldAs(std::size_t i, Ice::Int &out) const =0
void _copyTo(std::unique_ptr< T > &target) const
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr