HEBI C++ API  2.2.0
info.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "hebi.h"
4 
5 #include <string>
6 
7 #include "color.hpp"
8 #include "gains.hpp"
9 #include "util.hpp"
10 
11 namespace hebi {
12 
32 class Info final {
33 public:
34  enum class ControlStrategy {
36  Off,
38  DirectPWM,
41  Strategy2,
44  Strategy3,
47  Strategy4,
48  };
49 
50  enum class CalibrationState {
52  Normal,
59  };
60 
61  enum class MstopStrategy {
63  Disabled,
65  MotorOff,
68  };
69 
70  enum class PositionLimitStrategy {
76  MotorOff,
78  Disabled,
79  };
80 
81 protected:
83  class FloatField final {
84  public:
85 #ifndef DOXYGEN_OMIT_INTERNAL
86  FloatField(HebiInfoPtr internal, HebiInfoFloatField field);
87 #endif // DOXYGEN_OMIT_INTERNAL
88  explicit operator bool() const { return has(); }
102  bool has() const;
105  float get() const;
106 
108  private:
109  HebiInfoPtr const internal_;
110  HebiInfoFloatField const field_;
111  };
112 
118  class HighResAngleField final {
119  public:
120 #ifndef DOXYGEN_OMIT_INTERNAL
121  HighResAngleField(HebiInfoPtr internal, HebiInfoHighResAngleField field);
122 #endif // DOXYGEN_OMIT_INTERNAL
123  explicit operator bool() const { return has(); }
137  bool has() const;
143  double get() const;
155  void get(int64_t* revolutions, float* radian_offset) const;
156 
158  private:
159  HebiInfoPtr const internal_;
160  HebiInfoHighResAngleField const field_;
161  };
162 
164  class BoolField final {
165  public:
166 #ifndef DOXYGEN_OMIT_INTERNAL
167  BoolField(HebiInfoPtr internal, HebiInfoBoolField field);
168 #endif // DOXYGEN_OMIT_INTERNAL
169  bool has() const;
173  bool get() const;
174 
176  private:
177  HebiInfoPtr const internal_;
178  HebiInfoBoolField const field_;
179  };
180 
182  class StringField final {
183  public:
184 #ifndef DOXYGEN_OMIT_INTERNAL
185  StringField(HebiInfoPtr internal, HebiInfoStringField field);
186 #endif // DOXYGEN_OMIT_INTERNAL
187  explicit operator bool() const { return has(); }
201  bool has() const;
204  std::string get() const;
205 
207  private:
208  HebiInfoPtr const internal_;
209  HebiInfoStringField const field_;
210  };
211 
213  class FlagField final {
214  public:
215 #ifndef DOXYGEN_OMIT_INTERNAL
216  FlagField(HebiInfoPtr internal, HebiInfoFlagField field);
217 #endif // DOXYGEN_OMIT_INTERNAL
218  explicit operator bool() const { return has(); }
232  bool has() const;
233 
235  private:
236  HebiInfoPtr const internal_;
237  HebiInfoFlagField const field_;
238  };
239 
241  template<typename T>
242  class EnumField final {
243  public:
244 #ifndef DOXYGEN_OMIT_INTERNAL
245  EnumField(HebiInfoPtr internal, HebiInfoEnumField field) : internal_(internal), field_(field) {}
246 #endif // DOXYGEN_OMIT_INTERNAL
247  explicit operator bool() const { return has(); }
261  bool has() const { return (hebiInfoGetEnum(internal_, field_, nullptr) == HebiStatusSuccess); }
264  T get() const {
265  int32_t ret{};
266  hebiInfoGetEnum(internal_, field_, &ret);
267  return static_cast<T>(ret);
268  }
269 
271  private:
272  HebiInfoPtr const internal_;
273  HebiInfoEnumField const field_;
274  };
275 
277  class LedField final {
278  public:
279 #ifndef DOXYGEN_OMIT_INTERNAL
280  LedField(HebiInfoPtr internal, HebiInfoLedField field);
281 #endif // DOXYGEN_OMIT_INTERNAL
282  explicit operator bool() const { return hasColor(); }
296  bool hasColor() const;
298  Color getColor() const;
299 
301  private:
302  HebiInfoPtr const internal_;
303  HebiInfoLedField const field_;
304  };
305 
307 
309  class Settings final {
310  protected:
312  class Actuator final {
313  public:
314 #ifndef DOXYGEN_OMIT_INTERNAL
315  Actuator(HebiInfoPtr internal)
316  : internal_(internal),
317  position_gains_(internal, HebiInfoFloatPositionKp, HebiInfoBoolPositionDOnError),
318  velocity_gains_(internal, HebiInfoFloatVelocityKp, HebiInfoBoolVelocityDOnError),
319  effort_gains_(internal, HebiInfoFloatEffortKp, HebiInfoBoolEffortDOnError),
320  spring_constant_(internal, HebiInfoFloatSpringConstant),
321  velocity_limit_min_(internal, HebiInfoFloatVelocityLimitMin),
322  velocity_limit_max_(internal, HebiInfoFloatVelocityLimitMax),
323  effort_limit_min_(internal, HebiInfoFloatEffortLimitMin),
324  effort_limit_max_(internal, HebiInfoFloatEffortLimitMax),
325  position_limit_min_(internal, HebiInfoHighResAnglePositionLimitMin),
326  position_limit_max_(internal, HebiInfoHighResAnglePositionLimitMax),
327  control_strategy_(internal, HebiInfoEnumControlStrategy),
328  mstop_strategy_(internal, HebiInfoEnumMstopStrategy),
329  min_position_limit_strategy_(internal, HebiInfoEnumMinPositionLimitStrategy),
330  max_position_limit_strategy_(internal, HebiInfoEnumMaxPositionLimitStrategy) {}
331 #endif // DOXYGEN_OMIT_INTERNAL
332 
333  // With all submessage and field getters: Note that the returned reference
334  // should not be used after the lifetime of this parent.
335 
336  // Submessages ----------------
337 
339  const InfoGains& positionGains() const { return position_gains_; }
341  const InfoGains& velocityGains() const { return velocity_gains_; }
343  const InfoGains& effortGains() const { return effort_gains_; }
344 
345  // Subfields ----------------
346 
348  const FloatField& springConstant() const { return spring_constant_; }
350  const FloatField& velocityLimitMin() const { return velocity_limit_min_; }
352  const FloatField& velocityLimitMax() const { return velocity_limit_max_; }
354  const FloatField& effortLimitMin() const { return effort_limit_min_; }
356  const FloatField& effortLimitMax() const { return effort_limit_max_; }
358  const HighResAngleField& positionLimitMin() const { return position_limit_min_; }
360  const HighResAngleField& positionLimitMax() const { return position_limit_max_; }
362  const EnumField<ControlStrategy>& controlStrategy() const { return control_strategy_; }
364  const EnumField<MstopStrategy>& mstopStrategy() const { return mstop_strategy_; }
366  const EnumField<PositionLimitStrategy>& minPositionLimitStrategy() const { return min_position_limit_strategy_; }
368  const EnumField<PositionLimitStrategy>& maxPositionLimitStrategy() const { return max_position_limit_strategy_; }
369 
371  private:
372  HebiInfoPtr const internal_;
373 
374  InfoGains position_gains_;
375  InfoGains velocity_gains_;
376  InfoGains effort_gains_;
377 
378  FloatField spring_constant_;
379  FloatField velocity_limit_min_;
380  FloatField velocity_limit_max_;
381  FloatField effort_limit_min_;
382  FloatField effort_limit_max_;
383  HighResAngleField position_limit_min_;
384  HighResAngleField position_limit_max_;
385  EnumField<ControlStrategy> control_strategy_;
386  EnumField<MstopStrategy> mstop_strategy_;
387  EnumField<PositionLimitStrategy> min_position_limit_strategy_;
388  EnumField<PositionLimitStrategy> max_position_limit_strategy_;
389  };
390 
392  class Imu final {
393  public:
394 #ifndef DOXYGEN_OMIT_INTERNAL
395  Imu(HebiInfoPtr internal)
396  : internal_(internal), accel_includes_gravity_(internal, HebiInfoBoolAccelIncludesGravity) {}
397 #endif // DOXYGEN_OMIT_INTERNAL
398 
399  // With all submessage and field getters: Note that the returned reference
400  // should not be used after the lifetime of this parent.
401 
402  // Subfields ----------------
403 
405  const BoolField& accelIncludesGravity() const { return accel_includes_gravity_; }
406 
408  private:
409  HebiInfoPtr const internal_;
410 
411  BoolField accel_includes_gravity_;
412  };
413 
414  public:
415 #ifndef DOXYGEN_OMIT_INTERNAL
416  Settings(HebiInfoPtr internal)
417  : internal_(internal),
418  actuator_(internal),
419  imu_(internal),
420  name_(internal, HebiInfoStringName),
421  family_(internal, HebiInfoStringFamily),
422  save_current_settings_(internal, HebiInfoFlagSaveCurrentSettings) {}
423 #endif // DOXYGEN_OMIT_INTERNAL
424 
425  // With all submessage and field getters: Note that the returned reference
426  // should not be used after the lifetime of this parent.
427 
428  // Submessages ----------------
429 
431  const Actuator& actuator() const { return actuator_; }
433  const Imu& imu() const { return imu_; }
434 
435  // Subfields ----------------
436 
438  const StringField& name() const { return name_; }
440  const StringField& family() const { return family_; }
442  const FlagField& saveCurrentSettings() const { return save_current_settings_; }
443 
445  private:
446  HebiInfoPtr const internal_;
447 
448  Actuator actuator_;
449  Imu imu_;
450 
451  StringField name_;
452  StringField family_;
453  FlagField save_current_settings_;
454  };
455 
457  class Actuator final {
458  public:
459 #ifndef DOXYGEN_OMIT_INTERNAL
460  Actuator(HebiInfoPtr internal) : internal_(internal), calibration_state_(internal, HebiInfoEnumCalibrationState) {}
461 #endif // DOXYGEN_OMIT_INTERNAL
462 
463  // With all submessage and field getters: Note that the returned reference
464  // should not be used after the lifetime of this parent.
465 
466  // Subfields ----------------
467 
469  const EnumField<CalibrationState>& calibrationState() const { return calibration_state_; }
470 
472  private:
473  HebiInfoPtr const internal_;
474 
475  EnumField<CalibrationState> calibration_state_;
476  };
477 
478 private:
483  HebiInfoPtr internal_;
484 
485 public:
486 #ifndef DOXYGEN_OMIT_INTERNAL
487 
491  Info(HebiInfoPtr);
492 #endif // DOXYGEN_OMIT_INTERNAL
493 
496  Info(Info&& other);
497 
498  // With all submessage and field getters: Note that the returned reference
499  // should not be used after the lifetime of this parent.
500 
501  // Submessages -------------------------------------------------------------
502 
504  const Settings& settings() const { return settings_; }
506  const Actuator& actuator() const { return actuator_; }
507 
508  // Subfields -------------------------------------------------------------
509 
511  const StringField& serial() const { return serial_; }
513  const LedField& led() const { return led_; }
514 
519 
520  /* Disable move assigment operator. */
521  Info& operator=(Info&& other) = delete;
522 
523 private:
524  Settings settings_;
525  Actuator actuator_;
526 
527  StringField serial_;
528  LedField led_;
529 };
530 
531 } // namespace hebi
const FlagField & saveCurrentSettings() const
Indicates if the module should save the current values of all of its settings.
Definition: info.hpp:442
std::string get() const
If the field has a value, returns a copy of that value; otherwise, returns a default.
Definition: info.cpp:60
const HighResAngleField & positionLimitMin() const
The firmware safety limit for the minimum allowed position.
Definition: info.hpp:358
Module settings that are typically changed at a slower rate.
Definition: info.hpp:309
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:56
A message field for an angle measurement which does not lose precision at very high angles.
Definition: info.hpp:118
#define HEBI_DISABLE_COPY(Class)
Definition: util.hpp:16
Actuator-specific settings, such as controller gains.
Definition: info.hpp:312
const FloatField & effortLimitMin() const
The firmware safety limit for the minimum allowed effort.
Definition: info.hpp:354
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:44
const LedField & led() const
The module's LED.
Definition: info.hpp:513
const FloatField & springConstant() const
The spring constant of the module.
Definition: info.hpp:348
T get() const
If the field has a value, returns that value; otherwise, returns a default.
Definition: info.hpp:264
const FloatField & effortLimitMax() const
The firmware safety limit for the maximum allowed effort.
Definition: info.hpp:356
const EnumField< ControlStrategy > & controlStrategy() const
How the position, velocity, and effort PID loops are connected in order to control motor PWM.
Definition: info.hpp:362
PositionLimitStrategy
Definition: info.hpp:70
A message field representable by a bool value.
Definition: info.hpp:164
Definition: color.hpp:5
const HighResAngleField & positionLimitMax() const
The firmware safety limit for the maximum allowed position.
Definition: info.hpp:360
Actuator-specific information.
Definition: info.hpp:457
const EnumField< CalibrationState > & calibrationState() const
The calibration state of the module.
Definition: info.hpp:469
const Actuator & actuator() const
Actuator-specific settings, such as controller gains.
Definition: info.hpp:431
const InfoGains & effortGains() const
Controller gains for the effort PID loop.
Definition: info.hpp:343
Info objects have various fields representing the module state; which fields are populated depends on...
Definition: info.hpp:32
const StringField & serial() const
Gets the serial number for this module (e.g., X5-0001).
Definition: info.hpp:511
MstopStrategy
Definition: info.hpp:61
CalibrationState
Definition: info.hpp:50
#define HEBI_DISABLE_COPY_MOVE(Class)
Definition: util.hpp:6
const Imu & imu() const
IMU-specific settings.
Definition: info.hpp:433
const InfoGains & positionGains() const
Controller gains for the position PID loop.
Definition: info.hpp:339
const Actuator & actuator() const
Actuator-specific information.
Definition: info.hpp:506
A two-state message field (either set/true or cleared/false).
Definition: info.hpp:213
const BoolField & accelIncludesGravity() const
Whether to include acceleration due to gravity in acceleration feedback.
Definition: info.hpp:405
A message field for interfacing with an LED.
Definition: info.hpp:277
const FloatField & velocityLimitMin() const
The firmware safety limit for the minimum allowed velocity.
Definition: info.hpp:350
const InfoGains & velocityGains() const
Controller gains for the velocity PID loop.
Definition: info.hpp:341
Triggering the M-Stop results in the control strategy being set to 'off'. Remains 'off' until changed...
const Settings & settings() const
Module settings that are typically changed at a slower rate.
Definition: info.hpp:504
A direct PWM value (-1 to 1) can be sent to the motor (subject to onboard safety limiting).
The effort (e.g., spring nonlinearity) has not been calibrated.
The motor is not given power (equivalent to a 0 PWM value)
The current has not been calibrated.
Info & operator=(Info &&other)=delete
ControlStrategy
Definition: info.hpp:34
Info(Info &&other)
Move constructor (necessary for containment in STL template classes)
Definition: info.cpp:94
double get() const
If the field has a value, returns that value as a double; otherwise, returns a default.
Definition: info.cpp:26
A message field representable by a std::string.
Definition: info.hpp:182
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:9
const StringField & family() const
Gets the family for this module.
Definition: info.hpp:440
Color getColor() const
Returns the led color.
Definition: info.cpp:84
Exceeding the position limit results in the control strategy being set to 'off'. Remains 'off' until ...
float get() const
If the field has a value, returns that value; otherwise, returns a default.
Definition: info.cpp:11
const FloatField & velocityLimitMax() const
The firmware safety limit for the maximum allowed velocity.
Definition: info.hpp:352
const StringField & name() const
Gets the name for this module.
Definition: info.hpp:438
The module has been calibrated; this is the normal state.
bool hasColor() const
Returns true if the LED color is set, and false otherwise.
Definition: info.cpp:80
Triggering the M-Stop has no effect.
const EnumField< PositionLimitStrategy > & minPositionLimitStrategy() const
The position limit strategy (at the minimum position) for the actuator.
Definition: info.hpp:366
bool get() const
If the field has a value, returns that value; otherwise, returns false.
Definition: info.cpp:46
const EnumField< PositionLimitStrategy > & maxPositionLimitStrategy() const
The position limit strategy (at the maximum position) for the actuator.
Definition: info.hpp:368
Exceeding the position limit has no effect.
A message field representable by an enum of a given type.
Definition: info.hpp:242
Structure to describe an RGB color.
Definition: color.hpp:8
IMU-specific settings.
Definition: info.hpp:392
Exceeding the position limit results in the actuator holding the position. Needs to be manually set t...
Exceeding the position limit results in a virtual spring that pushes the actuator back to within the ...
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:22
const EnumField< MstopStrategy > & mstopStrategy() const
The motion stop strategy for the actuator.
Definition: info.hpp:364
bool has() const
Returns true if the flag is set, false if it is cleared.
Definition: info.cpp:76
Triggering the M-Stop results in the motor holding the motor position. Operations resume to normal on...
A message field representable by a single-precision floating point value.
Definition: info.hpp:83
The factory zero position has not been set.
bool has() const
True if (and only if) the field has a value.
Definition: info.hpp:261