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


kobuki_driver
Author(s): Daniel Stonier , Younghun Ju , Jorge Santos Simon
autogenerated on Thu Jun 6 2019 20:24:37