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 "hebi_cpp_api/group.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 {
60  Momentary, Toggle
61  };
62 
63  static std::unique_ptr<MobileIO> create(const std::string& family, const std::string& name);
64 
65  // Input/feedback
66  MobileIOState getState();
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 private:
93  MobileIO(std::shared_ptr<hebi::Group>);
94 
95  std::shared_ptr<hebi::Group> group_;
98 };
99 
100 } // namespace experimental
101 } // namespace hebi
std::shared_ptr< hebi::Group > group_
Definition: mobile_io.hpp:95
std::array< ButtonState, NumButtons > buttons_
Definition: mobile_io.hpp:53
A list of Feedback objects that can be received from a Group of modules; the size() must match the nu...
float getAxis(size_t axis) const
Definition: mobile_io.cpp:17
std::array< float, NumButtons > axes_
Definition: mobile_io.hpp:33
std::bitset< NumButtons > buttons_
Definition: mobile_io.hpp:32
Definition: arm.cpp:5
bool getButton(size_t button) const
Definition: mobile_io.cpp:11
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
hebi::GroupFeedback fbk_
Definition: mobile_io.hpp:96
MobileIOState current_state_
Definition: mobile_io.hpp:97
const hebi::Feedback & getLastFeedback() const
Definition: mobile_io.hpp:90
bool disableSnap(size_t axis_number)
Definition: mobile_io.hpp:74


hebi_cpp_api_ros
Author(s): Chris Bollinger , Matthew Tesch
autogenerated on Thu May 28 2020 03:14:45