Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * button_thread.h - Provide Nao buttons to Fawkes 00004 * 00005 * Created: Mon Aug 15 10:48:49 2011 00006 * Copyright 2006-2011 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #ifndef __PLUGINS_NAO_BUTTON_THREAD_H_ 00024 #define __PLUGINS_NAO_BUTTON_THREAD_H_ 00025 00026 #include <core/threading/thread.h> 00027 #include <aspect/clock.h> 00028 #include <aspect/logging.h> 00029 #include <aspect/configurable.h> 00030 #include <aspect/blackboard.h> 00031 #include <aspect/blocked_timing.h> 00032 #include <plugins/nao/aspect/naoqi.h> 00033 #include <core/utils/lock_vector.h> 00034 00035 #include <interfaces/SwitchInterface.h> 00036 00037 #include <alcommon/alproxy.h> 00038 00039 #include <vector> 00040 00041 namespace AL { 00042 class ALAudioPlayerProxy; 00043 } 00044 namespace fawkes { 00045 class NaoSensorInterface; 00046 class SwitchInterface; 00047 } 00048 00049 class NaoQiButtonThread 00050 : public fawkes::Thread, 00051 public fawkes::LoggingAspect, 00052 public fawkes::ConfigurableAspect, 00053 public fawkes::BlockedTimingAspect, 00054 public fawkes::ClockAspect, 00055 public fawkes::BlackBoardAspect, 00056 public fawkes::NaoQiAspect 00057 { 00058 public: 00059 NaoQiButtonThread(); 00060 virtual ~NaoQiButtonThread(); 00061 00062 virtual void init(); 00063 virtual void loop(); 00064 virtual void finalize(); 00065 00066 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */ 00067 protected: virtual void run() { Thread::run(); } 00068 00069 private: 00070 void set_interface(fawkes::SwitchInterface *switch_if, 00071 bool enabled, float value, float history, 00072 unsigned int activations, 00073 unsigned int short_act, unsigned int long_act); 00074 00075 void process_messages(fawkes::SwitchInterface *switch_if, 00076 bool &remote_enabled, float &value); 00077 00078 void pattern_button_logic(float value, float time_diff_sec, 00079 bool &enabled, float &history, 00080 unsigned int &activations, 00081 unsigned int &short_act, unsigned int &long_act, 00082 int sound_short, int sound_long); 00083 00084 void bumpers_logic(float value, float time_diff_sec, 00085 bool &enabled, float &history, 00086 unsigned int &activations, int sound_id); 00087 00088 void process_pattern_button(fawkes::SwitchInterface *switch_if, 00089 float sensor_value, float time_diff_sec, 00090 bool &remote_enabled, 00091 int sound_short = -1, int sound_long = -1); 00092 void process_bumpers(fawkes::SwitchInterface *switch_if, 00093 float left_value, float right_value, 00094 float time_diff_sec, 00095 bool &remote_enabled, int sound_id = -1); 00096 00097 private: 00098 AL::ALPtr<AL::ALAudioPlayerProxy> __auplayer; 00099 00100 AL::ALProcessSignals::ProcessSignalConnection __dcm_sigconn; 00101 00102 fawkes::NaoSensorInterface *__sensor_if; 00103 fawkes::SwitchInterface *__chestbut_if; 00104 fawkes::SwitchInterface *__lfoot_bumper_if; 00105 fawkes::SwitchInterface *__rfoot_bumper_if; 00106 fawkes::SwitchInterface *__head_front_if; 00107 fawkes::SwitchInterface *__head_middle_if; 00108 fawkes::SwitchInterface *__head_rear_if; 00109 00110 fawkes::Time now; 00111 fawkes::Time last; 00112 00113 int __sound_longpling; 00114 int __sound_pling; 00115 int __sound_bumper_left; 00116 int __sound_bumper_right; 00117 00118 bool __chestbut_remote_enabled; 00119 bool __lfoot_bumper_remote_enabled; 00120 bool __rfoot_bumper_remote_enabled; 00121 bool __head_front_remote_enabled; 00122 bool __head_middle_remote_enabled; 00123 bool __head_rear_remote_enabled; 00124 00125 unsigned int last_shutdown_actcount; 00126 bool __cfg_chest_triple_long_click_shutdown; 00127 }; 00128 00129 #endif