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 <alcommon/alproxy.h>
27#include <aspect/blackboard.h>
28#include <aspect/blocked_timing.h>
29#include <aspect/clock.h>
30#include <aspect/configurable.h>
31#include <aspect/logging.h>
32#include <core/threading/thread.h>
33#include <core/utils/lock_vector.h>
34#include <interfaces/SwitchInterface.h>
35#include <plugins/nao/aspect/naoqi.h>
36
37#include <vector>
38
39namespace AL {
40class ALAudioPlayerProxy;
41}
42namespace fawkes {
43class NaoSensorInterface;
44class SwitchInterface;
45} // namespace fawkes
46
54{
55public:
57 virtual ~NaoQiButtonThread();
58
59 virtual void init();
60 virtual void loop();
61 virtual void finalize();
62
63 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
64protected:
65 virtual void
67 {
68 Thread::run();
69 }
70
71private:
72 void set_interface(fawkes::SwitchInterface *switch_if,
73 bool enabled,
74 float value,
75 float history,
76 unsigned int activations,
77 unsigned int short_act,
78 unsigned int long_act);
79
80 void process_messages(fawkes::SwitchInterface *switch_if, bool &remote_enabled, float &value);
81
82 void pattern_button_logic(float value,
83 float time_diff_sec,
84 bool & enabled,
85 float & history,
86 unsigned int &activations,
87 unsigned int &short_act,
88 unsigned int &long_act,
89 int sound_short,
90 int sound_long);
91
92 void bumpers_logic(float value,
93 float time_diff_sec,
94 bool & enabled,
95 float & history,
96 unsigned int &activations,
97 int sound_id);
98
99 void process_pattern_button(fawkes::SwitchInterface *switch_if,
100 float sensor_value,
101 float time_diff_sec,
102 bool & remote_enabled,
103 int sound_short = -1,
104 int sound_long = -1);
105 void process_bumpers(fawkes::SwitchInterface *switch_if,
106 float left_value,
107 float right_value,
108 float time_diff_sec,
109 bool & remote_enabled,
110 int sound_id = -1);
111
112private:
113 AL::ALPtr<AL::ALAudioPlayerProxy> auplayer_;
114
115 AL::ALProcessSignals::ProcessSignalConnection dcm_sigconn_;
116
117 fawkes::NaoSensorInterface *sensor_if_;
118 fawkes::SwitchInterface * chestbut_if_;
119 fawkes::SwitchInterface * lfoot_bumper_if_;
120 fawkes::SwitchInterface * rfoot_bumper_if_;
121 fawkes::SwitchInterface * head_front_if_;
122 fawkes::SwitchInterface * head_middle_if_;
123 fawkes::SwitchInterface * head_rear_if_;
124
125 fawkes::Time now;
126 fawkes::Time last;
127
128 int sound_longpling_;
129 int sound_pling_;
130 int sound_bumper_left_;
131 int sound_bumper_right_;
132
133 bool chestbut_remote_enabled_;
134 bool lfoot_bumper_remote_enabled_;
135 bool rfoot_bumper_remote_enabled_;
136 bool head_front_remote_enabled_;
137 bool head_middle_remote_enabled_;
138 bool head_rear_remote_enabled_;
139
140 unsigned int last_shutdown_actcount;
141 bool cfg_chest_triple_long_click_shutdown_;
142};
143
144#endif
Thread to provide buttons to Fawkes.
Definition: button_thread.h:54
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: button_thread.h:66
NaoQiButtonThread()
Constructor.
virtual void loop()
Code to execute in the thread.
virtual void finalize()
Finalize the thread.
virtual void init()
Initialize the thread.
virtual ~NaoQiButtonThread()
Destructor.
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
Thread aspect to use blocked timing.
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:34
Thread aspect to access configuration data.
Definition: configurable.h:33
Thread aspect to log output.
Definition: logging.h:33
Thread aspect to get access to NaoQi broker.
Definition: naoqi.h:36
NaoSensorInterface Fawkes BlackBoard Interface.
SwitchInterface Fawkes BlackBoard Interface.
Thread class encapsulation of pthreads.
Definition: thread.h:46
A class for handling time.
Definition: time.h:93
Fawkes library namespace.