feedback.cpp
Go to the documentation of this file.
1 #include "feedback.hpp"
2 
3 #include <cmath>
4 #include <limits>
5 #ifndef M_PI
6 #define M_PI 3.14159265358979323846
7 #endif
8 
9 namespace hebi {
10 
12  : internal_(internal), field_(field) {}
13 
15  return (floatGetter(internal_, field_, nullptr) == HebiStatusSuccess);
16 }
17 
19  float ret;
20  if (floatGetter(internal_, field_, &ret) != HebiStatusSuccess) {
21  ret = std::numeric_limits<float>::quiet_NaN();
22  }
23  return ret;
24 }
25 
27  : internal_(internal), field_(field) {}
28 
30  return (highResAngleGetter(internal_, field_, nullptr, nullptr) == HebiStatusSuccess);
31 }
32 
34  int64_t revolutions;
35  float radian_offset;
36  if (highResAngleGetter(internal_, field_, &revolutions, &radian_offset) != HebiStatusSuccess) {
37  return std::numeric_limits<double>::quiet_NaN();
38  }
39  return (static_cast<double>(revolutions) * 2.0 * M_PI + static_cast<double>(radian_offset));
40 }
41 
42 void Feedback::HighResAngleField::get(int64_t* revolutions, float* radian_offset) const {
43  if (highResAngleGetter(internal_, field_, revolutions, radian_offset) != HebiStatusSuccess) {
44  *revolutions = 0;
45  *radian_offset = std::numeric_limits<float>::quiet_NaN();
46  }
47 }
48 
50  : internal_(internal), field_(field) {}
51 
52 bool Feedback::NumberedFloatField::has(size_t fieldNumber) const {
53  return (numberedFloatGetter(internal_, field_, fieldNumber, nullptr) == HebiStatusSuccess);
54 }
55 
56 float Feedback::NumberedFloatField::get(size_t fieldNumber) const {
57  float ret;
58  if (numberedFloatGetter(internal_, field_, fieldNumber, &ret) != HebiStatusSuccess) {
59  ret = std::numeric_limits<float>::quiet_NaN();
60  }
61  return ret;
62 }
63 
65  : internal_(internal), field_(field) {}
66 
68  return (uint64Getter(internal_, field_, nullptr) == HebiStatusSuccess);
69 }
70 
71 uint64_t Feedback::UInt64Field::get() const {
72  uint64_t ret;
73  if (uint64Getter(internal_, field_, &ret) != HebiStatusSuccess) {
74  ret = 0;
75  }
76  return ret;
77 }
78 
80  : internal_(internal), field_(field) {}
81 
83  return (vector3fGetter(internal_, field_, nullptr) == HebiStatusSuccess);
84 }
85 
87  HebiVector3f ret;
88  if (vector3fGetter(internal_, field_, &ret) != HebiStatusSuccess) {
89  ret.x = std::numeric_limits<float>::quiet_NaN();
90  ret.y = std::numeric_limits<float>::quiet_NaN();
91  ret.z = std::numeric_limits<float>::quiet_NaN();
92  }
93  return ret;
94 }
95 
97  : internal_(internal), field_(field) {}
98 
100  return (quaternionfGetter(internal_, field_, nullptr) == HebiStatusSuccess);
101 }
102 
104  HebiQuaternionf ret;
105  if (quaternionfGetter(internal_, field_, &ret) != HebiStatusSuccess) {
106  ret.w = std::numeric_limits<float>::quiet_NaN();
107  ret.x = std::numeric_limits<float>::quiet_NaN();
108  ret.y = std::numeric_limits<float>::quiet_NaN();
109  ret.z = std::numeric_limits<float>::quiet_NaN();
110  }
111  return ret;
112 }
113 
114 Feedback::IoBank::IoBank(const HebiFeedbackRef& internal, HebiFeedbackIoPinBank bank) : internal_(internal), bank_(bank) {}
115 
116 bool Feedback::IoBank::hasInt(size_t pinNumber) const {
117  return (intIoPinGetter(internal_, bank_, pinNumber, nullptr) == HebiStatusSuccess);
118 }
119 
120 bool Feedback::IoBank::hasFloat(size_t pinNumber) const {
121  return (floatIoPinGetter(internal_, bank_, pinNumber, nullptr) == HebiStatusSuccess);
122 }
123 
124 int64_t Feedback::IoBank::getInt(size_t pinNumber) const {
125  int64_t ret;
126  intIoPinGetter(internal_, bank_, pinNumber, &ret);
127  return ret;
128 }
129 
130 float Feedback::IoBank::getFloat(size_t pinNumber) const {
131  float ret;
132  floatIoPinGetter(internal_, bank_, pinNumber, &ret);
133  return ret;
134 }
135 
137  : internal_(internal), field_(field) {}
138 
140  return ledGetter(internal_, field_, nullptr, nullptr, nullptr, nullptr) == HebiStatusSuccess;
141 }
142 
144  uint8_t r, g, b, a;
145  if (ledGetter(internal_, field_, &r, &g, &b, &a) != HebiStatusSuccess) {
146  r = 0;
147  g = 0;
148  b = 0;
149  a = 0;
150  }
151  return Color(r, g, b, a);
152 }
153 
155  : internal_(feedback),
171 }
172 
174  : internal_(other.internal_),
175  io_(internal_ref_),
176  actuator_(internal_ref_),
177  mobile_(internal_ref_),
178  imu_(internal_ref_),
179  board_temperature_(internal_ref_, HebiFeedbackFloatBoardTemperature),
180  processor_temperature_(internal_ref_, HebiFeedbackFloatProcessorTemperature),
181  voltage_(internal_ref_, HebiFeedbackFloatVoltage),
182  receive_time_us_(internal_ref_, HebiFeedbackUInt64ReceiveTime),
183  transmit_time_us_(internal_ref_, HebiFeedbackUInt64TransmitTime),
184  hardware_receive_time_us_(internal_ref_, HebiFeedbackUInt64HardwareReceiveTime),
185  hardware_transmit_time_us_(internal_ref_, HebiFeedbackUInt64HardwareTransmitTime),
186  sender_id_(internal_ref_, HebiFeedbackUInt64SenderId),
187  debug_(internal_ref_, HebiFeedbackNumberedFloatDebug),
188  led_(internal_ref_, HebiFeedbackLedLed) {
189  // NOTE: it would be nice to also cleanup the actual internal pointer of other
190  // but alas we cannot change a const variable.
192 }
193 
194 } // namespace hebi
hebi::Feedback::IoBank::IoBank
IoBank(const HebiFeedbackRef &internal, HebiFeedbackIoPinBank bank)
Definition: feedback.cpp:114
hebi::floatGetter
HebiStatusCode floatGetter(const RefT &ref, MetadataT &metadata, int field, float *value)
Definition: message_helpers.cpp:21
hebi::Feedback::FloatField::has
bool has() const
True if (and only if) the field has a value.
Definition: feedback.cpp:14
hebi::Color
Structure to describe an RGB color.
Definition: color.hpp:8
HebiVector3f_::x
float x
Definition: hebi.h:565
HebiQuaternionf_::z
float z
Definition: hebi.h:574
hebi::Feedback::UInt64Field::has
bool has() const
True if (and only if) the field has a value.
Definition: feedback.cpp:67
hebi::Feedback::FloatField::FloatField
FloatField(const HebiFeedbackRef &internal, HebiFeedbackFloatField field)
Definition: feedback.cpp:11
HebiStatusSuccess
@ HebiStatusSuccess
Definition: hebi.h:24
hebi::Vector3f
Structure to hold a 3-D floating point vector (i.e., x/y/z components)
Definition: vector_3_f.hpp:8
HebiQuaternionf_
Definition: hebi.h:570
HebiFeedbackUInt64ReceiveTime
@ HebiFeedbackUInt64ReceiveTime
Sequence number going to module (local)
Definition: hebi.h:193
hebi::vector3fGetter
HebiStatusCode vector3fGetter(const RefT &ref, MetadataT &metadata, int field, HebiVector3f *value)
Definition: message_helpers.cpp:114
hebi::Feedback::IoBank::hasInt
bool hasInt(size_t pinNumber) const
True if (and only if) the particular numbered pin in this bank has an integer (e.g....
Definition: feedback.cpp:116
HebiFeedbackFloatProcessorTemperature
@ HebiFeedbackFloatProcessorTemperature
Ambient temperature inside the module (measured at the IMU chip)
Definition: hebi.h:163
HebiFeedbackQuaternionfField
HebiFeedbackQuaternionfField
Definition: hebi.h:206
HebiVector3f_::z
float z
Definition: hebi.h:567
hebi::Quaternionf
Structure to hold a floating point quaternion (i.e., w/x/y/z components)
Definition: quaternion_f.hpp:8
HebiQuaternionf_::x
float x
Definition: hebi.h:572
hebi::Feedback::Vector3fField::Vector3fField
Vector3fField(const HebiFeedbackRef &internal, HebiFeedbackVector3fField field)
Definition: feedback.cpp:79
HebiFeedbackUInt64Field
HebiFeedbackUInt64Field
Definition: hebi.h:191
hebi::ledGetter
HebiStatusCode ledGetter(const RefT &ref, MetadataT &metadata, int field, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a)
Definition: message_helpers.cpp:356
HebiFeedbackHighResAngleField
HebiFeedbackHighResAngleField
Definition: hebi.h:181
hebi::Feedback::IoBank::getInt
int64_t getInt(size_t pinNumber) const
If this numbered pin in this bank has an integer (e.g., digital) value, returns that value; otherwise...
Definition: feedback.cpp:124
hebi::Feedback::mobile_
Mobile mobile_
Definition: feedback.hpp:725
hebi::Feedback::internal_
HebiFeedbackPtr internal_
Definition: feedback.hpp:659
HebiFeedbackUInt64TransmitTime
@ HebiFeedbackUInt64TransmitTime
Timestamp of when message was received from module (local)
Definition: hebi.h:194
HebiFeedbackPtr
struct HebiFeedback_ * HebiFeedbackPtr
The C-style's API representation of feedback.
Definition: hebi.h:451
HebiFeedbackRef_
Definition: hebi.h:690
HebiQuaternionf_::y
float y
Definition: hebi.h:573
hebi::Feedback::QuaternionfField::QuaternionfField
QuaternionfField(const HebiFeedbackRef &internal, HebiFeedbackQuaternionfField field)
Definition: feedback.cpp:96
hebi::Feedback::processor_temperature_
FloatField processor_temperature_
Definition: feedback.hpp:729
hebi::Feedback::QuaternionfField::has
bool has() const
True if (and only if) the field has a value.
Definition: feedback.cpp:99
hebi::Feedback::LedField::getColor
Color getColor() const
Returns the led color.
Definition: feedback.cpp:143
hebi::Feedback::hardware_receive_time_us_
UInt64Field hardware_receive_time_us_
Definition: feedback.hpp:734
HebiFeedbackLedLed
@ HebiFeedbackLedLed
Definition: hebi.h:231
hebi::Feedback::IoBank::hasFloat
bool hasFloat(size_t pinNumber) const
True if (and only if) the particular numbered pin in this bank has an floating point (e....
Definition: feedback.cpp:120
hebi::Feedback::NumberedFloatField::has
bool has(size_t fieldNumber) const
True if (and only if) the particular numbered subvalue of this field has a value.
Definition: feedback.cpp:52
HebiFeedbackFloatBoardTemperature
@ HebiFeedbackFloatBoardTemperature
Definition: hebi.h:162
hebi::Feedback::actuator_
Actuator actuator_
Definition: feedback.hpp:724
hebi::Feedback::UInt64Field::get
uint64_t get() const
If the field has a value, returns that value; otherwise, returns a default.
Definition: feedback.cpp:71
hebi::Feedback::NumberedFloatField::get
float get(size_t fieldNumber) const
If the particular numbered subvalue of this field has a value, returns that value; otherwise returns ...
Definition: feedback.cpp:56
hebi::Feedback::NumberedFloatField::NumberedFloatField
NumberedFloatField(const HebiFeedbackRef &internal, HebiFeedbackNumberedFloatField field)
Definition: feedback.cpp:49
hebi::Feedback::transmit_time_us_
UInt64Field transmit_time_us_
Definition: feedback.hpp:733
hebi::highResAngleGetter
HebiStatusCode highResAngleGetter(const RefT &ref, MetadataT &metadata, int field, int64_t *revs, float *offset)
Definition: message_helpers.cpp:50
hebi::Feedback::HighResAngleField::get
double get() const
If the field has a value, returns that value as a double; otherwise, returns a default.
Definition: feedback.cpp:33
hebi::Feedback::IoBank::getFloat
float getFloat(size_t pinNumber) const
If this numbered pin in this bank has an floating point (e.g., analog or PWM) value,...
Definition: feedback.cpp:130
hebi::Feedback::UInt64Field::UInt64Field
UInt64Field(const HebiFeedbackRef &internal, HebiFeedbackUInt64Field field)
Definition: feedback.cpp:64
hebi::Feedback::led_
LedField led_
Definition: feedback.hpp:737
hebi
Definition: arm.cpp:5
hebi::Feedback::HighResAngleField::has
bool has() const
True if (and only if) the field has a value.
Definition: feedback.cpp:29
HebiVector3f_::y
float y
Definition: hebi.h:566
hebi::Feedback::Vector3fField::get
Vector3f get() const
If the field has a value, returns that value; otherwise, returns a default.
Definition: feedback.cpp:86
hebi::Feedback::sender_id_
UInt64Field sender_id_
Definition: feedback.hpp:736
HebiFeedbackNumberedFloatDebug
@ HebiFeedbackNumberedFloatDebug
Definition: hebi.h:188
hebi::Feedback::Feedback
Feedback(HebiFeedbackPtr)
Wraps an existing C-style object that is managed by its parent. NOTE: this should not be used except ...
Definition: feedback.cpp:154
HebiFeedbackFloatField
HebiFeedbackFloatField
Feedback Enums.
Definition: hebi.h:161
HebiQuaternionf_::w
float w
Definition: hebi.h:571
HebiFeedbackNumberedFloatField
HebiFeedbackNumberedFloatField
Definition: hebi.h:187
HebiFeedbackUInt64HardwareReceiveTime
@ HebiFeedbackUInt64HardwareReceiveTime
Timestamp of when message was transmitted to module (local)
Definition: hebi.h:195
hebi::Feedback::board_temperature_
FloatField board_temperature_
Definition: feedback.hpp:728
hebi::Feedback::LedField::hasColor
bool hasColor() const
Returns true if the LED color is set, and false otherwise.
Definition: feedback.cpp:139
hebi::Feedback::internal_ref_
HebiFeedbackRef internal_ref_
Definition: feedback.hpp:660
hebi::Feedback::Vector3fField::has
bool has() const
True if (and only if) the field has a value.
Definition: feedback.cpp:82
M_PI
#define M_PI
Definition: feedback.cpp:6
hebi::Feedback::hardware_transmit_time_us_
UInt64Field hardware_transmit_time_us_
Definition: feedback.hpp:735
hebiFeedbackGetReference
void hebiFeedbackGetReference(HebiFeedbackPtr feedback, HebiFeedbackRef *ref)
Feedback API.
hebi::Feedback::voltage_
FloatField voltage_
Definition: feedback.hpp:730
hebi::quaternionfGetter
HebiStatusCode quaternionfGetter(const RefT &ref, MetadataT &metadata, int field, HebiQuaternionf *value)
Definition: message_helpers.cpp:143
HebiFeedbackUInt64HardwareTransmitTime
@ HebiFeedbackUInt64HardwareTransmitTime
Timestamp of when message was received by module (remote)
Definition: hebi.h:196
feedback.hpp
HebiFeedbackIoPinBank
HebiFeedbackIoPinBank
Definition: hebi.h:221
hebi::intIoPinGetter
HebiStatusCode intIoPinGetter(const RefT &ref, MetadataT &metadata, int index, size_t pin_number, int64_t *value)
Definition: message_helpers.cpp:209
hebi::Feedback::imu_
Imu imu_
Definition: feedback.hpp:726
hebi::Feedback::QuaternionfField::get
Quaternionf get() const
If the field has a value, returns that value; otherwise, returns a default.
Definition: feedback.cpp:103
HebiFeedbackUInt64SenderId
@ HebiFeedbackUInt64SenderId
Timestamp of when message was transmitted from module (remote)
Definition: hebi.h:197
HebiFeedbackVector3fField
HebiFeedbackVector3fField
Definition: hebi.h:200
HebiFeedbackLedField
HebiFeedbackLedField
Definition: hebi.h:230
hebi::uint64Getter
HebiStatusCode uint64Getter(const RefT &ref, MetadataT &metadata, int field, uint64_t *value)
Definition: message_helpers.cpp:327
hebi::Feedback::receive_time_us_
UInt64Field receive_time_us_
Definition: feedback.hpp:732
hebi::numberedFloatGetter
HebiStatusCode numberedFloatGetter(const RefT &ref, MetadataT &metadata, int field, size_t number, float *value)
Definition: message_helpers.cpp:81
hebi::Feedback::LedField::LedField
LedField(const HebiFeedbackRef &internal, HebiFeedbackLedField field)
Definition: feedback.cpp:136
hebi::Feedback
Feedback objects have various fields representing feedback from modules; which fields are populated d...
Definition: feedback.hpp:32
hebi::floatIoPinGetter
HebiStatusCode floatIoPinGetter(const RefT &ref, MetadataT &metadata, int index, size_t pin_number, float *value)
Definition: message_helpers.cpp:172
HebiVector3f_
Definition: hebi.h:564
HebiFeedbackFloatVoltage
@ HebiFeedbackFloatVoltage
Temperature of the processor chip.
Definition: hebi.h:164
hebi::Feedback::FloatField::get
float get() const
If the field has a value, returns that value; otherwise, returns a default.
Definition: feedback.cpp:18
hebi::Feedback::debug_
NumberedFloatField debug_
Definition: feedback.hpp:731
hebi::Feedback::HighResAngleField::HighResAngleField
HighResAngleField(const HebiFeedbackRef &internal, HebiFeedbackHighResAngleField field)
Definition: feedback.cpp:26
hebi::Feedback::io_
Io io_
Definition: feedback.hpp:723


hebi_cpp_api_ros
Author(s): Chris Bollinger , Matthew Tesch
autogenerated on Fri Aug 2 2024 08:35:18