HEBI C++ API  3.4.0
mobile_io.hpp
Go to the documentation of this file.
1 #pragma once
2 
10 #include <array>
11 #include <bitset>
12 #include <memory>
13 
14 #include "group.hpp"
15 #include "group_feedback.hpp"
16 
17 namespace hebi {
18 namespace experimental {
19 
20 static constexpr size_t NumButtons = 8;
21 
22 struct MobileIODiff;
23 class MobileIO;
24 
25 // The current state at any time
26 struct MobileIOState {
27  // Note: one-indexed to match buttons on the screen
28  bool getButton(size_t button) const;
29  float getAxis(size_t axis) const;
30 
31 private:
32  std::bitset<NumButtons> buttons_;
33  std::array<float, NumButtons> axes_;
34 
35  friend struct MobileIODiff;
36  friend class MobileIO;
37 };
38 
39 // Difference between two IO states, useful for checking to see if a button
40 // has been pressed.
41 struct MobileIODiff {
42  MobileIODiff(const MobileIOState& prev, const MobileIOState& current);
43 
44  enum class ButtonState {
45  Off, On, // These occur if last + current state are the same
46  ToOff, ToOn // Edge triggers; these occur if last + current state are different
47  };
48 
49  // Note: one-indexed to match buttons on the screen
50  ButtonState get(int button) const;
51 
52 private:
53  std::array<ButtonState, NumButtons> buttons_;
54 };
55 
56 // Wrapper around a mobile IO controller
57 class MobileIO {
58 public:
59  enum class ButtonMode {
61  };
62 
63  static std::unique_ptr<MobileIO> create(const std::string& family, const std::string& name);
64 
65  // Input/feedback
67  // Input/feedback; the "got_feedback" flag indicates if feedback was received within the timeout
68  // or not.
69  MobileIOState getState(bool& got_feedback);
70 
71  // Outputs
72  // Note: one-indexed to match axes/buttons on the screen
73 
74  bool disableSnap(size_t axis_number) {
75  return setSnap(axis_number, std::numeric_limits<float>::quiet_NaN());
76  }
77 
78  bool setSnap(size_t axis_number, float snap_to);
79  bool setAxisValue(size_t axis_number, float value);
80 
81  bool setButtonMode(size_t button_number, ButtonMode mode);
82  bool setButtonOutput(size_t button_number, bool on);
83 
84  bool setLedColor(uint8_t r, uint8_t g, uint8_t b);
85 
86  bool sendText(const std::string& message);
87  bool clearText();
88 
89  // Return Feedback object specific to the mobile device (not GroupFeedback)
90  const hebi::Feedback& getLastFeedback() const { return fbk_[0]; };
91 
92  // Get AR Position
93  const Vector3f getPosition() const { return fbk_[0].mobile().arPosition().get(); }
94 
95  // Get AR Orientation
96  const Quaternionf getOrientation() const { return fbk_[0].mobile().arOrientation().get(); }
97 
98 private:
99  MobileIO(std::shared_ptr<hebi::Group>);
100 
101  std::shared_ptr<hebi::Group> group_;
102  hebi::GroupFeedback fbk_;
103  MobileIOState current_state_;
104 };
105 
106 } // namespace experimental
107 } // namespace hebi
A list of Feedback objects that can be received from a Group of modules; the size() must match the nu...
Definition: group_feedback.hpp:16
Structure to hold a 3-D floating point vector (i.e., x/y/z components)
Definition: vector_3_f.hpp:8
bool clearText()
Definition: mobile_io.cpp:121
bool sendText(const std::string &message)
Definition: mobile_io.cpp:115
bool getButton(size_t button) const
Definition: mobile_io.cpp:11
static std::unique_ptr< MobileIO > create(const std::string &family, const std::string &name)
Definition: mobile_io.cpp:43
Definition: arm.cpp:5
Structure to hold a floating point quaternion (i.e., w/x/y/z components)
Definition: quaternion_f.hpp:8
bool setLedColor(uint8_t r, uint8_t g, uint8_t b)
Definition: mobile_io.cpp:109
static constexpr size_t NumButtons
Definition: mobile_io.hpp:20
Feedback objects have various fields representing feedback from modules; which fields are populated d...
Definition: feedback.hpp:32
const hebi::Feedback & getLastFeedback() const
Definition: mobile_io.hpp:90
ButtonMode
Definition: mobile_io.hpp:59
bool setSnap(size_t axis_number, float snap_to)
Definition: mobile_io.cpp:85
bool setButtonMode(size_t button_number, ButtonMode mode)
Definition: mobile_io.cpp:97
const Quaternionf getOrientation() const
Definition: mobile_io.hpp:96
ButtonState get(int button) const
Definition: mobile_io.cpp:37
MobileIOState getState()
Definition: mobile_io.cpp:51
bool setButtonOutput(size_t button_number, bool on)
Definition: mobile_io.cpp:103
bool setAxisValue(size_t axis_number, float value)
Definition: mobile_io.cpp:91
MobileIODiff(const MobileIOState &prev, const MobileIOState &current)
Definition: mobile_io.cpp:24
Definition: mobile_io.hpp:41
Definition: mobile_io.hpp:26
bool disableSnap(size_t axis_number)
Definition: mobile_io.hpp:74
Definition: mobile_io.hpp:57
ButtonState
Definition: mobile_io.hpp:44
const Vector3f getPosition() const
Definition: mobile_io.hpp:93
float getAxis(size_t axis) const
Definition: mobile_io.cpp:17