HEBI C++ API  1.0.0
feedback.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "hebi.h"
4 #include "color.hpp"
5 #include "vector_3_f.hpp"
6 #include "util.hpp"
7 
8 namespace hebi {
9 
29 class Feedback final
30 {
31  // Note: this is 'protected' instead of 'private' for easier use with Doxygen
32  protected:
34  class FloatField final
35  {
36  public:
37  #ifndef DOXYGEN_OMIT_INTERNAL
38  FloatField(HebiFeedbackPtr internal, HebiFeedbackFloatField field);
39  #endif // DOXYGEN_OMIT_INTERNAL
40  explicit operator bool() const;
54  bool has() const;
57  float get() const;
58 
59  private:
60  HebiFeedbackPtr const internal_;
61  HebiFeedbackFloatField const field_;
62 
64  };
70  class HighResAngleField final
71  {
72  public:
73  #ifndef DOXYGEN_OMIT_INTERNAL
74  HighResAngleField(HebiFeedbackPtr internal, HebiFeedbackHighResAngleField field);
75  #endif // DOXYGEN_OMIT_INTERNAL
76  explicit operator bool() const;
90  bool has() const;
96  double get() const;
108  void get(int64_t* revolutions, float* radian_offset) const;
109 
110  private:
111  HebiFeedbackPtr const internal_;
112  HebiFeedbackHighResAngleField const field_;
113 
115  };
116 
119  class NumberedFloatField final
120  {
121  public:
122  #ifndef DOXYGEN_OMIT_INTERNAL
123  NumberedFloatField(HebiFeedbackPtr internal, HebiFeedbackNumberedFloatField field);
124  #endif // DOXYGEN_OMIT_INTERNAL
125  bool has(size_t fieldNumber) const;
136  float get(size_t fieldNumber) const;
137 
138  private:
139  HebiFeedbackPtr const internal_;
140  HebiFeedbackNumberedFloatField const field_;
141 
143  };
144 
146  class UInt64Field final
147  {
148  public:
149  #ifndef DOXYGEN_OMIT_INTERNAL
150  UInt64Field(HebiFeedbackPtr internal, HebiFeedbackUInt64Field field);
151  #endif // DOXYGEN_OMIT_INTERNAL
152  explicit operator bool() const;
166  bool has() const;
169  uint64_t get() const;
170 
171  private:
172  HebiFeedbackPtr const internal_;
173  HebiFeedbackUInt64Field const field_;
174 
176  };
179  class Vector3fField final
180  {
181  public:
182  #ifndef DOXYGEN_OMIT_INTERNAL
183  Vector3fField(HebiFeedbackPtr internal, HebiFeedbackVector3fField field);
184  #endif // DOXYGEN_OMIT_INTERNAL
185  explicit operator bool() const;
199  bool has() const;
202  Vector3f get() const;
203 
204  private:
205  HebiFeedbackPtr const internal_;
206  HebiFeedbackVector3fField const field_;
207 
209  };
210 
212  class IoBank final
213  {
214  public:
215  #ifndef DOXYGEN_OMIT_INTERNAL
216  IoBank(HebiFeedbackPtr internal, HebiFeedbackIoPinBank bank);
217  #endif // DOXYGEN_OMIT_INTERNAL
218  bool hasInt(size_t pinNumber) const;
229  bool hasFloat(size_t pinNumber) const;
235  int64_t getInt(size_t pinNumber) const;
242  float getFloat(size_t pinNumber) const;
243 
244  private:
245  HebiFeedbackPtr const internal_;
246  HebiFeedbackIoPinBank const bank_;
247 
249  };
251  class LedField final
252  {
253  public:
254  #ifndef DOXYGEN_OMIT_INTERNAL
255  LedField(HebiFeedbackPtr internal, HebiFeedbackLedField field);
256  #endif // DOXYGEN_OMIT_INTERNAL
257  explicit operator bool() const { return hasColor(); }
271  bool hasColor() const;
273  Color getColor() const;
274 
275  private:
276  HebiFeedbackPtr const internal_;
277  HebiFeedbackLedField const field_;
278 
280  };
281 
283  class Io final
284  {
285  public:
286  #ifndef DOXYGEN_OMIT_INTERNAL
287  Io(HebiFeedbackPtr internal)
288  : internal_(internal),
289  a_(internal, HebiFeedbackIoBankA),
290  b_(internal, HebiFeedbackIoBankB),
291  c_(internal, HebiFeedbackIoBankC),
292  d_(internal, HebiFeedbackIoBankD),
293  e_(internal, HebiFeedbackIoBankE),
294  f_(internal, HebiFeedbackIoBankF)
295  {
296  }
297  #endif // DOXYGEN_OMIT_INTERNAL
298 
299  // With all submessage and field getters: Note that the returned reference
300  // should not be used after the lifetime of this parent.
301 
302  // Subfields ----------------
303 
305  const IoBank& a() const { return a_; }
307  const IoBank& b() const { return b_; }
309  const IoBank& c() const { return c_; }
311  const IoBank& d() const { return d_; }
313  const IoBank& e() const { return e_; }
315  const IoBank& f() const { return f_; }
316 
317  private:
318  HebiFeedbackPtr const internal_;
319 
320  IoBank a_;
321  IoBank b_;
322  IoBank c_;
323  IoBank d_;
324  IoBank e_;
325  IoBank f_;
326 
328  };
329 
331  class Actuator final
332  {
333  public:
334  #ifndef DOXYGEN_OMIT_INTERNAL
335  Actuator(HebiFeedbackPtr internal)
336  : internal_(internal),
337  velocity_(internal, HebiFeedbackFloatVelocity),
338  effort_(internal, HebiFeedbackFloatEffort),
339  velocity_command_(internal, HebiFeedbackFloatVelocityCommand),
340  effort_command_(internal, HebiFeedbackFloatEffortCommand),
341  deflection_(internal, HebiFeedbackFloatDeflection),
342  deflection_velocity_(internal, HebiFeedbackFloatDeflectionVelocity),
343  motor_velocity_(internal, HebiFeedbackFloatMotorVelocity),
344  motor_current_(internal, HebiFeedbackFloatMotorCurrent),
345  motor_sensor_temperature_(internal, HebiFeedbackFloatMotorSensorTemperature),
346  motor_winding_current_(internal, HebiFeedbackFloatMotorWindingCurrent),
347  motor_winding_temperature_(internal, HebiFeedbackFloatMotorWindingTemperature),
348  motor_housing_temperature_(internal, HebiFeedbackFloatMotorHousingTemperature),
349  position_(internal, HebiFeedbackHighResAnglePosition),
350  position_command_(internal, HebiFeedbackHighResAnglePositionCommand),
351  sequence_number_(internal, HebiFeedbackUInt64SequenceNumber),
352  receive_time_(internal, HebiFeedbackUInt64ReceiveTime),
353  transmit_time_(internal, HebiFeedbackUInt64TransmitTime),
354  hardware_receive_time_(internal, HebiFeedbackUInt64HardwareReceiveTime),
355  hardware_transmit_time_(internal, HebiFeedbackUInt64HardwareTransmitTime),
356  sender_id_(internal, HebiFeedbackUInt64SenderId)
357  {
358  }
359  #endif // DOXYGEN_OMIT_INTERNAL
360 
361  // With all submessage and field getters: Note that the returned reference
362  // should not be used after the lifetime of this parent.
363 
364  // Subfields ----------------
365 
367  const FloatField& velocity() const { return velocity_; }
369  const FloatField& effort() const { return effort_; }
371  const FloatField& velocityCommand() const { return velocity_command_; }
373  const FloatField& effortCommand() const { return effort_command_; }
375  const FloatField& deflection() const { return deflection_; }
377  const FloatField& deflectionVelocity() const { return deflection_velocity_; }
379  const FloatField& motorVelocity() const { return motor_velocity_; }
381  const FloatField& motorCurrent() const { return motor_current_; }
383  const FloatField& motorSensorTemperature() const { return motor_sensor_temperature_; }
385  const FloatField& motorWindingCurrent() const { return motor_winding_current_; }
387  const FloatField& motorWindingTemperature() const { return motor_winding_temperature_; }
389  const FloatField& motorHousingTemperature() const { return motor_housing_temperature_; }
391  const HighResAngleField& position() const { return position_; }
393  const HighResAngleField& positionCommand() const { return position_command_; }
395  const UInt64Field& sequenceNumber() const { return sequence_number_; }
397  const UInt64Field& receiveTime() const { return receive_time_; }
399  const UInt64Field& transmitTime() const { return transmit_time_; }
401  const UInt64Field& hardwareReceiveTime() const { return hardware_receive_time_; }
403  const UInt64Field& hardwareTransmitTime() const { return hardware_transmit_time_; }
405  const UInt64Field& senderId() const { return sender_id_; }
406 
407  private:
408  HebiFeedbackPtr const internal_;
409 
410  FloatField velocity_;
411  FloatField effort_;
412  FloatField velocity_command_;
413  FloatField effort_command_;
414  FloatField deflection_;
415  FloatField deflection_velocity_;
416  FloatField motor_velocity_;
417  FloatField motor_current_;
418  FloatField motor_sensor_temperature_;
419  FloatField motor_winding_current_;
420  FloatField motor_winding_temperature_;
421  FloatField motor_housing_temperature_;
422  HighResAngleField position_;
423  HighResAngleField position_command_;
424  UInt64Field sequence_number_;
425  UInt64Field receive_time_;
426  UInt64Field transmit_time_;
427  UInt64Field hardware_receive_time_;
428  UInt64Field hardware_transmit_time_;
429  UInt64Field sender_id_;
430 
432  };
433 
435  class Imu final
436  {
437  public:
438  #ifndef DOXYGEN_OMIT_INTERNAL
439  Imu(HebiFeedbackPtr internal)
440  : internal_(internal),
441  accelerometer_(internal, HebiFeedbackVector3fAccelerometer),
442  gyro_(internal, HebiFeedbackVector3fGyro)
443  {
444  }
445  #endif // DOXYGEN_OMIT_INTERNAL
446 
447  // With all submessage and field getters: Note that the returned reference
448  // should not be used after the lifetime of this parent.
449 
450  // Subfields ----------------
451 
453  const Vector3fField& accelerometer() const { return accelerometer_; }
455  const Vector3fField& gyro() const { return gyro_; }
456 
457  private:
458  HebiFeedbackPtr const internal_;
459 
460  Vector3fField accelerometer_;
461  Vector3fField gyro_;
462 
464  };
465 
466  private:
471  HebiFeedbackPtr internal_;
472 
473  public:
474  #ifndef DOXYGEN_OMIT_INTERNAL
475 
479  Feedback(HebiFeedbackPtr );
480  #endif // DOXYGEN_OMIT_INTERNAL
481 
484  Feedback(Feedback&& other);
488  ~Feedback() noexcept; /* annotating specified destructor as noexcept is best-practice */
489 
490  // With all submessage and field getters: Note that the returned reference
491  // should not be used after the lifetime of this parent.
492 
493  // Submessages -------------------------------------------------------------
494 
496  const Io& io() const { return io_; }
498  const Actuator& actuator() const { return actuator_; }
500  const Imu& imu() const { return imu_; }
501 
502  // Subfields -------------------------------------------------------------
503 
505  const FloatField& boardTemperature() const;
507  const FloatField& processorTemperature() const;
509  const FloatField& voltage() const;
510  #ifndef DOXYGEN_OMIT_INTERNAL
511  const NumberedFloatField& debug() const;
513  #endif // DOXYGEN_OMIT_INTERNAL
514  const LedField& led() const;
516 
517  private:
518  Io io_;
519  Actuator actuator_;
520  Imu imu_;
521 
522  FloatField board_temperature_;
523  FloatField processor_temperature_;
524  FloatField voltage_;
525  NumberedFloatField debug_;
526  LedField led_;
527 
532 
533  /* Disable move assigment operator. */
534  Feedback& operator= (const Feedback&& other) = delete;
535 };
536 
537 } // namespace hebi
const Imu & imu() const
Inertial measurement unit feedback (accelerometers and gyros).
Definition: feedback.hpp:500
const UInt64Field & transmitTime() const
Timestamp of when message was transmitted to module (local)
Definition: feedback.hpp:399
Structure to hold a 3-D floating point vector (i.e., x/y/z components)
Definition: vector_3_f.hpp:8
#define HEBI_DISABLE_COPY(Class)
Definition: util.hpp:17
const FloatField & boardTemperature() const
Ambient temperature inside the module (measured at the IMU chip), in degrees Celsius.
Definition: feedback.cpp:227
const FloatField & effortCommand() const
Commanded effort at the module output; units vary (e.g., N * m for rotational joints and N for linear...
Definition: feedback.hpp:373
~Feedback() noexcept
Cleans up feedback object as necessary.
Definition: feedback.cpp:208
const IoBank & c() const
I/O pin bank c (pins 1-8 available)
Definition: feedback.hpp:309
Definition: color.hpp:5
const FloatField & deflectionVelocity() const
Velocity (in radians/second) of the difference between the pre-spring and post-spring output position...
Definition: feedback.hpp:377
const UInt64Field & hardwareTransmitTime() const
Timestamp of when message was transmitted from module (remote)
Definition: feedback.hpp:403
const FloatField & motorSensorTemperature() const
The temperature from a sensor near the motor housing.
Definition: feedback.hpp:383
const FloatField & motorWindingTemperature() const
The estimated temperature of the motor windings.
Definition: feedback.hpp:387
const UInt64Field & sequenceNumber() const
Sequence number going to module (local)
Definition: feedback.hpp:395
const IoBank & d() const
I/O pin bank d (pins 1-8 available)
Definition: feedback.hpp:311
const FloatField & motorWindingCurrent() const
The estimated current in the motor windings.
Definition: feedback.hpp:385
const UInt64Field & hardwareReceiveTime() const
Timestamp of when message was received by module (remote)
Definition: feedback.hpp:401
#define HEBI_DISABLE_COPY_MOVE(Class)
Definition: util.hpp:7
A message field representable by a single-precision floating point value.
Definition: feedback.hpp:34
const FloatField & motorHousingTemperature() const
The estimated temperature of the motor housing.
Definition: feedback.hpp:389
Inertial measurement unit feedback (accelerometers and gyros).
Definition: feedback.hpp:435
Feedback objects have various fields representing feedback from modules; which fields are populated d...
Definition: feedback.hpp:29
A message field for interfacing with a bank of I/O pins.
Definition: feedback.hpp:212
const UInt64Field & receiveTime() const
Timestamp of when message was received from module (local)
Definition: feedback.hpp:397
const FloatField & motorVelocity() const
The velocity (in radians/second) of the motor shaft.
Definition: feedback.hpp:379
const HighResAngleField & position() const
Position of the module output (post-spring), in radians.
Definition: feedback.hpp:391
const LedField & led() const
The module's LED.
Definition: feedback.cpp:243
A message field for an angle measurement which does not lose precision at very high angles...
Definition: feedback.hpp:70
bool has() const
True if (and only if) the field has a value.
Definition: feedback.cpp:20
const FloatField & deflection() const
Difference (in radians) between the pre-spring and post-spring output position.
Definition: feedback.hpp:375
const Actuator & actuator() const
Actuator-specific feedback.
Definition: feedback.hpp:498
const IoBank & e() const
I/O pin bank e (pins 1-8 available)
Definition: feedback.hpp:313
const FloatField & velocityCommand() const
Commanded velocity of the module output (post-spring), in radians/second.
Definition: feedback.hpp:371
A message field for interfacing with an LED.
Definition: feedback.hpp:251
const FloatField & voltage() const
Bus voltage that the module is running at (in Volts).
Definition: feedback.cpp:235
const FloatField & motorCurrent() const
Current supplied to the motor.
Definition: feedback.hpp:381
const IoBank & f() const
I/O pin bank f (pins 1-8 available)
Definition: feedback.hpp:315
Feedback from any available I/O pins on the device.
Definition: feedback.hpp:283
A message field representable by an unsigned 64 bit integer value.
Definition: feedback.hpp:146
const UInt64Field & senderId() const
Unique ID of the module transmitting this feedback.
Definition: feedback.hpp:405
const IoBank & a() const
I/O pin bank a (pins 1-8 available)
Definition: feedback.hpp:305
const FloatField & processorTemperature() const
Temperature of the processor chip, in degrees Celsius.
Definition: feedback.cpp:231
Actuator-specific feedback.
Definition: feedback.hpp:331
const Io & io() const
Feedback from any available I/O pins on the device.
Definition: feedback.hpp:496
const Vector3fField & accelerometer() const
Accelerometer data, in m/s^2.
Definition: feedback.hpp:453
Feedback(Feedback &&other)
Move constructor (necessary for containment in STL template classes)
Definition: feedback.cpp:196
const IoBank & b() const
I/O pin bank b (pins 1-8 available)
Definition: feedback.hpp:307
const HighResAngleField & positionCommand() const
Commanded position of the module output (post-spring), in radians.
Definition: feedback.hpp:393
Structure to describe an RGB color.
Definition: color.hpp:8
const FloatField & velocity() const
Velocity of the module output (post-spring), in radians/second.
Definition: feedback.hpp:367
A message field containing a numbered set of single-precision floating point values.
Definition: feedback.hpp:119
A message field representable by a 3-D vector of single-precision floating point values.
Definition: feedback.hpp:179
const FloatField & effort() const
Effort at the module output; units vary (e.g., N * m for rotational joints and N for linear stages)...
Definition: feedback.hpp:369
const Vector3fField & gyro() const
Gyro data, in radians/second.
Definition: feedback.hpp:455