Fawkes API  Fawkes Development Version
button_thread.h
1 
2 /***************************************************************************
3  * button_thread.h - Provide Nao buttons to Fawkes
4  *
5  * Created: Mon Aug 15 10:48:49 2011
6  * Copyright 2006-2011 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef __PLUGINS_NAO_BUTTON_THREAD_H_
24 #define __PLUGINS_NAO_BUTTON_THREAD_H_
25 
26 #include <core/threading/thread.h>
27 #include <aspect/clock.h>
28 #include <aspect/logging.h>
29 #include <aspect/configurable.h>
30 #include <aspect/blackboard.h>
31 #include <aspect/blocked_timing.h>
32 #include <plugins/nao/aspect/naoqi.h>
33 #include <core/utils/lock_vector.h>
34 
35 #include <interfaces/SwitchInterface.h>
36 
37 #include <alcommon/alproxy.h>
38 
39 #include <vector>
40 
41 namespace AL {
42  class ALAudioPlayerProxy;
43 }
44 namespace fawkes {
45  class NaoSensorInterface;
46  class SwitchInterface;
47 }
48 
50 : public fawkes::Thread,
51  public fawkes::LoggingAspect,
54  public fawkes::ClockAspect,
56  public fawkes::NaoQiAspect
57 {
58  public:
60  virtual ~NaoQiButtonThread();
61 
62  virtual void init();
63  virtual void loop();
64  virtual void finalize();
65 
66  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
67  protected: virtual void run() { Thread::run(); }
68 
69  private:
70  void set_interface(fawkes::SwitchInterface *switch_if,
71  bool enabled, float value, float history,
72  unsigned int activations,
73  unsigned int short_act, unsigned int long_act);
74 
75  void process_messages(fawkes::SwitchInterface *switch_if,
76  bool &remote_enabled, float &value);
77 
78  void pattern_button_logic(float value, float time_diff_sec,
79  bool &enabled, float &history,
80  unsigned int &activations,
81  unsigned int &short_act, unsigned int &long_act,
82  int sound_short, int sound_long);
83 
84  void bumpers_logic(float value, float time_diff_sec,
85  bool &enabled, float &history,
86  unsigned int &activations, int sound_id);
87 
88  void process_pattern_button(fawkes::SwitchInterface *switch_if,
89  float sensor_value, float time_diff_sec,
90  bool &remote_enabled,
91  int sound_short = -1, int sound_long = -1);
92  void process_bumpers(fawkes::SwitchInterface *switch_if,
93  float left_value, float right_value,
94  float time_diff_sec,
95  bool &remote_enabled, int sound_id = -1);
96 
97  private:
98  AL::ALPtr<AL::ALAudioPlayerProxy> __auplayer;
99 
100  AL::ALProcessSignals::ProcessSignalConnection __dcm_sigconn;
101 
102  fawkes::NaoSensorInterface *__sensor_if;
103  fawkes::SwitchInterface *__chestbut_if;
104  fawkes::SwitchInterface *__lfoot_bumper_if;
105  fawkes::SwitchInterface *__rfoot_bumper_if;
106  fawkes::SwitchInterface *__head_front_if;
107  fawkes::SwitchInterface *__head_middle_if;
108  fawkes::SwitchInterface *__head_rear_if;
109 
110  fawkes::Time now;
111  fawkes::Time last;
112 
113  int __sound_longpling;
114  int __sound_pling;
115  int __sound_bumper_left;
116  int __sound_bumper_right;
117 
118  bool __chestbut_remote_enabled;
119  bool __lfoot_bumper_remote_enabled;
120  bool __rfoot_bumper_remote_enabled;
121  bool __head_front_remote_enabled;
122  bool __head_middle_remote_enabled;
123  bool __head_rear_remote_enabled;
124 
125  unsigned int last_shutdown_actcount;
126  bool __cfg_chest_triple_long_click_shutdown;
127 };
128 
129 #endif
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:36
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: button_thread.h:67
Fawkes library namespace.
Thread to provide buttons to Fawkes.
Definition: button_thread.h:49
A class for handling time.
Definition: time.h:91
Thread class encapsulation of pthreads.
Definition: thread.h:42
NaoSensorInterface Fawkes BlackBoard Interface.
Thread aspect to use blocked timing.
SwitchInterface Fawkes BlackBoard Interface.
Thread aspect to log output.
Definition: logging.h:35
Thread aspect to get access to NaoQi broker.
Definition: naoqi.h:36
Thread aspect to access configuration data.
Definition: configurable.h:35