HEBI C++ API  3.8.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 util {
19 
20 // Wrapper around a mobile IO controller
21 class MobileIO {
22 public:
23  static constexpr size_t NumButtons = 8;
24 
25  enum class ButtonMode { Momentary = 0, Toggle = 1 };
26 
27  enum class ButtonState {
28  ToOff = -1, // Edge triggers; these occur if last + current state are different
29  Unchanged = 0, // Last + current state are the same
30  ToOn = 1 // Edge triggers; these occur if last + current state are different
31  };
32 
33  static std::unique_ptr<MobileIO> create(const std::string& family, const std::string& name);
34 
35  // Call to update the current state. Returns "true" if feedback was received within the timeout
36  // or not.
37  bool update(int32_t timeout_ms = Group::DEFAULT_TIMEOUT_MS);
38 
39  bool resetUI(bool acknowledge_send = true);
40 
41  // Outputs
42  // Note: one-indexed to match axes/buttons on the screen
43 
44  bool setAxisSnap(int axis_number, float snap_to, bool acknowledge_send = true);
45  bool disableAxisSnap(int axis_number, bool acknowledge_send = true) { return setAxisSnap(axis_number, std::numeric_limits<float>::quiet_NaN()); }
46  bool setAxisValue(int axis_number, float value, bool acknowledge_send = true);
47  bool setAxisLabel(int axis_number, const std::string& message, bool acknowledge_send = true);
48 
49  bool setButtonMode(int button_number, ButtonMode mode, bool acknowledge_send = true);
50  bool setButtonLed(int button_number, bool on, bool acknowledge_send = true);
51  // NB: needs support on mobile IO app side...
52  //bool setButtonLed(int button_number, hebi::Color color);
53  bool setButtonLabel(int button_number, const std::string& message, bool acknowledge_send = true);
54 
55  bool setLedColor(uint8_t r, uint8_t g, uint8_t b, bool acknowledge_send = true);
56 
57  bool appendText(const std::string& message, bool acknowledge_send = true);
58  bool clearText(bool acknowledge_send = true);
59 
60  // Return Feedback object specific to the mobile device (not GroupFeedback)
61  const hebi::Feedback& getLastFeedback() const { return fbk_[0]; };
62 
63  // Get AR Position
64  const Vector3f getArPosition() const { return fbk_[0].mobile().arPosition().get(); }
65 
66  // Get AR Orientation
67  const Quaternionf getArOrientation() const { return fbk_[0].mobile().arOrientation().get(); }
68 
69  // Get current state of axis; one-indexed to match axes on the screen
70  float getAxis(int axis) const;
71  // Get current state of button; one-indexed to match buttons on the screen
72  bool getButton(int button) const;
73 
74  // Difference between two IO states, useful for checking to see if a button
75  // has been pressed.
76  // Note: one-indexed to match buttons on the screen
77  ButtonState getButtonDiff(int button) const;
78 
79 private:
80  MobileIO(std::shared_ptr<hebi::Group> group) : group_(std::move(group)), fbk_(group_->size()) {}
81 
82  std::shared_ptr<hebi::Group> group_;
84 
85  std::bitset<NumButtons> buttons_{};
86  std::array<float, NumButtons> axes_{};
87 
88  std::bitset<NumButtons> prev_buttons_{};
89  std::array<float, NumButtons> prev_axes_{};
90 };
91 
92 } // namespace util
93 } // 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:18
ButtonState getButtonDiff(int button) const
Definition: mobile_io.cpp:175
Structure to hold a 3-D floating point vector (i.e., x/y/z components)
Definition: vector_3_f.hpp:8
bool setAxisLabel(int axis_number, const std::string &message, bool acknowledge_send=true)
Definition: mobile_io.cpp:90
bool update(int32_t timeout_ms=Group::DEFAULT_TIMEOUT_MS)
Definition: mobile_io.cpp:23
Definition: arm.cpp:8
Structure to hold a floating point quaternion (i.e., w/x/y/z components)
Definition: quaternion_f.hpp:8
static const int32_t DEFAULT_TIMEOUT_MS
The default timeout for any send-with-acknowledgement or request operation is 500 ms.
Definition: group.hpp:77
const Vector3f getArPosition() const
Definition: mobile_io.hpp:64
static std::unique_ptr< MobileIO > create(const std::string &family, const std::string &name)
Definition: mobile_io.cpp:14
Feedback objects have various fields representing feedback from modules; which fields are populated d...
Definition: feedback.hpp:32
Definition: mobile_io.hpp:21
bool setButtonLed(int button_number, bool on, bool acknowledge_send=true)
Definition: mobile_io.cpp:110
bool appendText(const std::string &message, bool acknowledge_send=true)
Definition: mobile_io.cpp:147
bool setButtonLabel(int button_number, const std::string &message, bool acknowledge_send=true)
Definition: mobile_io.cpp:129
bool setButtonMode(int button_number, ButtonMode mode, bool acknowledge_send=true)
Definition: mobile_io.cpp:100
bool setLedColor(uint8_t r, uint8_t g, uint8_t b, bool acknowledge_send=true)
Definition: mobile_io.cpp:139
const hebi::Feedback & getLastFeedback() const
Definition: mobile_io.hpp:61
bool resetUI(bool acknowledge_send=true)
Definition: mobile_io.cpp:52
float getAxis(int axis) const
Definition: mobile_io.cpp:163
bool clearText(bool acknowledge_send=true)
Definition: mobile_io.cpp:155
bool getButton(int button) const
Definition: mobile_io.cpp:169
const Quaternionf getArOrientation() const
Definition: mobile_io.hpp:67
bool setAxisValue(int axis_number, float value, bool acknowledge_send=true)
Definition: mobile_io.cpp:80
ButtonMode
Definition: mobile_io.hpp:25
bool setAxisSnap(int axis_number, float snap_to, bool acknowledge_send=true)
Definition: mobile_io.cpp:70
bool disableAxisSnap(int axis_number, bool acknowledge_send=true)
Definition: mobile_io.hpp:45
ButtonState
Definition: mobile_io.hpp:27
static constexpr size_t NumButtons
Definition: mobile_io.hpp:23