event_manager.hpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Ifdefs
11 *****************************************************************************/
12 
13 #ifndef KOBUKI_BUTTON_EVENT_HPP_
14 #define KOBUKI_BUTTON_EVENT_HPP_
15 
16 /*****************************************************************************
17 ** Includes
18 *****************************************************************************/
19 
20 #include <stdint.h>
21 #include <vector>
22 #include <ecl/sigslots.hpp>
23 
24 #include "packets/core_sensors.hpp"
25 #include "macros.hpp"
26 
27 /*****************************************************************************
28 ** Namespaces
29 *****************************************************************************/
30 
31 namespace kobuki {
32 
33 /*****************************************************************************
34 ** Event Structures
35 *****************************************************************************/
36 
37 struct ButtonEvent {
38  enum State {
39  Released,
40  Pressed
41  } state;
42  enum Button {
44  Button1,
45  Button2
46  } button;
47 };
48 
49 struct BumperEvent {
50  enum State {
51  Released,
53  } state;
54  enum Bumper {
58  } bumper;
59 };
60 
61 struct CliffEvent {
62  enum State {
64  Cliff
65  } state;
66  enum Sensor {
70  } sensor;
71  uint16_t bottom;
72 };
73 
74 struct WheelEvent {
75  enum State {
76  Raised,
78  } state;
79  enum Wheel {
82  } wheel;
83 };
84 
85 struct PowerEvent {
86  enum Event {
87  Unplugged = 0,
88  PluggedToAdapter = 1,
90  ChargeCompleted = 3,
93  } event;
94 };
95 
96 struct InputEvent {
97  bool values[4];
98 };
99 
100 struct RobotEvent {
101  enum State {
104  Unknown // at startup
105  } state;
106 };
107 
108 /*****************************************************************************
109 ** Interfaces
110 *****************************************************************************/
111 
113 public:
114  EventManager() {
115  last_state.buttons = 0;
116  last_state.bumper = 0;
117  last_state.cliff = 0;
118  last_state.wheel_drop = 0;
119  last_state.charger = 0;
120  last_state.battery = 0;
121  last_digital_input = 0;
122  last_robot_state = RobotEvent::Unknown;
123  }
124 
125  void init(const std::string &sigslots_namespace);
126  void update(const CoreSensors::Data &new_state, const std::vector<uint16_t> &cliff_data);
127  void update(const uint16_t &digital_input);
128  void update(bool is_plugged, bool is_alive);
129 
130 private:
131  CoreSensors::Data last_state;
132  uint16_t last_digital_input;
133  RobotEvent::State last_robot_state;
134 
135  ecl::Signal<const ButtonEvent&> sig_button_event;
136  ecl::Signal<const BumperEvent&> sig_bumper_event;
137  ecl::Signal<const CliffEvent&> sig_cliff_event;
138  ecl::Signal<const WheelEvent&> sig_wheel_event;
142 };
143 
144 
145 } // namespace kobuki
146 
147 #endif /* KOBUKI_BUTTON_EVENT_HPP_ */
kobuki::WheelEvent::Left
@ Left
Definition: event_manager.hpp:86
kobuki::CliffEvent::Left
@ Left
Definition: event_manager.hpp:73
kobuki::InputEvent
Definition: event_manager.hpp:102
kobuki::ButtonEvent::Button1
@ Button1
Definition: event_manager.hpp:58
kobuki::ButtonEvent::Button
Button
Definition: event_manager.hpp:56
kobuki::CliffEvent::bottom
uint16_t bottom
Definition: event_manager.hpp:77
kobuki::ButtonEvent::Button0
@ Button0
Definition: event_manager.hpp:57
kobuki::BumperEvent::Left
@ Left
Definition: event_manager.hpp:61
kobuki::CoreSensors::Data
Definition: core_sensors.hpp:54
kobuki::BumperEvent::Right
@ Right
Definition: event_manager.hpp:63
kobuki::RobotEvent::Offline
@ Offline
Definition: event_manager.hpp:108
kobuki
Definition: command.hpp:31
kobuki::ButtonEvent::Pressed
@ Pressed
Definition: event_manager.hpp:62
kobuki::RobotEvent::Unknown
@ Unknown
Definition: event_manager.hpp:110
sigslots.hpp
kobuki::ButtonEvent::Button2
@ Button2
Definition: event_manager.hpp:59
kobuki::PowerEvent::ChargeCompleted
@ ChargeCompleted
Definition: event_manager.hpp:96
kobuki::ButtonEvent::State
State
Definition: event_manager.hpp:52
kobuki::WheelEvent::wheel
enum kobuki::WheelEvent::Wheel wheel
kobuki::BumperEvent::bumper
enum kobuki::BumperEvent::Bumper bumper
kobuki::WheelEvent
Definition: event_manager.hpp:80
kobuki::RobotEvent::state
enum kobuki::RobotEvent::State state
kobuki::WheelEvent::state
enum kobuki::WheelEvent::State state
kobuki::WheelEvent::Dropped
@ Dropped
Definition: event_manager.hpp:83
kobuki::PowerEvent::PluggedToDockbase
@ PluggedToDockbase
Definition: event_manager.hpp:95
kobuki::PowerEvent::BatteryCritical
@ BatteryCritical
Definition: event_manager.hpp:98
kobuki::CliffEvent::State
State
Definition: event_manager.hpp:68
kobuki::CliffEvent::Floor
@ Floor
Definition: event_manager.hpp:69
macros.hpp
Macros for kobuki_driver.
kobuki::WheelEvent::Wheel
Wheel
Definition: event_manager.hpp:85
kobuki::WheelEvent::Raised
@ Raised
Definition: event_manager.hpp:82
kobuki::BumperEvent::State
State
Definition: event_manager.hpp:56
kobuki::RobotEvent
Definition: event_manager.hpp:106
kobuki::WheelEvent::Right
@ Right
Definition: event_manager.hpp:87
kobuki::ButtonEvent::Released
@ Released
Definition: event_manager.hpp:61
kobuki::ButtonEvent::button
enum kobuki::ButtonEvent::Button button
kobuki::CliffEvent
Definition: event_manager.hpp:67
core_sensors.hpp
Core sensor packet payloads.
kobuki::PowerEvent::Event
Event
Definition: event_manager.hpp:92
kobuki::Cliff
Definition: cliff.hpp:41
ecl::Signal
kobuki::BumperEvent::state
enum kobuki::BumperEvent::State state
kobuki::PowerEvent::event
enum kobuki::PowerEvent::Event event
kobuki::BumperEvent::Released
@ Released
Definition: event_manager.hpp:57
kobuki::EventManager
Definition: event_manager.hpp:118
kobuki::PowerEvent::BatteryLow
@ BatteryLow
Definition: event_manager.hpp:97
kobuki_PUBLIC
#define kobuki_PUBLIC
Definition: macros.hpp:39
kobuki::BumperEvent::Bumper
Bumper
Definition: event_manager.hpp:60
kobuki::PowerEvent::PluggedToAdapter
@ PluggedToAdapter
Definition: event_manager.hpp:94
kobuki::RobotEvent::Online
@ Online
Definition: event_manager.hpp:109
kobuki::BumperEvent::Pressed
@ Pressed
Definition: event_manager.hpp:58
kobuki::InputEvent::values
bool values[4]
Definition: event_manager.hpp:103
kobuki::CliffEvent::Center
@ Center
Definition: event_manager.hpp:74
kobuki::CliffEvent::Right
@ Right
Definition: event_manager.hpp:75
kobuki::CliffEvent::sensor
enum kobuki::CliffEvent::Sensor sensor
kobuki::RobotEvent::State
State
Definition: event_manager.hpp:107
kobuki::ButtonEvent::state
enum kobuki::ButtonEvent::State state
kobuki::CliffEvent::state
enum kobuki::CliffEvent::State state
kobuki::PowerEvent
Definition: event_manager.hpp:91
kobuki::CliffEvent::Sensor
Sensor
Definition: event_manager.hpp:72
kobuki::BumperEvent::Center
@ Center
Definition: event_manager.hpp:62
kobuki::PowerEvent::Unplugged
@ Unplugged
Definition: event_manager.hpp:93


kobuki_driver
Author(s): Daniel Stonier , Younghun Ju , Jorge Santos Simon
autogenerated on Wed Mar 2 2022 00:26:14