ControlTarget1DoFActuator.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::ActuatorVelocityTarget
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 <RobotAPI/components/units/RobotUnit/Constants.h> // for ControllerConstants::ValueNotSetNaN
26
27#include "ControlTargetBase.h"
28
29namespace armarx
30{
31#define make_ControlTarget1DoFActuator(type, invalid, name, varname, cmode) \
32 class name : public ControlTargetBase \
33 { \
34 public: \
35 type varname = ControllerConstants::ValueNotSetNaN; \
36 name() = default; \
37 name(const name&) = default; \
38 name(name&&) = default; \
39 name(type val) : varname{val} \
40 { \
41 } \
42 name& operator=(const name&) = default; \
43 name& operator=(name&&) = default; \
44 name& \
45 operator=(type val) \
46 { \
47 varname = val; \
48 return *this; \
49 } \
50 virtual const std::string& \
51 getControlMode() const override \
52 { \
53 return cmode; \
54 } \
55 virtual void \
56 reset() override \
57 { \
58 varname = invalid; \
59 } \
60 virtual bool \
61 isValid() const override \
62 { \
63 return std::isfinite(varname); \
64 } \
65 DETAIL_ControlTargetBase_DEFAULT_METHOD_IMPLEMENTATION static ControlTargetInfo<name> \
66 GetClassMemberInfo() \
67 { \
68 ControlTargetInfo<name> cti; \
69 cti.addMemberVariable(&name::varname, #varname); \
70 return cti; \
71 } \
72 }
73
75 ControllerConstants::ValueNotSetNaN,
76 ControlTarget1DoFActuatorPosition,
77 position,
78 ControlModes::Position1DoF);
80 ControllerConstants::ValueNotSetNaN,
81 ControlTarget1DoFActuatorVelocity,
82 velocity,
83 ControlModes::Velocity1DoF);
85 ControllerConstants::ValueNotSetNaN,
86 ControlTarget1DoFActuatorTorque,
87 torque,
88 ControlModes::Torque1DoF);
90 ControllerConstants::ValueNotSetNaN,
91 ControlTarget1DoFActuatorZeroTorque,
92 torque,
93 ControlModes::ZeroTorque1DoF);
95 ControllerConstants::ValueNotSetNaN,
96 ControlTarget1DoFActuatorZeroVelocity,
97 velocity,
98 ControlModes::ZeroVelocity1DoF);
100 ControllerConstants::ValueNotSetNaN,
101 ControlTarget1DoFActuatorCurrent,
102 current,
103 ControlModes::Current1DoF);
104#undef make_ControlTarget1DoFActuator
105
106 class ControlTarget1DoFActuatorTorqueVelocity : public ControlTarget1DoFActuatorVelocity
107 {
108 public:
110
111 const std::string&
112 getControlMode() const override
113 {
114 return ControlModes::VelocityTorque;
115 }
116
117 void
118 reset() override
119 {
120 ControlTarget1DoFActuatorVelocity::reset();
121 maxTorque = -1.0f; // if < 0, default value for joint is to be used
122 }
123
124 bool
125 isValid() const override
126 {
127 return ControlTarget1DoFActuatorVelocity::isValid() && std::isfinite(maxTorque);
128 }
129
130 static ControlTargetInfo<ControlTarget1DoFActuatorTorqueVelocity>
132 {
133 ControlTargetInfo<ControlTarget1DoFActuatorTorqueVelocity> cti;
134 cti.addBaseClass<ControlTarget1DoFActuatorVelocity>();
135 cti.addMemberVariable(&ControlTarget1DoFActuatorTorqueVelocity::maxTorque, "maxTorque");
136 return cti;
137 }
138
140 };
141
143 {
144 public:
145 float position;
146 float kp;
147 float kd;
148
149 const std::string&
150 getControlMode() const override
151 {
152 return ControlModes::ActiveImpedance;
153 }
154
155 void
156 reset() override
157 {
158 position = 0;
159 kp = 0;
160 kd = 0;
161 }
162
163 bool
164 isValid() const override
165 {
166 return std::isfinite(position) && kp >= 0;
167 }
168
178
180 };
181
183 {
184 public:
185 std::int16_t pwm;
186
187 public:
188 const std::string&
189 getControlMode() const override
190 {
191 return ControlModes::PWM1DoF;
192 }
193
194 void
195 reset() override
196 {
197 pwm = std::numeric_limits<std::int16_t>::max();
198 }
199
200 bool
201 isValid() const override
202 {
203 return std::abs(pwm) < std::numeric_limits<std::int16_t>::max();
204 }
205
213
215 };
216
217 class ControlTarget1DoFActuatorPositionWithPWMLimit : public ControlTarget1DoFActuatorPosition
218 {
219 public:
220 int16_t maxPWM;
221
222 protected:
223 std::int16_t pwmDefaultLimit = 256;
224 std::int16_t pwmHardLimit = 256;
225
226 public:
227 const std::string&
228 getControlMode() const override
229 {
230 return ControlModes::PositionWithPwmLimit1DoF;
231 }
232
233 void
234 reset() override
235 {
237 ControlTarget1DoFActuatorPosition::reset();
238 }
239
240 bool
241 isValid() const override
242 {
243 return std::abs(maxPWM) <= pwmHardLimit && ControlTarget1DoFActuatorPosition::isValid();
244 }
245
246 static ControlTargetInfo<ControlTarget1DoFActuatorPositionWithPWMLimit>
248 {
249 ControlTargetInfo<ControlTarget1DoFActuatorPositionWithPWMLimit> cti;
250 cti.addBaseClass<ControlTarget1DoFActuatorPosition>();
251 cti.addMemberVariable(&ControlTarget1DoFActuatorPositionWithPWMLimit::maxPWM, "maxPWM");
253 "pwmHardLimit");
254 return cti;
255 }
256
257 void
258 setPWMLimits(std::int16_t hard, std::int16_t def, ControlDeviceAccessToken)
259 {
260 pwmHardLimit = hard;
261 pwmDefaultLimit = def;
262 }
263
265 };
266
267 class ControlTarget1DoFActuatorVelocityWithPWMLimit : public ControlTarget1DoFActuatorVelocity
268 {
269 public:
270 int16_t maxPWM;
271
272 protected:
273 std::int16_t pwmDefaultLimit = 256;
274 std::int16_t pwmHardLimit = 256;
275
276 public:
277 const std::string&
278 getControlMode() const override
279 {
280 return ControlModes::VelocityWithPwmLimit1DoF;
281 }
282
283 void
284 reset() override
285 {
287 ControlTarget1DoFActuatorVelocity::reset();
288 }
289
290 bool
291 isValid() const override
292 {
293 return std::abs(maxPWM) <= pwmHardLimit && ControlTarget1DoFActuatorVelocity::isValid();
294 }
295
296 static ControlTargetInfo<ControlTarget1DoFActuatorVelocityWithPWMLimit>
298 {
299 ControlTargetInfo<ControlTarget1DoFActuatorVelocityWithPWMLimit> cti;
300 cti.addBaseClass<ControlTarget1DoFActuatorVelocity>();
301 cti.addMemberVariable(&ControlTarget1DoFActuatorVelocityWithPWMLimit::maxPWM, "maxPWM");
303 "pwmHardLimit");
304 return cti;
305 }
306
307 void
308 setPWMLimits(std::int16_t hard, std::int16_t def, ControlDeviceAccessToken)
309 {
310 pwmHardLimit = hard;
311 pwmDefaultLimit = def;
312 }
313
315 };
316} // namespace armarx
#define make_ControlTarget1DoFActuator(type, invalid, name, varname, cmode)
#define DETAIL_ControlTargetBase_DEFAULT_METHOD_IMPLEMENTATION
static ControlTargetInfo< ActiveImpedanceControlTarget > GetClassMemberInfo()
const std::string & getControlMode() const override
const std::string & getControlMode() const override
static ControlTargetInfo< ControlTarget1DoFActuatorPWM > GetClassMemberInfo()
static ControlTargetInfo< ControlTarget1DoFActuatorPositionWithPWMLimit > GetClassMemberInfo()
void setPWMLimits(std::int16_t hard, std::int16_t def, ControlDeviceAccessToken)
static ControlTargetInfo< ControlTarget1DoFActuatorTorqueVelocity > GetClassMemberInfo()
static ControlTargetInfo< ControlTarget1DoFActuatorVelocityWithPWMLimit > GetClassMemberInfo()
void setPWMLimits(std::int16_t hard, std::int16_t def, ControlDeviceAccessToken)
Brief description of class JointControlTargetBase.
introspection::ClassMemberInfo< ControlTargetBase, DerivedClass > ControlTargetInfo
This file offers overloads of toIce() and fromIce() functions for STL container types.
bool isfinite(const std::vector< T, Ts... > &v)
Definition algorithm.h:366
EntryConfigurator< ClassType > addMemberVariable(MemberType ClassType::*ptr, const std::string &name)
add a member variable of the current class