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 
29 namespace 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:
109  float maxTorque;
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 
169  static ControlTargetInfo<ActiveImpedanceControlTarget>
171  {
176  return cti;
177  }
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  {
198  }
199 
200  bool
201  isValid() const override
202  {
204  }
205 
206  static ControlTargetInfo<ControlTarget1DoFActuatorPWM>
208  {
211  return cti;
212  }
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
armarx::ControlTarget1DoFActuatorTorqueVelocity::isValid
bool isValid() const override
Definition: ControlTarget1DoFActuator.h:125
armarx::ActiveImpedanceControlTarget::reset
void reset() override
Definition: ControlTarget1DoFActuator.h:156
armarx::ControlTarget1DoFActuatorTorqueVelocity::reset
void reset() override
Definition: ControlTarget1DoFActuator.h:118
armarx::ActiveImpedanceControlTarget::kd
float kd
Definition: ControlTarget1DoFActuator.h:147
armarx::ControlTarget1DoFActuatorTorqueVelocity::getControlMode
const std::string & getControlMode() const override
Definition: ControlTarget1DoFActuator.h:112
armarx::ControlTarget1DoFActuatorVelocityWithPWMLimit::pwmDefaultLimit
std::int16_t pwmDefaultLimit
Definition: ControlTarget1DoFActuator.h:273
armarx::ControlTarget1DoFActuatorPWM::getControlMode
const std::string & getControlMode() const override
Definition: ControlTarget1DoFActuator.h:189
armarx::ControlTargetBase
Brief description of class JointControlTargetBase.
Definition: ControlTargetBase.h:47
armarx::ControlTarget1DoFActuatorPWM
Definition: ControlTarget1DoFActuator.h:182
ControlTargetBase.h
armarx::introspection::ClassMemberInfo
Definition: ClassMemberInfo.h:34
Constants.h
armarx::ControlTarget1DoFActuatorPositionWithPWMLimit::pwmDefaultLimit
std::int16_t pwmDefaultLimit
Definition: ControlTarget1DoFActuator.h:223
armarx::ControlTarget1DoFActuatorVelocityWithPWMLimit
Definition: ControlTarget1DoFActuator.h:267
armarx::ControlTarget1DoFActuatorPWM::isValid
bool isValid() const override
Definition: ControlTarget1DoFActuator.h:201
armarx::ControlTarget1DoFActuatorVelocityWithPWMLimit::isValid
bool isValid() const override
Definition: ControlTarget1DoFActuator.h:291
std::isfinite
bool isfinite(const std::vector< T, Ts... > &v)
Definition: algorithm.h:327
armarx::abs
std::vector< T > abs(const std::vector< T > &v)
Definition: VectorHelpers.h:253
armarx::make_ControlTarget1DoFActuator
make_ControlTarget1DoFActuator(float, ControllerConstants::ValueNotSetNaN, ControlTarget1DoFActuatorPosition, position, ControlModes::Position1DoF)
armarx::ControlTarget1DoFActuatorTorqueVelocity::GetClassMemberInfo
static ControlTargetInfo< ControlTarget1DoFActuatorTorqueVelocity > GetClassMemberInfo()
Definition: ControlTarget1DoFActuator.h:131
armarx::ActiveImpedanceControlTarget::position
float position
Definition: ControlTarget1DoFActuator.h:145
armarx::introspection::ClassMemberInfo::addMemberVariable
EntryConfigurator< ClassType > addMemberVariable(MemberType ClassType::*ptr, const std::string &name)
add a member variable of the current class
armarx::ControlTarget1DoFActuatorVelocityWithPWMLimit::reset
void reset() override
Definition: ControlTarget1DoFActuator.h:284
armarx::ActiveImpedanceControlTarget::kp
float kp
Definition: ControlTarget1DoFActuator.h:146
armarx::ControlTarget1DoFActuatorPositionWithPWMLimit::setPWMLimits
void setPWMLimits(std::int16_t hard, std::int16_t def, ControlDeviceAccessToken)
Definition: ControlTarget1DoFActuator.h:258
armarx::ControlTarget1DoFActuatorPositionWithPWMLimit::reset
void reset() override
Definition: ControlTarget1DoFActuator.h:234
max
T max(T t1, T t2)
Definition: gdiam.h:48
armarx::ControlTarget1DoFActuatorPositionWithPWMLimit
Definition: ControlTarget1DoFActuator.h:217
armarx::ControlTarget1DoFActuatorPositionWithPWMLimit::maxPWM
int16_t maxPWM
Definition: ControlTarget1DoFActuator.h:220
armarx::ControlTarget1DoFActuatorPWM::pwm
std::int16_t pwm
Definition: ControlTarget1DoFActuator.h:185
armarx::ControlTarget1DoFActuatorVelocityWithPWMLimit::setPWMLimits
void setPWMLimits(std::int16_t hard, std::int16_t def, ControlDeviceAccessToken)
Definition: ControlTarget1DoFActuator.h:308
armarx::ControlTarget1DoFActuatorVelocityWithPWMLimit::pwmHardLimit
std::int16_t pwmHardLimit
Definition: ControlTarget1DoFActuator.h:274
armarx::ControlTarget1DoFActuatorPWM::reset
void reset() override
Definition: ControlTarget1DoFActuator.h:195
armarx::ActiveImpedanceControlTarget
Definition: ControlTarget1DoFActuator.h:142
armarx::ControlTarget1DoFActuatorPositionWithPWMLimit::getControlMode
const std::string & getControlMode() const override
Definition: ControlTarget1DoFActuator.h:228
DETAIL_ControlTargetBase_DEFAULT_METHOD_IMPLEMENTATION
#define DETAIL_ControlTargetBase_DEFAULT_METHOD_IMPLEMENTATION
Definition: ControlTargetBase.h:122
armarx::ControlTarget1DoFActuatorPositionWithPWMLimit::GetClassMemberInfo
static ControlTargetInfo< ControlTarget1DoFActuatorPositionWithPWMLimit > GetClassMemberInfo()
Definition: ControlTarget1DoFActuator.h:247
armarx::ControlTarget1DoFActuatorTorqueVelocity
Definition: ControlTarget1DoFActuator.h:106
armarx::ControlTarget1DoFActuatorPWM::GetClassMemberInfo
static ControlTargetInfo< ControlTarget1DoFActuatorPWM > GetClassMemberInfo()
Definition: ControlTarget1DoFActuator.h:207
armarx::ControlTarget1DoFActuatorTorqueVelocity::maxTorque
float maxTorque
Definition: ControlTarget1DoFActuator.h:109
armarx::ControlTarget1DoFActuatorVelocityWithPWMLimit::getControlMode
const std::string & getControlMode() const override
Definition: ControlTarget1DoFActuator.h:278
armarx::ControlTarget1DoFActuatorVelocityWithPWMLimit::maxPWM
int16_t maxPWM
Definition: ControlTarget1DoFActuator.h:270
armarx::ActiveImpedanceControlTarget::getControlMode
const std::string & getControlMode() const override
Definition: ControlTarget1DoFActuator.h:150
armarx::ActiveImpedanceControlTarget::isValid
bool isValid() const override
Definition: ControlTarget1DoFActuator.h:164
armarx::ControlTarget1DoFActuatorVelocityWithPWMLimit::GetClassMemberInfo
static ControlTargetInfo< ControlTarget1DoFActuatorVelocityWithPWMLimit > GetClassMemberInfo()
Definition: ControlTarget1DoFActuator.h:297
armarx::ControlTarget1DoFActuatorPositionWithPWMLimit::pwmHardLimit
std::int16_t pwmHardLimit
Definition: ControlTarget1DoFActuator.h:224
armarx::ActiveImpedanceControlTarget::GetClassMemberInfo
static ControlTargetInfo< ActiveImpedanceControlTarget > GetClassMemberInfo()
Definition: ControlTarget1DoFActuator.h:170
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ControlTarget1DoFActuatorPositionWithPWMLimit::isValid
bool isValid() const override
Definition: ControlTarget1DoFActuator.h:241