Go to the documentation of this file.00001
00009
00010
00011
00012
00013 #ifndef KOBUKI_BUTTON_EVENT_HPP_
00014 #define KOBUKI_BUTTON_EVENT_HPP_
00015
00016
00017
00018
00019
00020 #include <stdint.h>
00021 #include <vector>
00022 #include <ecl/sigslots.hpp>
00023
00024 #include "packets/core_sensors.hpp"
00025
00026
00027
00028
00029
00030 namespace kobuki {
00031
00032
00033
00034
00035
00036 struct ButtonEvent {
00037 enum State {
00038 Released,
00039 Pressed
00040 } state;
00041 enum Button {
00042 Button0,
00043 Button1,
00044 Button2
00045 } button;
00046 };
00047
00048 struct BumperEvent {
00049 enum State {
00050 Released,
00051 Pressed
00052 } state;
00053 enum Bumper {
00054 Left,
00055 Center,
00056 Right
00057 } bumper;
00058 };
00059
00060 struct CliffEvent {
00061 enum State {
00062 Floor,
00063 Cliff
00064 } state;
00065 enum Sensor {
00066 Left,
00067 Center,
00068 Right
00069 } sensor;
00070 uint16_t bottom;
00071 };
00072
00073 struct WheelEvent {
00074 enum State {
00075 Raised,
00076 Dropped
00077 } state;
00078 enum Wheel {
00079 Left,
00080 Right
00081 } wheel;
00082 };
00083
00084 struct PowerEvent {
00085 enum Event {
00086 Unplugged = 0,
00087 PluggedToAdapter = 1,
00088 PluggedToDockbase = 2,
00089 ChargeCompleted = 3,
00090 BatteryLow = 4,
00091 BatteryCritical = 5
00092 } event;
00093 };
00094
00095 struct InputEvent {
00096 bool values[4];
00097 };
00098
00099 struct RobotEvent {
00100 enum State {
00101 Offline,
00102 Online,
00103 Unknown
00104 } state;
00105 };
00106
00107
00108
00109
00110
00111 class EventManager {
00112 public:
00113 EventManager() {
00114 last_state.buttons = 0;
00115 last_state.bumper = 0;
00116 last_state.cliff = 0;
00117 last_state.wheel_drop = 0;
00118 last_state.charger = 0;
00119 last_state.battery = 0;
00120 last_digital_input = 0;
00121 last_robot_state = RobotEvent::Unknown;
00122 }
00123
00124 void init(const std::string &sigslots_namespace);
00125 void update(const CoreSensors::Data &new_state, const std::vector<uint16_t> &cliff_data);
00126 void update(const uint16_t &digital_input);
00127 void update(bool is_plugged, bool is_alive);
00128
00129 private:
00130 CoreSensors::Data last_state;
00131 uint16_t last_digital_input;
00132 RobotEvent::State last_robot_state;
00133
00134 ecl::Signal<const ButtonEvent&> sig_button_event;
00135 ecl::Signal<const BumperEvent&> sig_bumper_event;
00136 ecl::Signal<const CliffEvent&> sig_cliff_event;
00137 ecl::Signal<const WheelEvent&> sig_wheel_event;
00138 ecl::Signal<const PowerEvent&> sig_power_event;
00139 ecl::Signal<const InputEvent&> sig_input_event;
00140 ecl::Signal<const RobotEvent&> sig_robot_event;
00141 };
00142
00143
00144 }
00145
00146 #endif