HEBI C++ API  1.0.0
info.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "hebi.h"
4 #include "color.hpp"
5 #include <string>
6 #include "util.hpp"
7 #include "gains.hpp"
8 
9 namespace hebi {
10 
30 class Info final
31 {
32  public:
33  enum class ControlStrategy {
35  Off,
37  DirectPWM,
39  Strategy2,
41  Strategy3,
43  Strategy4,
44  };
45 
46  // Note: this is 'protected' instead of 'private' for easier use with Doxygen
47  protected:
49  class FloatField final
50  {
51  public:
52  #ifndef DOXYGEN_OMIT_INTERNAL
53  FloatField(HebiInfoPtr internal, HebiInfoFloatField field);
54  #endif // DOXYGEN_OMIT_INTERNAL
55  explicit operator bool() const;
69  bool has() const;
72  float get() const;
73 
74  private:
75  HebiInfoPtr const internal_;
76  HebiInfoFloatField const field_;
77 
79  };
81  class BoolField final
82  {
83  public:
84  #ifndef DOXYGEN_OMIT_INTERNAL
85  BoolField(HebiInfoPtr internal, HebiInfoBoolField field);
86  #endif // DOXYGEN_OMIT_INTERNAL
87  bool has() const;
91  bool get() const;
92 
93  private:
94  HebiInfoPtr const internal_;
95  HebiInfoBoolField const field_;
96 
98  };
99 
101  class StringField final
102  {
103  public:
104  #ifndef DOXYGEN_OMIT_INTERNAL
105  StringField(HebiInfoPtr internal, HebiInfoStringField field);
106  #endif // DOXYGEN_OMIT_INTERNAL
107  explicit operator bool() const;
121  bool has() const;
124  std::string get() const;
125 
126  private:
127  HebiInfoPtr const internal_;
128  HebiInfoStringField const field_;
129 
131  };
132 
134  class FlagField final
135  {
136  public:
137  #ifndef DOXYGEN_OMIT_INTERNAL
138  FlagField(HebiInfoPtr internal, HebiInfoFlagField field);
139  #endif // DOXYGEN_OMIT_INTERNAL
140  explicit operator bool() const;
154  bool has() const;
155 
156  private:
157  HebiInfoPtr const internal_;
158  HebiInfoFlagField const field_;
159 
161  };
162 
164  template <typename T>
165  class EnumField final
166  {
167  public:
168  #ifndef DOXYGEN_OMIT_INTERNAL
169  EnumField(HebiInfoPtr internal, HebiInfoEnumField field)
170  : internal_(internal), field_(field) {}
171  #endif // DOXYGEN_OMIT_INTERNAL
172  explicit operator bool() const { return has(); }
186  bool has() const { return (hebiInfoGetEnum(internal_, field_, nullptr) == HebiStatusSuccess); }
189  T get() const { int32_t ret{}; hebiInfoGetEnum(internal_, field_, &ret); return static_cast<T>(ret); }
190 
191  private:
192  HebiInfoPtr const internal_;
193  HebiInfoEnumField const field_;
194 
196  };
197 
199  class LedField final
200  {
201  public:
202  #ifndef DOXYGEN_OMIT_INTERNAL
203  LedField(HebiInfoPtr internal, HebiInfoLedField field);
204  #endif // DOXYGEN_OMIT_INTERNAL
205  explicit operator bool() const { return hasColor(); }
219  bool hasColor() const;
221  Color getColor() const;
222 
223  private:
224  HebiInfoPtr const internal_;
225  HebiInfoLedField const field_;
226 
228  };
229 
231 
233  class Settings final
234  {
235  // Note: this is 'protected' instead of 'private' for easier use with Doxygen
236  protected:
238  class Actuator final
239  {
240  public:
241  #ifndef DOXYGEN_OMIT_INTERNAL
242  Actuator(HebiInfoPtr internal)
243  : internal_(internal),
244  position_gains_(internal, HebiInfoFloatPositionKp, HebiInfoBoolPositionDOnError),
245  velocity_gains_(internal, HebiInfoFloatVelocityKp, HebiInfoBoolVelocityDOnError),
246  effort_gains_(internal, HebiInfoFloatEffortKp, HebiInfoBoolEffortDOnError),
247  spring_constant_(internal, HebiInfoFloatSpringConstant),
248  control_strategy_(internal, HebiInfoEnumControlStrategy)
249  {
250  }
251  #endif // DOXYGEN_OMIT_INTERNAL
252 
253  // With all submessage and field getters: Note that the returned reference
254  // should not be used after the lifetime of this parent.
255 
256  // Submessages ----------------
257 
259  const InfoGains& positionGains() const { return position_gains_; }
261  const InfoGains& velocityGains() const { return velocity_gains_; }
263  const InfoGains& effortGains() const { return effort_gains_; }
264 
265  // Subfields ----------------
266 
268  const FloatField& springConstant() const { return spring_constant_; }
270  const EnumField<ControlStrategy>& controlStrategy() const { return control_strategy_; }
271 
272  private:
273  HebiInfoPtr const internal_;
274 
275  InfoGains position_gains_;
276  InfoGains velocity_gains_;
277  InfoGains effort_gains_;
278 
279  FloatField spring_constant_;
280  EnumField<ControlStrategy> control_strategy_;
281 
283  };
284 
285  public:
286  #ifndef DOXYGEN_OMIT_INTERNAL
287  Settings(HebiInfoPtr internal)
288  : internal_(internal),
289  actuator_(internal),
290  name_(internal, HebiInfoStringName),
291  family_(internal, HebiInfoStringFamily),
292  save_current_settings_(internal, HebiInfoFlagSaveCurrentSettings)
293  {
294  }
295  #endif // DOXYGEN_OMIT_INTERNAL
296 
297  // With all submessage and field getters: Note that the returned reference
298  // should not be used after the lifetime of this parent.
299 
300  // Submessages ----------------
301 
303  const Actuator& actuator() const { return actuator_; }
304 
305  // Subfields ----------------
306 
308  const StringField& name() const { return name_; }
310  const StringField& family() const { return family_; }
312  const FlagField& saveCurrentSettings() const { return save_current_settings_; }
313 
314  private:
315  HebiInfoPtr const internal_;
316 
317  Actuator actuator_;
318 
319  StringField name_;
320  StringField family_;
321  FlagField save_current_settings_;
322 
324  };
325 
326  private:
331  HebiInfoPtr internal_;
332 
333  public:
334  #ifndef DOXYGEN_OMIT_INTERNAL
335 
339  Info(HebiInfoPtr );
340  #endif // DOXYGEN_OMIT_INTERNAL
341 
344  Info(Info&& other);
348  ~Info() noexcept; /* annotating specified destructor as noexcept is best-practice */
349 
350  // With all submessage and field getters: Note that the returned reference
351  // should not be used after the lifetime of this parent.
352 
353  // Submessages -------------------------------------------------------------
354 
356  const Settings& settings() const { return settings_; }
357 
358  // Subfields -------------------------------------------------------------
359 
361  const LedField& led() const;
362 
364  const StringField& serial() const { return serial_; }
365 
366  private:
367  Settings settings_;
368 
369  LedField led_;
370 
371  StringField serial_;
372 
377 
378  /* Disable move assigment operator. */
379  Info& operator= (const Info&& other) = delete;
380 };
381 
382 } // namespace hebi
const FlagField & saveCurrentSettings() const
Indicates if the module should save the current values of all of its settings.
Definition: info.hpp:312
Module settings that are typically changed at a slower rate.
Definition: info.hpp:233
#define HEBI_DISABLE_COPY(Class)
Definition: util.hpp:17
Actuator-specific settings, such as controller gains.
Definition: info.hpp:238
A message field representable by a bool value.
Definition: info.hpp:81
Definition: color.hpp:5
const Settings & settings() const
Module settings that are typically changed at a slower rate.
Definition: info.hpp:356
const StringField & name() const
Gets the name for this module.
Definition: info.hpp:308
~Info() noexcept
Cleans up info object as necessary.
Definition: info.cpp:126
const Actuator & actuator() const
Actuator-specific settings, such as controller gains.
Definition: info.hpp:303
Info objects have various fields representing the module state; which fields are populated depends on...
Definition: info.hpp:30
#define HEBI_DISABLE_COPY_MOVE(Class)
Definition: util.hpp:7
A two-state message field (either set/true or cleared/false).
Definition: info.hpp:134
const FloatField & springConstant() const
The spring constant of the module.
Definition: info.hpp:268
A message field for interfacing with an LED.
Definition: info.hpp:199
const InfoGains & effortGains() const
Controller gains for the effort PID loop.
Definition: info.hpp:263
A combination of the position, velocity, and effort loops with P and V feeding to T; documented on do...
const LedField & led() const
The module&#39;s LED.
Definition: info.cpp:140
const InfoGains & velocityGains() const
Controller gains for the velocity PID loop.
Definition: info.hpp:261
A direct PWM value (-1 to 1) can be sent to the motor (subject to onboard safety limiting).
bool has() const
True if (and only if) the field has a value.
Definition: info.hpp:186
const StringField & family() const
Gets the family for this module.
Definition: info.hpp:310
The motor is not given power (equivalent to a 0 PWM value)
ControlStrategy
Definition: info.hpp:33
Info(Info &&other)
Move constructor (necessary for containment in STL template classes)
Definition: info.cpp:119
A message field representable by a std::string.
Definition: info.hpp:101
const EnumField< ControlStrategy > & controlStrategy() const
How the position, velocity, and effort PID loops are connected in order to control motor PWM...
Definition: info.hpp:270
A combination of the position, velocity, and effort loops with P feeding to T and V feeding to PWM; d...
const StringField & serial() const
Gets the serial number for this module (e.g., X5-0001).
Definition: info.hpp:364
A combination of the position, velocity, and effort loops with P, V, and T feeding to PWM; documented...
A message field representable by an enum of a given type.
Definition: info.hpp:165
Structure to describe an RGB color.
Definition: color.hpp:8
A message field representable by a single-precision floating point value.
Definition: info.hpp:49
A message field representable by an enum of a given type.
Definition: command.hpp:287
const InfoGains & positionGains() const
Controller gains for the position PID loop.
Definition: info.hpp:259