23 #include "button_thread.h" 25 #include <alproxies/allauncherproxy.h> 26 #include <alproxies/dcmproxy.h> 27 #include <alproxies/alaudioplayerproxy.h> 28 #include <alproxies/almemoryproxy.h> 29 #include <alproxies/alsentinelproxy.h> 30 #include <alcore/alerror.h> 31 #include <almemoryfastaccess/almemoryfastaccess.h> 33 #include <interfaces/NaoSensorInterface.h> 34 #include <interfaces/SwitchInterface.h> 36 #include <boost/bind.hpp> 43 #define POWEROFF_PATH "/sbin/poweroff" 59 :
Thread(
"NaoQiButtonThread",
Thread::OPMODE_WAITFORWAKEUP),
74 __sound_longpling = __sound_pling = -1;
75 __sound_bumper_left = __sound_bumper_right = -1;
76 last_shutdown_actcount = 0;
78 __cfg_chest_triple_long_click_shutdown =
false;
80 __cfg_chest_triple_long_click_shutdown =
81 config->
get_bool(
"/hardware/nao/chestbut_triple_long_click_shutdown");
86 AL::ALPtr<AL::ALLauncherProxy> launcher(
new AL::ALLauncherProxy(
naoqi_broker));
87 bool is_auplayer_available = launcher->isModulePresent(
"ALAudioPlayer");
88 bool is_alsentinel_available = launcher->isModulePresent(
"ALSentinel");
90 if (! is_auplayer_available) {
94 AL::ALPtr<AL::ALAudioPlayerProxy>(
new AL::ALAudioPlayerProxy(
naoqi_broker));
95 __sound_longpling = __auplayer->loadFile(RESDIR
"/sounds/longpling.wav");
96 __sound_pling = __auplayer->loadFile(RESDIR
"/sounds/pling.wav");
98 __auplayer->loadFile(RESDIR
"/sounds/metal_click_1_left.wav");
99 __sound_bumper_right =
100 __auplayer->loadFile(RESDIR
"/sounds/metal_click_1_right.wav");
103 if (is_alsentinel_available) {
105 AL::ALPtr<AL::ALSentinelProxy>
107 alsentinel->enableDefaultActionSimpleClick(
false);
108 alsentinel->enableDefaultActionDoubleClick(
false);
109 alsentinel->enableDefaultActionTripleClick(
false);
111 }
catch (AL::ALError& e) {
112 throw Exception(
"Checking module availability failed: %s",
113 e.toString().c_str());
139 __chestbut_remote_enabled =
false;
140 __lfoot_bumper_remote_enabled = __rfoot_bumper_remote_enabled =
false;
141 __head_front_remote_enabled = __head_middle_remote_enabled =
142 __head_rear_remote_enabled =
false;
161 __chestbut_if = NULL;
162 __lfoot_bumper_if = NULL;
163 __rfoot_bumper_if = NULL;
164 __head_front_if = NULL;
165 __head_middle_if = NULL;
166 __head_rear_if = NULL;
170 __auplayer->unloadFile(__sound_longpling);
171 __auplayer->unloadFile(__sound_pling);
172 __auplayer->unloadFile(__sound_bumper_left);
173 __auplayer->unloadFile(__sound_bumper_right);
189 process_pattern_button(__chestbut_if, __sensor_if->
chest_button(),
190 time_diff_sec, __chestbut_remote_enabled,
191 __sound_pling, __sound_longpling);
193 time_diff_sec, __head_front_remote_enabled);
195 time_diff_sec, __head_middle_remote_enabled);
197 time_diff_sec, __head_rear_remote_enabled);
201 __lfoot_bumper_remote_enabled, __sound_bumper_left);
205 __rfoot_bumper_remote_enabled, __sound_bumper_right);
207 if (__cfg_chest_triple_long_click_shutdown &&
213 if (__auplayer) __auplayer->playFile(RESDIR
"/sounds/naoshutdown.wav");
216 if (stat(POWEROFF_PATH, &s) == -1) {
220 if (s.st_mode & S_ISUID) {
221 int rv = system(POWEROFF_PATH);
222 if (rv == -1 || (WEXITSTATUS(rv) != 0)) {
236 bool enabled,
float value,
float history,
237 unsigned int activations,
238 unsigned int short_act,
unsigned int long_act)
256 bool &remote_enabled,
257 int sound_short,
int sound_long)
260 process_messages(switch_if, remote_enabled, value);
261 value = std::max(value, sensor_value);
263 bool enabled =
false;
264 float history = switch_if->
history();
270 activations, short_act, long_act,
271 sound_short, sound_long);
273 set_interface(switch_if, enabled, value, history,
274 activations, short_act, long_act);
280 float left_value,
float right_value,
282 bool &remote_enabled,
int sound_id)
285 process_messages(switch_if, remote_enabled, value);
286 value = std::max(std::max(value, left_value), right_value);
288 bool enabled =
false;
289 float history = switch_if->
history();
294 bumpers_logic(value,
time_diff_sec, enabled, history, activations, sound_id);
296 set_interface(switch_if, enabled, value, history,
297 activations, short_act, long_act);
304 bool &remote_enabled,
float &value)
309 if (msg->is_enabled()) {
310 value = std::min(0.5f, msg->value());
312 value = std::max(0.49f, msg->value());
321 remote_enabled =
true;
328 remote_enabled =
false;
335 if (remote_enabled) value = 1.;
340 NaoQiButtonThread::pattern_button_logic(
float value,
float time_diff_sec,
341 bool &enabled,
float &history,
342 unsigned int &activations,
343 unsigned int &short_act,
344 unsigned int &long_act,
345 int sound_short,
int sound_long)
348 if (history > 0.025 ) {
352 if (__auplayer && (sound_long != -1)) __auplayer->play(sound_long);
355 if (__auplayer && (sound_short != -1)) __auplayer->play(sound_short);
357 }
else if ( history < -2.0 ) {
359 short_act = long_act = 0;
363 if ( history < 0. ) {
371 if ( history > 0. ) {
379 if (history < -120.) {
381 }
else if (history > 120.) {
388 NaoQiButtonThread::bumpers_logic(
float value,
float time_diff_sec,
389 bool &enabled,
float &history,
390 unsigned int &activations,
int sound_id)
394 if ( history < 0. ) {
401 if (history <= 0. ) {
402 if (__auplayer && (sound_id != -1)) __auplayer->play(sound_id);
407 if ( history > 0. ) {
415 if (history < -120.) {
417 }
else if (history > 120.) {
uint8_t r_foot_bumper_r() const
Get r_foot_bumper_r value.
SetMessage Fawkes BlackBoard Interface Message.
bool msgq_empty()
Check if queue is empty.
uint8_t l_foot_bumper_l() const
Get l_foot_bumper_l value.
Fawkes library namespace.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
AL::ALPtr< AL::ALBroker > naoqi_broker
NaoQi broker.
const char * id() const
Get identifier of interface.
uint32_t short_activations() const
Get short_activations value.
uint32_t activation_count() const
Get activation_count value.
uint8_t l_foot_bumper_r() const
Get l_foot_bumper_r value.
Thread class encapsulation of pthreads.
NaoSensorInterface Fawkes BlackBoard Interface.
void set_history(const float new_history)
Set history value.
void write()
Write from local copy into BlackBoard memory.
uint32_t long_activations() const
Get long_activations value.
Logger * logger
This is the Logger member used to access the logger.
void set_short_activations(const uint32_t new_short_activations)
Set short_activations value.
Clock * clock
By means of this member access to the clock is given.
Thread aspect to use blocked timing.
void msgq_pop()
Erase first message from queue.
SwitchInterface Fawkes BlackBoard Interface.
void set_activation_count(const uint32_t new_activation_count)
Set activation_count value.
Base class for exceptions in Fawkes.
void set_clock(Clock *clock)
Set clock for this instance.
void read()
Read from BlackBoard into local copy.
void set_enabled(const bool new_enabled)
Set enabled value.
double time_diff_sec(const timeval &a, const timeval &b)
Calculate time difference of two time structs.
uint8_t chest_button() const
Get chest_button value.
DisableSwitchMessage Fawkes BlackBoard Interface Message.
void copy_shared_to_buffer(unsigned int buffer)
Copy data from private memory to buffer.
const char * name() const
Get name of thread.
float history() const
Get history value.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
void set_long_activations(const uint32_t new_long_activations)
Set long_activations value.
EnableSwitchMessage Fawkes BlackBoard Interface Message.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
void resize_buffers(unsigned int num_buffers)
Resize buffer array.
MessageType * msgq_first_safe(MessageType *&msg)
Get first message casted to the desired type without exceptions.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
uint8_t head_touch_rear() const
Get head_touch_rear value.
void set_value(const float new_value)
Set value value.
uint8_t r_foot_bumper_l() const
Get r_foot_bumper_l value.
int compare_buffers(unsigned int buffer)
Compare buffer to private memory.
Time & stamp()
Set this time to the current time.
Configuration * config
This is the Configuration member used to access the configuration.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
uint8_t head_touch_front() const
Get head_touch_front value.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
uint8_t head_touch_middle() const
Get head_touch_middle value.
virtual void close(Interface *interface)=0
Close interface.