HEBI C++ API  1.0.0-rc1
feedback.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "hebi_feedback.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(int fieldNumber) const;
136  float get(int 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(int pinNumber) const;
229  bool hasFloat(int pinNumber) const;
235  int64_t getInt(int pinNumber) const;
242  float getFloat(int 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  {
357  }
358  #endif // DOXYGEN_OMIT_INTERNAL
359 
360  // With all submessage and field getters: Note that the returned reference
361  // should not be used after the lifetime of this parent.
362 
363  // Subfields ----------------
364 
366  const FloatField& velocity() const { return velocity_; }
368  const FloatField& effort() const { return effort_; }
370  const FloatField& velocityCommand() const { return velocity_command_; }
372  const FloatField& effortCommand() const { return effort_command_; }
374  const FloatField& deflection() const { return deflection_; }
376  const FloatField& deflectionVelocity() const { return deflection_velocity_; }
378  const FloatField& motorVelocity() const { return motor_velocity_; }
380  const FloatField& motorCurrent() const { return motor_current_; }
382  const FloatField& motorSensorTemperature() const { return motor_sensor_temperature_; }
384  const FloatField& motorWindingCurrent() const { return motor_winding_current_; }
386  const FloatField& motorWindingTemperature() const { return motor_winding_temperature_; }
388  const FloatField& motorHousingTemperature() const { return motor_housing_temperature_; }
390  const HighResAngleField& position() const { return position_; }
392  const HighResAngleField& positionCommand() const { return position_command_; }
394  const UInt64Field& sequenceNumber() const { return sequence_number_; }
396  const UInt64Field& receiveTime() const { return receive_time_; }
398  const UInt64Field& transmitTime() const { return transmit_time_; }
400  const UInt64Field& hardwareReceiveTime() const { return hardware_receive_time_; }
402  const UInt64Field& hardwareTransmitTime() const { return hardware_transmit_time_; }
403 
404  private:
405  HebiFeedbackPtr const internal_;
406 
407  FloatField velocity_;
408  FloatField effort_;
409  FloatField velocity_command_;
410  FloatField effort_command_;
411  FloatField deflection_;
412  FloatField deflection_velocity_;
413  FloatField motor_velocity_;
414  FloatField motor_current_;
415  FloatField motor_sensor_temperature_;
416  FloatField motor_winding_current_;
417  FloatField motor_winding_temperature_;
418  FloatField motor_housing_temperature_;
419  HighResAngleField position_;
420  HighResAngleField position_command_;
421  UInt64Field sequence_number_;
422  UInt64Field receive_time_;
423  UInt64Field transmit_time_;
424  UInt64Field hardware_receive_time_;
425  UInt64Field hardware_transmit_time_;
426 
428  };
429 
431  class Imu final
432  {
433  public:
434  #ifndef DOXYGEN_OMIT_INTERNAL
435  Imu(HebiFeedbackPtr internal)
436  : internal_(internal),
437  accelerometer_(internal, HebiFeedbackVector3fAccelerometer),
438  gyro_(internal, HebiFeedbackVector3fGyro)
439  {
440  }
441  #endif // DOXYGEN_OMIT_INTERNAL
442 
443  // With all submessage and field getters: Note that the returned reference
444  // should not be used after the lifetime of this parent.
445 
446  // Subfields ----------------
447 
449  const Vector3fField& accelerometer() const { return accelerometer_; }
451  const Vector3fField& gyro() const { return gyro_; }
452 
453  private:
454  HebiFeedbackPtr const internal_;
455 
456  Vector3fField accelerometer_;
457  Vector3fField gyro_;
458 
460  };
461 
462  private:
467  HebiFeedbackPtr internal_;
468 
469  public:
470  #ifndef DOXYGEN_OMIT_INTERNAL
471 
475  Feedback(HebiFeedbackPtr );
476  #endif // DOXYGEN_OMIT_INTERNAL
477 
480  Feedback(Feedback&& other);
484  virtual ~Feedback() noexcept; /* annotating specified destructor as noexcept is best-practice */
485 
486  // With all submessage and field getters: Note that the returned reference
487  // should not be used after the lifetime of this parent.
488 
489  // Submessages -------------------------------------------------------------
490 
492  const Io& io() const { return io_; }
494  const Actuator& actuator() const { return actuator_; }
496  const Imu& imu() const { return imu_; }
497 
498  // Subfields -------------------------------------------------------------
499 
501  const FloatField& boardTemperature() const;
503  const FloatField& processorTemperature() const;
505  const FloatField& voltage() const;
506  #ifndef DOXYGEN_OMIT_INTERNAL
507  const NumberedFloatField& debug() const;
509  #endif // DOXYGEN_OMIT_INTERNAL
510  const LedField& led() const;
512 
513  private:
514  Io io_;
515  Actuator actuator_;
516  Imu imu_;
517 
518  FloatField board_temperature_;
519  FloatField processor_temperature_;
520  FloatField voltage_;
521  NumberedFloatField debug_;
522  LedField led_;
523 
528 
529  /* Disable move assigment operator. */
530  Feedback& operator= (const Feedback&& other) = delete;
531 };
532 
533 } // namespace hebi
const Imu & imu() const
Inertial measurement unit feedback (accelerometers and gyros).
Definition: feedback.hpp:496
const UInt64Field & transmitTime() const
Timestamp of when message was transmitted to module (local)
Definition: feedback.hpp:398
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:222
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:372
virtual ~Feedback() noexcept
Cleans up feedback object as necessary.
Definition: feedback.cpp:203
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:376
const UInt64Field & hardwareTransmitTime() const
Timestamp of when message was transmitted from module (remote)
Definition: feedback.hpp:402
const FloatField & motorSensorTemperature() const
The temperature from a sensor near the motor housing.
Definition: feedback.hpp:382
const FloatField & motorWindingTemperature() const
The estimated temperature of the motor windings.
Definition: feedback.hpp:386
const UInt64Field & sequenceNumber() const
Sequence number going to module (local)
Definition: feedback.hpp:394
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:384
const UInt64Field & hardwareReceiveTime() const
Timestamp of when message was received by module (remote)
Definition: feedback.hpp:400
#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:388
Inertial measurement unit feedback (accelerometers and gyros).
Definition: feedback.hpp:431
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:396
const FloatField & motorVelocity() const
The velocity (in radians/second) of the motor shaft.
Definition: feedback.hpp:378
const HighResAngleField & position() const
Position of the module output (post-spring), in radians.
Definition: feedback.hpp:390
const LedField & led() const
The module's LED.
Definition: feedback.cpp:238
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:374
const Actuator & actuator() const
Actuator-specific feedback.
Definition: feedback.hpp:494
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:370
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:230
const FloatField & motorCurrent() const
Current supplied to the motor.
Definition: feedback.hpp:380
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 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:226
Actuator-specific feedback.
Definition: feedback.hpp:331
const Io & io() const
Feedback from any available I/O pins on the device.
Definition: feedback.hpp:492
const Vector3fField & accelerometer() const
Accelerometer data, in m/s^2.
Definition: feedback.hpp:449
Feedback(Feedback &&other)
Move constructor (necessary for containment in STL template classes)
Definition: feedback.cpp:191
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:392
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:366
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:368
const Vector3fField & gyro() const
Gyro data, in radians/second.
Definition: feedback.hpp:451