command.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 Command 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
54  #endif // DOXYGEN_OMIT_INTERNAL
55  explicit operator bool() const;
69  bool has() const;
72  float get() const;
74  void set(float value);
76  void clear();
77 
78  private:
81 
83  };
89  class HighResAngleField final
90  {
91  public:
92  #ifndef DOXYGEN_OMIT_INTERNAL
94  #endif // DOXYGEN_OMIT_INTERNAL
95  explicit operator bool() const;
109  bool has() const;
115  double get() const;
127  void get(int64_t* revolutions, float* radian_offset) const;
132  void set(double radians);
139  void set(int64_t revolutions, float radian_offset);
141  void clear();
142 
143  private:
146 
148  };
149 
152  class NumberedFloatField final
153  {
154  public:
155  #ifndef DOXYGEN_OMIT_INTERNAL
157  #endif // DOXYGEN_OMIT_INTERNAL
158  bool has(size_t fieldNumber) const;
169  float get(size_t fieldNumber) const;
175  void set(size_t fieldNumber, float value);
181  void clear(size_t fieldNumber);
182 
183  private:
186 
188  };
189 
191  class BoolField final
192  {
193  public:
194  #ifndef DOXYGEN_OMIT_INTERNAL
196  #endif // DOXYGEN_OMIT_INTERNAL
197  bool has() const;
201  bool get() const;
203  void set(bool value);
205  void clear();
206 
207  private:
210 
212  };
213 
215  class StringField final
216  {
217  public:
218  #ifndef DOXYGEN_OMIT_INTERNAL
220  #endif // DOXYGEN_OMIT_INTERNAL
221  explicit operator bool() const;
235  bool has() const;
238  std::string get() const;
240  void set(const std::string& value);
242  void clear();
243 
244  private:
247 
249  };
250 
252  class FlagField final
253  {
254  public:
255  #ifndef DOXYGEN_OMIT_INTERNAL
257  #endif // DOXYGEN_OMIT_INTERNAL
258  explicit operator bool() const;
272  bool has() const;
274  void set();
276  void clear();
277 
278  private:
281 
283  };
284 
286  template <typename T>
287  class EnumField final
288  {
289  public:
290  #ifndef DOXYGEN_OMIT_INTERNAL
292  : internal_(internal), field_(field) {}
293  #endif // DOXYGEN_OMIT_INTERNAL
294  explicit operator bool() const { return has(); }
308  bool has() const { return (hebiCommandGetEnum(internal_, field_, nullptr) == HebiStatusSuccess); }
311  T get() const { int32_t ret{}; hebiCommandGetEnum(internal_, field_, &ret); return static_cast<T>(ret); }
313  void set(T _value) { int32_t value = static_cast<int32_t>(_value); hebiCommandSetEnum(internal_, field_, &value); }
315  void clear() { hebiCommandSetEnum(internal_, field_, nullptr); }
316 
317  private:
320 
322  };
323 
325  class IoBank final
326  {
327  public:
328  #ifndef DOXYGEN_OMIT_INTERNAL
330  #endif // DOXYGEN_OMIT_INTERNAL
331  bool hasInt(size_t pinNumber) const;
342  bool hasFloat(size_t pinNumber) const;
348  int64_t getInt(size_t pinNumber) const;
355  float getFloat(size_t pinNumber) const;
361  void setInt(size_t pinNumber, int64_t value);
367  void setFloat(size_t pinNumber, float value);
372  void clear(size_t pinNumber);
373 
374  private:
377 
379  };
381  class LedField final
382  {
383  public:
384  #ifndef DOXYGEN_OMIT_INTERNAL
386  #endif // DOXYGEN_OMIT_INTERNAL
387  bool has() const;
402  Color get() const;
408  void set(const Color& color);
413  void clear();
414 
415  private:
418 
420  };
421 
423  class Io final
424  {
425  public:
426  #ifndef DOXYGEN_OMIT_INTERNAL
427  Io(HebiCommandPtr internal)
428  : internal_(internal),
435  {
436  }
437  #endif // DOXYGEN_OMIT_INTERNAL
438 
439  // With all submessage and field getters: Note that the returned reference
440  // should not be used after the lifetime of this parent.
441 
442  // Subfields ----------------
443 
445  IoBank& a() { return a_; }
447  const IoBank& a() const { return a_; }
449  IoBank& b() { return b_; }
451  const IoBank& b() const { return b_; }
453  IoBank& c() { return c_; }
455  const IoBank& c() const { return c_; }
457  IoBank& d() { return d_; }
459  const IoBank& d() const { return d_; }
461  IoBank& e() { return e_; }
463  const IoBank& e() const { return e_; }
465  IoBank& f() { return f_; }
467  const IoBank& f() const { return f_; }
468 
469  private:
471 
478 
480  };
481 
483 
485  class Settings final
486  {
487  // Note: this is 'protected' instead of 'private' for easier use with Doxygen
488  protected:
490  class Actuator final
491  {
492  public:
493  #ifndef DOXYGEN_OMIT_INTERNAL
495  : internal_(internal),
499  spring_constant_(internal, HebiCommandFloatSpringConstant),
500  reference_position_(internal, HebiCommandFloatReferencePosition),
501  reference_effort_(internal, HebiCommandFloatReferenceEffort),
504  control_strategy_(internal, HebiCommandEnumControlStrategy)
505  {
506  }
507  #endif // DOXYGEN_OMIT_INTERNAL
508 
509  // With all submessage and field getters: Note that the returned reference
510  // should not be used after the lifetime of this parent.
511 
512  // Submessages ----------------
513 
515  CommandGains& positionGains() { return position_gains_; }
517  const CommandGains& positionGains() const { return position_gains_; }
519  CommandGains& velocityGains() { return velocity_gains_; }
521  const CommandGains& velocityGains() const { return velocity_gains_; }
523  CommandGains& effortGains() { return effort_gains_; }
525  const CommandGains& effortGains() const { return effort_gains_; }
526 
527  // Subfields ----------------
528 
530  FloatField& springConstant() { return spring_constant_; }
532  const FloatField& springConstant() const { return spring_constant_; }
534  FloatField& referencePosition() { return reference_position_; }
536  const FloatField& referencePosition() const { return reference_position_; }
538  FloatField& referenceEffort() { return reference_effort_; }
540  const FloatField& referenceEffort() const { return reference_effort_; }
542  HighResAngleField& positionLimitMin() { return position_limit_min_; }
544  const HighResAngleField& positionLimitMin() const { return position_limit_min_; }
546  HighResAngleField& positionLimitMax() { return position_limit_max_; }
548  const HighResAngleField& positionLimitMax() const { return position_limit_max_; }
550  EnumField<ControlStrategy>& controlStrategy() { return control_strategy_; }
552  const EnumField<ControlStrategy>& controlStrategy() const { return control_strategy_; }
553 
554  private:
556 
560 
567 
569  };
570 
571  public:
572  #ifndef DOXYGEN_OMIT_INTERNAL
574  : internal_(internal),
578  save_current_settings_(internal, HebiCommandFlagSaveCurrentSettings)
579  {
580  }
581  #endif // DOXYGEN_OMIT_INTERNAL
582 
583  // With all submessage and field getters: Note that the returned reference
584  // should not be used after the lifetime of this parent.
585 
586  // Submessages ----------------
587 
589  Actuator& actuator() { return actuator_; }
591  const Actuator& actuator() const { return actuator_; }
592 
593  // Subfields ----------------
594 
596  StringField& name() { return name_; }
598  const StringField& name() const { return name_; }
600  StringField& family() { return family_; }
602  const StringField& family() const { return family_; }
604  FlagField& saveCurrentSettings() { return save_current_settings_; }
606  const FlagField& saveCurrentSettings() const { return save_current_settings_; }
607 
608  private:
610 
612 
616 
618  };
619 
621  class Actuator final
622  {
623  public:
624  #ifndef DOXYGEN_OMIT_INTERNAL
626  : internal_(internal),
630  {
631  }
632  #endif // DOXYGEN_OMIT_INTERNAL
633 
634  // With all submessage and field getters: Note that the returned reference
635  // should not be used after the lifetime of this parent.
636 
637  // Subfields ----------------
638 
640  FloatField& velocity() { return velocity_; }
642  const FloatField& velocity() const { return velocity_; }
644  FloatField& effort() { return effort_; }
646  const FloatField& effort() const { return effort_; }
648  HighResAngleField& position() { return position_; }
650  const HighResAngleField& position() const { return position_; }
651 
652  private:
654 
658 
660  };
661 
662  private:
668 
669  public:
670  #ifndef DOXYGEN_OMIT_INTERNAL
671 
676  #endif // DOXYGEN_OMIT_INTERNAL
677 
680  Command(Command&& other);
684  ~Command() noexcept; /* annotating specified destructor as noexcept is best-practice */
685 
686  // With all submessage and field getters: Note that the returned reference
687  // should not be used after the lifetime of this parent.
688 
689  // Submessages -------------------------------------------------------------
690 
692  Io& io() { return io_; }
694  const Io& io() const { return io_; }
696  Settings& settings() { return settings_; }
698  const Settings& settings() const { return settings_; }
700  Actuator& actuator() { return actuator_; }
702  const Actuator& actuator() const { return actuator_; }
703 
704  // Subfields -------------------------------------------------------------
705 
706  #ifndef DOXYGEN_OMIT_INTERNAL
710  const NumberedFloatField& debug() const;
711  #endif // DOXYGEN_OMIT_INTERNAL
712  FlagField& reset();
715  const FlagField& reset() const;
717  FlagField& boot();
719  const FlagField& boot() const;
721  FlagField& stopBoot();
723  const FlagField& stopBoot() const;
725  LedField& led();
727  const LedField& led() const;
728 
729  private:
733 
739 
744 
745  /* Disable move assigment operator. */
746  Command& operator= (const Command&& other) = delete;
747 };
748 
749 } // namespace hebi
Sets the name for this module. Name must be null-terminated character string for the name; must be <=...
Definition: hebi.h:97
HebiCommandPtr const internal_
Definition: command.hpp:653
IoBank & f()
I/O pin bank f (pins 1-8 available)
Definition: command.hpp:465
const CommandGains & velocityGains() const
Controller gains for the velocity PID loop.
Definition: command.hpp:521
FlagField & saveCurrentSettings()
Indicates if the module should save the current values of all of its settings.
Definition: command.hpp:604
HebiCommandBoolField const field_
Definition: command.hpp:209
The spring constant of the module.
Definition: hebi.h:75
IoBank & d()
I/O pin bank d (pins 1-8 available)
Definition: command.hpp:457
const FloatField & velocity() const
Velocity of the module output (post-spring), in radians/second.
Definition: command.hpp:642
HebiCommandPtr const internal_
Definition: command.hpp:208
HebiCommandPtr const internal_
Definition: command.hpp:144
HebiCommandHighResAngleField
Definition: hebi.h:79
const FloatField & effort() const
Effort at the module output; units vary (e.g., N * m for rotational joints and N for linear stages)...
Definition: command.hpp:646
HighResAngleField & positionLimitMax()
The firmware safety limit for the maximum allowed position.
Definition: command.hpp:546
#define HEBI_DISABLE_COPY(Class)
Definition: util.hpp:17
const FloatField & springConstant() const
The spring constant of the module.
Definition: command.hpp:532
HebiCommandIoPinBank const bank_
Definition: command.hpp:376
A simple lowpass filter applied to the controller output; needs to be between 0 and 1...
Definition: hebi.h:61
A message field representable by a bool value.
Definition: command.hpp:191
Actuator & actuator()
Actuator-specific commands.
Definition: command.hpp:700
Actuator-specific commands.
Definition: command.hpp:621
HebiCommandPtr const internal_
Definition: command.hpp:555
Io & io()
Any available digital or analog output pins on the device.
Definition: command.hpp:692
Settings & settings()
Module settings that are typically changed at a slower rate.
Definition: command.hpp:696
const StringField & name() const
Sets the name for this module. Name must be null-terminated character string for the name; must be <=...
Definition: command.hpp:598
HebiCommandPtr const internal_
Definition: command.hpp:375
Set the firmware safety limit for the minimum allowed position.
Definition: hebi.h:82
FloatField & springConstant()
The spring constant of the module.
Definition: command.hpp:530
HebiCommandPtr const internal_
Definition: command.hpp:79
FlagField save_current_settings_
Definition: command.hpp:615
A message field for interfacing with a bank of I/O pins.
Definition: command.hpp:325
const Actuator & actuator() const
Actuator-specific commands.
Definition: command.hpp:702
FlagField & stopBoot()
Stop the module from automatically booting into application.
Definition: command.cpp:361
Actuator & actuator()
Actuator-specific settings, such as controller gains.
Definition: command.hpp:589
StringField & family()
Sets the family for this module. Name must be null-terminated character string for the family; must b...
Definition: command.hpp:600
Command objects have various fields that can be set; when sent to the module, these fields control in...
Definition: command.hpp:30
~Command() noexcept
Cleans up command object as necessary.
Definition: command.cpp:330
IoBank & a()
I/O pin bank a (pins 1-8 available)
Definition: command.hpp:445
A message field representable by a std::string.
Definition: command.hpp:215
Command(HebiCommandPtr)
Wraps an existing C-style object that is managed by its parent. NOTE: this should not be used except ...
Definition: command.cpp:318
Definition: color.hpp:5
I/O pin bank b (pins 1-8 available)
Definition: hebi.h:114
const HighResAngleField & positionLimitMin() const
The firmware safety limit for the minimum allowed position.
Definition: command.hpp:544
A combination of the position, velocity, and effort loops with P feeding to T and V feeding to PWM; d...
A message field for interfacing with an LED.
Definition: command.hpp:381
HebiCommandNumberedFloatField const field_
Definition: command.hpp:185
HebiCommandPtr const internal_
Definition: command.hpp:279
Actuator(HebiCommandPtr internal)
Definition: command.hpp:494
The motor is not given power (equivalent to a 0 PWM value)
HebiCommandHighResAngleField const field_
Definition: command.hpp:145
bool has() const
True if (and only if) the field has a value.
Definition: command.hpp:308
CommandGains & effortGains()
Controller gains for the effort PID loop.
Definition: command.hpp:523
HebiCommandIoPinBank
Definition: hebi.h:111
#define HEBI_DISABLE_COPY_MOVE(Class)
Definition: util.hpp:7
HebiCommandPtr const internal_
Definition: command.hpp:470
IoBank & c()
I/O pin bank c (pins 1-8 available)
Definition: command.hpp:453
HebiCommandFloatField const field_
Definition: command.hpp:80
HighResAngleField & position()
Position of the module output (post-spring), in radians.
Definition: command.hpp:648
CommandGains & velocityGains()
Controller gains for the velocity PID loop.
Definition: command.hpp:519
HebiCommandPtr const internal_
Definition: command.hpp:609
Velocity of the module output (post-spring), in radians/second.
Definition: hebi.h:34
Actuator-specific settings, such as controller gains.
Definition: command.hpp:490
const Io & io() const
Any available digital or analog output pins on the device.
Definition: command.hpp:694
FlagField & reset()
Restart the module.
Definition: command.cpp:353
Module settings that are typically changed at a slower rate.
Definition: command.hpp:485
FloatField & referencePosition()
The internal encoder reference offset (setting this matches the current position to the given referen...
Definition: command.hpp:534
A combination of the position, velocity, and effort loops with P and V feeding to T; documented on do...
A two-state message field (either set/true or cleared/false).
Definition: command.hpp:252
FlagField reset_
Definition: command.hpp:735
const FloatField & referenceEffort() const
The internal effort reference offset (setting this matches the current effort to the given reference ...
Definition: command.hpp:540
const IoBank & e() const
I/O pin bank e (pins 1-8 available)
Definition: command.hpp:463
IoBank & b()
I/O pin bank b (pins 1-8 available)
Definition: command.hpp:449
A message field containing a numbered set of single-precision floating point values.
Definition: command.hpp:152
HebiCommandFlagField const field_
Definition: command.hpp:280
const Settings & settings() const
Module settings that are typically changed at a slower rate.
Definition: command.hpp:698
const IoBank & c() const
I/O pin bank c (pins 1-8 available)
Definition: command.hpp:455
HebiCommandPtr const internal_
Definition: command.hpp:245
const IoBank & b() const
I/O pin bank b (pins 1-8 available)
Definition: command.hpp:451
HebiCommandFloatField
Definition: hebi.h:32
HebiCommandStringField
Definition: hebi.h:95
HebiCommandPtr const internal_
Definition: command.hpp:318
HebiCommandNumberedFloatField
Definition: hebi.h:85
Set the internal encoder reference offset so that the current position matches the given reference co...
Definition: hebi.h:76
HighResAngleField position_limit_max_
Definition: command.hpp:565
EnumField< ControlStrategy > & controlStrategy()
How the position, velocity, and effort PID loops are connected in order to control motor PWM...
Definition: command.hpp:550
HighResAngleField & positionLimitMin()
The firmware safety limit for the minimum allowed position.
Definition: command.hpp:542
HebiCommandLedField const field_
Definition: command.hpp:417
FloatField & velocity()
Velocity of the module output (post-spring), in radians/second.
Definition: command.hpp:640
HebiCommandPtr const internal_
Definition: command.hpp:184
Any available digital or analog output pins on the device.
Definition: command.hpp:423
HebiCommandFlagField
Definition: hebi.h:100
EnumField< ControlStrategy > control_strategy_
Definition: command.hpp:566
const IoBank & d() const
I/O pin bank d (pins 1-8 available)
Definition: command.hpp:459
FloatField & referenceEffort()
The internal effort reference offset (setting this matches the current effort to the given reference ...
Definition: command.hpp:538
ROSCPP_DECL bool has(const std::string &key)
LedField led_
Definition: command.hpp:738
const FloatField & referencePosition() const
The internal encoder reference offset (setting this matches the current position to the given referen...
Definition: command.hpp:536
void clear()
Removes any currently set value for this field.
Definition: command.hpp:315
Actuator(HebiCommandPtr internal)
Definition: command.hpp:625
A combination of the position, velocity, and effort loops with P, V, and T feeding to PWM; documented...
IoBank & e()
I/O pin bank e (pins 1-8 available)
Definition: command.hpp:461
Actuator actuator_
Definition: command.hpp:732
A simple lowpass filter applied to the controller output; needs to be between 0 and 1...
Definition: hebi.h:48
HighResAngleField position_
Definition: command.hpp:657
FlagField stop_boot_
Definition: command.hpp:737
HighResAngleField position_limit_min_
Definition: command.hpp:564
A message field for an angle measurement which does not lose precision at very high angles...
Definition: command.hpp:89
Controls whether the Kd term uses the "derivative of error" or "derivative of measurement." When the setpoints have step inputs or are noisy, setting this to false can eliminate corresponding spikes or noise in the output.
Definition: hebi.h:92
FlagField boot_
Definition: command.hpp:736
FlagField & boot()
Boot the module from bootloader into application.
Definition: command.cpp:357
HebiStatusCode hebiCommandGetEnum(HebiCommandPtr cmd, HebiCommandEnumField field, int32_t *value)
void hebiCommandSetEnum(HebiCommandPtr cmd, HebiCommandEnumField field, const int32_t *value)
const CommandGains & positionGains() const
Controller gains for the position PID loop.
Definition: command.hpp:517
NumberedFloatField & debug()
Values for internal debug functions (channel 1-9 available).
Definition: command.cpp:349
struct _HebiCommand * HebiCommandPtr
The C-style&#39;s API representation of a command.
Definition: hebi.h:315
Settings settings_
Definition: command.hpp:731
HebiCommandEnumField const field_
Definition: command.hpp:319
Position of the module output (post-spring), in radians.
Definition: hebi.h:81
NumberedFloatField debug_
Definition: command.hpp:734
I/O pin bank d (pins 1-8 available)
Definition: hebi.h:116
Effort at the module output; units vary (e.g., N * m for rotational joints and N for linear stages)...
Definition: hebi.h:35
HebiCommandEnumField
Definition: hebi.h:107
StringField & name()
Sets the name for this module. Name must be null-terminated character string for the name; must be <=...
Definition: command.hpp:596
HebiCommandStringField const field_
Definition: command.hpp:246
EnumField(HebiCommandPtr internal, HebiCommandEnumField field)
Definition: command.hpp:291
Settings(HebiCommandPtr internal)
Definition: command.hpp:573
const IoBank & f() const
I/O pin bank f (pins 1-8 available)
Definition: command.hpp:467
const FlagField & saveCurrentSettings() const
Indicates if the module should save the current values of all of its settings.
Definition: command.hpp:606
HebiCommandLedField
Definition: hebi.h:120
Controls whether the Kd term uses the "derivative of error" or "derivative of measurement." When the setpoints have step inputs or are noisy, setting this to false can eliminate corresponding spikes or noise in the output.
Definition: hebi.h:91
const IoBank & a() const
I/O pin bank a (pins 1-8 available)
Definition: command.hpp:447
const HighResAngleField & positionLimitMax() const
The firmware safety limit for the maximum allowed position.
Definition: command.hpp:548
const EnumField< ControlStrategy > & controlStrategy() const
How the position, velocity, and effort PID loops are connected in order to control motor PWM...
Definition: command.hpp:552
HebiCommandBoolField
Definition: hebi.h:89
const Actuator & actuator() const
Actuator-specific settings, such as controller gains.
Definition: command.hpp:591
A direct PWM value (-1 to 1) can be sent to the motor (subject to onboard safety limiting).
const CommandGains & effortGains() const
Controller gains for the effort PID loop.
Definition: command.hpp:525
Structure to describe an RGB color.
Definition: color.hpp:8
CommandGains & positionGains()
Controller gains for the position PID loop.
Definition: command.hpp:515
const StringField & family() const
Sets the family for this module. Name must be null-terminated character string for the family; must b...
Definition: command.hpp:602
A message field representable by a single-precision floating point value.
Definition: command.hpp:49
const HighResAngleField & position() const
Position of the module output (post-spring), in radians.
Definition: command.hpp:650
HebiCommandPtr const internal_
Definition: command.hpp:416
I/O pin bank c (pins 1-8 available)
Definition: hebi.h:115
I/O pin bank a (pins 1-8 available)
Definition: hebi.h:113
HebiCommandPtr internal_
Definition: command.hpp:667
A simple lowpass filter applied to the controller output; needs to be between 0 and 1...
Definition: hebi.h:74
Io(HebiCommandPtr internal)
Definition: command.hpp:427
I/O pin bank e (pins 1-8 available)
Definition: hebi.h:117
A message field representable by an enum of a given type.
Definition: command.hpp:287
FloatField & effort()
Effort at the module output; units vary (e.g., N * m for rotational joints and N for linear stages)...
Definition: command.hpp:644
LedField & led()
The module&#39;s LED.
Definition: command.cpp:365


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:03