group_feedback.cpp
Go to the documentation of this file.
1 #include "group_feedback.hpp"
2 
3 namespace hebi {
4 
5 GroupFeedback::GroupFeedback(size_t number_of_modules)
6  : internal_(hebiGroupFeedbackCreate(number_of_modules)),
7  manage_pointer_lifetime_(true),
8  number_of_modules_(number_of_modules)
9 {
10  for (size_t i = 0; i < number_of_modules_; i++)
12 }
13 
15  : internal_(group_feedback),
18 {
19  for (size_t i = 0; i < number_of_modules_; i++)
21 }
22 
24 {
25  if (manage_pointer_lifetime_ && internal_ != nullptr)
27 }
28 
29 size_t GroupFeedback::size() const
30 {
31  return number_of_modules_;
32 }
33 
34 const Feedback& GroupFeedback::operator[](size_t index) const
35 {
36  return feedbacks_[index];
37 }
38 
39 Eigen::VectorXd GroupFeedback::getBoardTemperature() const
40 {
41  Eigen::VectorXd res(number_of_modules_);
42  for (size_t i = 0; i < number_of_modules_; ++i)
43  {
44  auto& fbk = feedbacks_[i].boardTemperature();
45  res[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
46  }
47  return res;
48 }
50 {
51  Eigen::VectorXd res(number_of_modules_);
52  for (size_t i = 0; i < number_of_modules_; ++i)
53  {
54  auto& fbk = feedbacks_[i].processorTemperature();
55  res[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
56  }
57  return res;
58 }
59 Eigen::VectorXd GroupFeedback::getVoltage() const
60 {
61  Eigen::VectorXd res(number_of_modules_);
62  for (size_t i = 0; i < number_of_modules_; ++i)
63  {
64  auto& fbk = feedbacks_[i].voltage();
65  res[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
66  }
67  return res;
68 }
69 
70 Eigen::VectorXd GroupFeedback::getDeflection() const
71 {
72  Eigen::VectorXd res(number_of_modules_);
73  for (size_t i = 0; i < number_of_modules_; ++i)
74  {
75  auto& cmd = feedbacks_[i].actuator().deflection();
76  res[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
77  }
78  return res;
79 }
80 Eigen::VectorXd GroupFeedback::getDeflectionVelocity() const
81 {
82  Eigen::VectorXd res(number_of_modules_);
83  for (size_t i = 0; i < number_of_modules_; ++i)
84  {
85  auto& cmd = feedbacks_[i].actuator().deflectionVelocity();
86  res[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
87  }
88  return res;
89 }
90 Eigen::VectorXd GroupFeedback::getMotorVelocity() const
91 {
92  Eigen::VectorXd res(number_of_modules_);
93  for (size_t i = 0; i < number_of_modules_; ++i)
94  {
95  auto& cmd = feedbacks_[i].actuator().motorVelocity();
96  res[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
97  }
98  return res;
99 }
100 Eigen::VectorXd GroupFeedback::getMotorCurrent() const
101 {
102  Eigen::VectorXd res(number_of_modules_);
103  for (size_t i = 0; i < number_of_modules_; ++i)
104  {
105  auto& fbk = feedbacks_[i].actuator().motorCurrent();
106  res[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
107  }
108  return res;
109 }
111 {
112  Eigen::VectorXd res(number_of_modules_);
113  for (size_t i = 0; i < number_of_modules_; ++i)
114  {
115  auto& fbk = feedbacks_[i].actuator().motorSensorTemperature();
116  res[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
117  }
118  return res;
119 }
121 {
122  Eigen::VectorXd res(number_of_modules_);
123  for (size_t i = 0; i < number_of_modules_; ++i)
124  {
125  auto& fbk = feedbacks_[i].actuator().motorWindingCurrent();
126  res[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
127  }
128  return res;
129 }
130 
132 {
133  Eigen::VectorXd res(number_of_modules_);
134  for (size_t i = 0; i < number_of_modules_; ++i)
135  {
136  auto& cmd = feedbacks_[i].actuator().motorWindingTemperature();
137  res[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
138  }
139  return res;
140 }
142 {
143  Eigen::VectorXd res(number_of_modules_);
144  for (size_t i = 0; i < number_of_modules_; ++i)
145  {
146  auto& cmd = feedbacks_[i].actuator().motorHousingTemperature();
147  res[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
148  }
149  return res;
150 }
151 
152 Eigen::VectorXd GroupFeedback::getPosition() const
153 {
154  Eigen::VectorXd res(number_of_modules_);
155  for (size_t i = 0; i < number_of_modules_; ++i)
156  {
157  auto& fbk = feedbacks_[i].actuator().position();
158  res[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
159  }
160  return res;
161 }
162 Eigen::VectorXd GroupFeedback::getVelocity() const
163 {
164  Eigen::VectorXd res(number_of_modules_);
165  for (size_t i = 0; i < number_of_modules_; ++i)
166  {
167  auto& fbk = feedbacks_[i].actuator().velocity();
168  res[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
169  }
170  return res;
171 }
172 Eigen::VectorXd GroupFeedback::getEffort() const
173 {
174  Eigen::VectorXd res(number_of_modules_);
175  for (size_t i = 0; i < number_of_modules_; ++i)
176  {
177  auto& fbk = feedbacks_[i].actuator().effort();
178  res[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
179  }
180  return res;
181 }
182 
183 Eigen::VectorXd GroupFeedback::getPositionCommand() const
184 {
185  Eigen::VectorXd res(number_of_modules_);
186  for (size_t i = 0; i < number_of_modules_; ++i)
187  {
188  auto& cmd = feedbacks_[i].actuator().positionCommand();
189  res[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
190  }
191  return res;
192 }
193 Eigen::VectorXd GroupFeedback::getVelocityCommand() const
194 {
195  Eigen::VectorXd res(number_of_modules_);
196  for (size_t i = 0; i < number_of_modules_; ++i)
197  {
198  auto& cmd = feedbacks_[i].actuator().velocityCommand();
199  res[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
200  }
201  return res;
202 }
203 Eigen::VectorXd GroupFeedback::getEffortCommand() const
204 {
205  Eigen::VectorXd res(number_of_modules_);
206  for (size_t i = 0; i < number_of_modules_; ++i)
207  {
208  auto& cmd = feedbacks_[i].actuator().effortCommand();
209  res[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
210  }
211  return res;
212 }
213 
214 Eigen::MatrixX3d GroupFeedback::getAccelerometer() const
215 {
216  Eigen::MatrixX3d res(number_of_modules_, 3);
217  for (size_t i = 0; i < number_of_modules_; ++i)
218  {
219  auto& fbk = feedbacks_[i].imu().accelerometer();
220  if (fbk)
221  {
222  auto vec = fbk.get();
223  res(i, 0) = vec.getX();
224  res(i, 1) = vec.getY();
225  res(i, 2) = vec.getZ();
226  }
227  else
228  {
229  res(i, 0) = std::numeric_limits<double>::quiet_NaN();
230  res(i, 1) = std::numeric_limits<double>::quiet_NaN();
231  res(i, 2) = std::numeric_limits<double>::quiet_NaN();
232  }
233  }
234  return res;
235 }
236 Eigen::MatrixX3d GroupFeedback::getGyro() const
237 {
238  Eigen::MatrixX3d res(number_of_modules_, 3);
239  for (size_t i = 0; i < number_of_modules_; ++i)
240  {
241  auto& fbk = feedbacks_[i].imu().gyro();
242  if (fbk)
243  {
244  auto vec = fbk.get();
245  res(i, 0) = vec.getX();
246  res(i, 1) = vec.getY();
247  res(i, 2) = vec.getZ();
248  }
249  else
250  {
251  res(i, 0) = std::numeric_limits<double>::quiet_NaN();
252  res(i, 1) = std::numeric_limits<double>::quiet_NaN();
253  res(i, 2) = std::numeric_limits<double>::quiet_NaN();
254  }
255  }
256  return res;
257 }
258 
259 void GroupFeedback::getBoardTemperature(Eigen::VectorXd& out) const
260 {
261  if (out.size() != number_of_modules_)
262  {
263  out.resize(number_of_modules_);
264  }
265 
266  for (size_t i = 0; i < number_of_modules_; ++i)
267  {
268  auto& fbk = feedbacks_[i].boardTemperature();
269  out[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
270  }
271 }
272 void GroupFeedback::getProcessorTemperature(Eigen::VectorXd& out) const
273 {
274  if (out.size() != number_of_modules_)
275  {
276  out.resize(number_of_modules_);
277  }
278 
279  for (size_t i = 0; i < number_of_modules_; ++i)
280  {
281  auto& fbk = feedbacks_[i].processorTemperature();
282  out[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
283  }
284 }
285 void GroupFeedback::getVoltage(Eigen::VectorXd& out) const
286 {
287  if (out.size() != number_of_modules_)
288  {
289  out.resize(number_of_modules_);
290  }
291 
292  for (size_t i = 0; i < number_of_modules_; ++i)
293  {
294  auto& fbk = feedbacks_[i].voltage();
295  out[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
296  }
297 }
298 
299 void GroupFeedback::getDeflection(Eigen::VectorXd& out) const
300 {
301  if (out.size() != number_of_modules_)
302  {
303  out.resize(number_of_modules_);
304  }
305 
306  for (size_t i = 0; i < number_of_modules_; ++i)
307  {
308  auto& cmd = feedbacks_[i].actuator().deflection();
309  out[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
310  }
311 }
312 void GroupFeedback::getDeflectionVelocity(Eigen::VectorXd& out) const
313 {
314  if (out.size() != number_of_modules_)
315  {
316  out.resize(number_of_modules_);
317  }
318 
319  for (size_t i = 0; i < number_of_modules_; ++i)
320  {
321  auto& cmd = feedbacks_[i].actuator().deflectionVelocity();
322  out[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
323  }
324 }
325 void GroupFeedback::getMotorVelocity(Eigen::VectorXd& out) const
326 {
327  if (out.size() != number_of_modules_)
328  {
329  out.resize(number_of_modules_);
330  }
331 
332  for (size_t i = 0; i < number_of_modules_; ++i)
333  {
334  auto& cmd = feedbacks_[i].actuator().motorVelocity();
335  out[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
336  }
337 }
338 void GroupFeedback::getMotorCurrent(Eigen::VectorXd& out) const
339 {
340  if (out.size() != number_of_modules_)
341  {
342  out.resize(number_of_modules_);
343  }
344 
345  for (size_t i = 0; i < number_of_modules_; ++i)
346  {
347  auto& fbk = feedbacks_[i].actuator().motorCurrent();
348  out[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
349  }
350 }
351 void GroupFeedback::getMotorSensorTemperature(Eigen::VectorXd& out) const
352 {
353  if (out.size() != number_of_modules_)
354  {
355  out.resize(number_of_modules_);
356  }
357 
358  for (size_t i = 0; i < number_of_modules_; ++i)
359  {
360  auto& fbk = feedbacks_[i].actuator().motorSensorTemperature();
361  out[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
362  }
363 }
364 void GroupFeedback::getMotorWindingCurrent(Eigen::VectorXd& out) const
365 {
366  if (out.size() != number_of_modules_)
367  {
368  out.resize(number_of_modules_);
369  }
370 
371  for (size_t i = 0; i < number_of_modules_; ++i)
372  {
373  auto& fbk = feedbacks_[i].actuator().motorWindingCurrent();
374  out[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
375  }
376 }
377 
378 void GroupFeedback::getMotorWindingTemperature(Eigen::VectorXd& out) const
379 {
380  if (out.size() != number_of_modules_)
381  {
382  out.resize(number_of_modules_);
383  }
384 
385  for (size_t i = 0; i < number_of_modules_; ++i)
386  {
387  auto& cmd = feedbacks_[i].actuator().motorWindingTemperature();
388  out[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
389  }
390 }
391 void GroupFeedback::getMotorHousingTemperature(Eigen::VectorXd& out) const
392 {
393  if (out.size() != number_of_modules_)
394  {
395  out.resize(number_of_modules_);
396  }
397 
398  for (size_t i = 0; i < number_of_modules_; ++i)
399  {
400  auto& cmd = feedbacks_[i].actuator().motorHousingTemperature();
401  out[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
402  }
403 }
404 
405 void GroupFeedback::getPosition(Eigen::VectorXd& out) const
406 {
407  if (out.size() != number_of_modules_)
408  {
409  out.resize(number_of_modules_);
410  }
411 
412  for (size_t i = 0; i < number_of_modules_; ++i)
413  {
414  auto& fbk = feedbacks_[i].actuator().position();
415  out[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
416  }
417 }
418 void GroupFeedback::getVelocity(Eigen::VectorXd& out) const
419 {
420  if (out.size() != number_of_modules_)
421  {
422  out.resize(number_of_modules_);
423  }
424 
425  for (size_t i = 0; i < number_of_modules_; ++i)
426  {
427  auto& fbk = feedbacks_[i].actuator().velocity();
428  out[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
429  }
430 }
431 void GroupFeedback::getEffort(Eigen::VectorXd& out) const
432 {
433  if (out.size() != number_of_modules_)
434  {
435  out.resize(number_of_modules_);
436  }
437 
438  for (size_t i = 0; i < number_of_modules_; ++i)
439  {
440  auto& fbk = feedbacks_[i].actuator().effort();
441  out[i] = (fbk) ? fbk.get() : std::numeric_limits<float>::quiet_NaN();
442  }
443 }
444 
445 void GroupFeedback::getPositionCommand(Eigen::VectorXd& out) const
446 {
447  if (out.size() != number_of_modules_)
448  {
449  out.resize(number_of_modules_);
450  }
451 
452  for (size_t i = 0; i < number_of_modules_; ++i)
453  {
454  auto& cmd = feedbacks_[i].actuator().positionCommand();
455  out[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
456  }
457 }
458 void GroupFeedback::getVelocityCommand(Eigen::VectorXd& out) const
459 {
460  if (out.size() != number_of_modules_)
461  {
462  out.resize(number_of_modules_);
463  }
464 
465  for (size_t i = 0; i < number_of_modules_; ++i)
466  {
467  auto& cmd = feedbacks_[i].actuator().velocityCommand();
468  out[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
469  }
470 }
471 void GroupFeedback::getEffortCommand(Eigen::VectorXd& out) const
472 {
473  if (out.size() != number_of_modules_)
474  {
475  out.resize(number_of_modules_);
476  }
477 
478  for (size_t i = 0; i < number_of_modules_; ++i)
479  {
480  auto& cmd = feedbacks_[i].actuator().effortCommand();
481  out[i] = (cmd) ? cmd.get() : std::numeric_limits<float>::quiet_NaN();
482  }
483 }
484 
485 void GroupFeedback::getAccelerometer(Eigen::MatrixX3d& out) const
486 {
487  if (out.rows() != number_of_modules_ || out.cols() != 3)
488  {
489  out.resize(number_of_modules_, 3);
490  }
491 
492  for (size_t i = 0; i < number_of_modules_; ++i)
493  {
494  auto& fbk = feedbacks_[i].imu().accelerometer();
495  if (fbk)
496  {
497  auto vec = fbk.get();
498  out(i, 0) = vec.getX();
499  out(i, 1) = vec.getY();
500  out(i, 2) = vec.getZ();
501  }
502  else
503  {
504  out(i, 0) = std::numeric_limits<double>::quiet_NaN();
505  out(i, 1) = std::numeric_limits<double>::quiet_NaN();
506  out(i, 2) = std::numeric_limits<double>::quiet_NaN();
507  }
508  }
509 }
510 void GroupFeedback::getGyro(Eigen::MatrixX3d& out) const
511 {
512  if (out.rows() != number_of_modules_ || out.cols() != 3)
513  {
514  out.resize(number_of_modules_, 3);
515  }
516 
517  for (size_t i = 0; i < number_of_modules_; ++i)
518  {
519  auto& fbk = feedbacks_[i].imu().gyro();
520  if (fbk)
521  {
522  auto vec = fbk.get();
523  out(i, 0) = vec.getX();
524  out(i, 1) = vec.getY();
525  out(i, 2) = vec.getZ();
526  }
527  else
528  {
529  out(i, 0) = std::numeric_limits<double>::quiet_NaN();
530  out(i, 1) = std::numeric_limits<double>::quiet_NaN();
531  out(i, 2) = std::numeric_limits<double>::quiet_NaN();
532  }
533  }
534 }
535 
536 } // namespace hebi
const Feedback & operator[](size_t index) const
Access the feedback for an individual module.
Eigen::VectorXd getVelocityCommand() const
Convenience function for returning commanded velocity values.
Eigen::VectorXd getBoardTemperature() const
Convenience function for returning feedback board temperature values.
Eigen::VectorXd getEffort() const
Convenience function for returning feedback effort values.
string cmd
HebiGroupFeedbackPtr hebiGroupFeedbackCreate(size_t size)
Creates a GroupFeedback for a group with the specified number of modules.
struct _HebiGroupFeedback * HebiGroupFeedbackPtr
The C-style&#39;s API representation of group feedback.
Definition: hebi.h:346
Definition: color.hpp:5
Eigen::VectorXd getDeflection() const
Convenience function for returning feedback deflection values.
size_t size() const
Returns the number of module feedbacks in this group feedback.
Eigen::VectorXd getVelocity() const
Convenience function for returning feedback velocity values.
Eigen::VectorXd getProcessorTemperature() const
Convenience function for returning feedback processor temperature values.
Feedback objects have various fields representing feedback from modules; which fields are populated d...
Definition: feedback.hpp:30
Eigen::MatrixX3d getGyro() const
Convenience function for returning feedback gyroscope values.
const bool manage_pointer_lifetime_
GroupFeedback(size_t number_of_modules)
Create a group feedback with the specified number of modules.
HebiFeedbackPtr hebiGroupFeedbackGetModuleFeedback(HebiGroupFeedbackPtr fbk, size_t module_index)
Get an individual feedback for a particular module at index module_index.
Eigen::VectorXd getMotorSensorTemperature() const
Convenience function for returning feedback motor sensor temperature values.
std::vector< Feedback > feedbacks_
Eigen::VectorXd getDeflectionVelocity() const
Convenience function for returning feedback deflection velocity values.
Eigen::VectorXd getVoltage() const
Convenience function for returning feedback voltage values.
HebiGroupFeedbackPtr internal_
const size_t number_of_modules_
Eigen::VectorXd getMotorWindingCurrent() const
Convenience function for returning feedback motor winding current values.
size_t hebiGroupFeedbackGetSize(HebiGroupFeedbackPtr fbk)
Return the number of modules in this group Feedback.
Eigen::VectorXd getMotorVelocity() const
Convenience function for returning feedback motor velocity values.
Eigen::MatrixX3d getAccelerometer() const
Convenience function for returning feedback accelerometer values.
Eigen::VectorXd getMotorHousingTemperature() const
Convenience function for returning feedback motor housing temperature values.
void hebiGroupFeedbackRelease(HebiGroupFeedbackPtr fbk)
Frees resources created by the GroupFeedback object.
Eigen::VectorXd getMotorCurrent() const
Convenience function for returning feedback motor current values.
~GroupFeedback() noexcept
Destructor cleans up group feedback object as necessary.
Eigen::VectorXd getPositionCommand() const
Convenience function for returning commanded position values.
Eigen::VectorXd getEffortCommand() const
Convenience function for returning commanded effort values.
Eigen::VectorXd getPosition() const
Convenience function for returning feedback position values.
Eigen::VectorXd getMotorWindingTemperature() const
Convenience function for returning feedback motor winding temperature values.


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