151
// runs a shell command when a general event occurs
152
void run_general_command(int command)
154
if( (command < 0) || (command >= GENERAL_EVENTS)) return;
156
if (general_command[command] != "") {
157
if (system(general_command[command].c_str())==0) {
158
ROS_INFO("Running command:\n%s",general_command[command].c_str());
163
// runs a shell command when a button is pressed
164
void run_button_command(int command)
166
if (button_command[command] != "") {
167
if (system(button_command[command].c_str())==0) {
168
ROS_INFO("Running command:\n%s",button_command[command].c_str());
148
174
* \brief loads place names from a comma separated string. eg. Kitchen table,Lounge,Hallway
149
175
* \param placenames string containing place names
197
say(general_sound[SOUND_ESTOP_ACTIVE], speak_command);
233
// A button was pressed but the E-stop is active
234
run_general_command(EVENT_ESTOP_ACTIVE);
235
say(general_event[EVENT_ESTOP_ACTIVE], speak_command);
198
236
ROS_WARN("Button press prevented by E-stop");
202
240
// E-stop released
203
241
if ((Estop) && (command=='e')) {
205
say(general_sound[SOUND_ESTOP_RELEASED], speak_command);
243
run_general_command(EVENT_ESTOP_RELEASED);
244
say(general_event[EVENT_ESTOP_RELEASED], speak_command);
206
245
ROS_WARN("E-stop released");
209
248
// E-stop activated
210
249
if ((!Estop) && (command=='E')) {
251
stop_motors(initialised, cmd);
212
say(general_sound[SOUND_ESTOP_PRESSED], speak_command);
254
run_general_command(EVENT_ESTOP_PRESSED);
255
say(general_event[EVENT_ESTOP_PRESSED], speak_command);
213
256
ROS_WARN("E-stop activated");
263
// make an announcement when a button is pressed
264
void button_announce(int button)
266
if (button_sound[button] !="") say(button_sound[button],speak_command);
220
269
// Do stuff when buttons are pressed
221
270
void update(bool * prev_enable, bool * prev_started, int index)
246
295
// load the initial pose
247
if (button_sound[BUTTON_START] !="") say(button_sound[BUTTON_START],speak_command);
248
if (button_command[BUTTON_START] != "") {
249
if (system(button_command[BUTTON_START].c_str())==0) {
250
ROS_INFO("Running command:\n%s",button_command[BUTTON_START].c_str());
296
button_announce(BUTTON_START);
297
run_button_command(BUTTON_START);
254
298
ROS_INFO("Start button pressed");
258
302
case BUTTON_STOP: {
262
ac->cancelAllGoals();
263
moving_to_goal=false;
266
if (button_sound[BUTTON_STOP] !="") say(button_sound[BUTTON_STOP],speak_command);
267
if (button_command[BUTTON_STOP] != "") {
268
if (system(button_command[BUTTON_STOP].c_str())==0) {
269
ROS_INFO("Running command:\n%s",button_command[BUTTON_STOP].c_str());
306
button_announce(BUTTON_STOP);
307
run_button_command(BUTTON_STOP);
273
308
ROS_INFO("Stop button pressed");
340
375
if ((en) && (!*prev_enable)) {
341
if (general_sound[SOUND_ENABLED] !="") say(general_sound[SOUND_ENABLED],speak_command);
376
if (general_event[EVENT_ENABLED] !="") say(general_event[EVENT_ENABLED],speak_command);
344
379
if (moving_to_goal) {
345
380
if (ac->getState() == actionlib::SimpleClientGoalState::SUCCEEDED) {
346
381
char saystr[255];
347
sprintf((char*)saystr,general_sound[SOUND_GOAL_ARRIVED].c_str(),place_names[current_place_name_index].c_str());
382
run_general_command(EVENT_GOAL_ARRIVED);
383
sprintf((char*)saystr,general_event[EVENT_GOAL_ARRIVED].c_str(),place_names[current_place_name_index].c_str());
348
384
ROS_INFO("%s",saystr);
349
385
say(saystr,speak_command);
350
386
// Proceed to the next location
356
392
(ac->getState() == actionlib::SimpleClientGoalState::REJECTED) ||
357
393
(ac->getState() == actionlib::SimpleClientGoalState::ABORTED)) {
358
394
char saystr[255];
359
sprintf((char*)saystr,general_sound[SOUND_GOAL_FAILED].c_str(),place_names[current_place_name_index].c_str());
395
run_general_command(EVENT_GOAL_FAILED);
396
sprintf((char*)saystr,general_event[EVENT_GOAL_FAILED].c_str(),place_names[current_place_name_index].c_str());
360
397
ROS_INFO("%s",saystr);
361
398
say(saystr,speak_command);
362
399
moving_to_goal = false;
408
445
if (sound_str != "") button_sound[BUTTON_GO] = sound_str;
410
447
nh.getParam("enablesound", sound_str);
411
if (sound_str != "") general_sound[SOUND_ENABLED] = sound_str;
448
if (sound_str != "") general_event[EVENT_ENABLED] = sound_str;
413
450
nh.getParam("estopactivesound", sound_str);
414
if (sound_str != "") general_sound[SOUND_ESTOP_ACTIVE] = sound_str;
451
if (sound_str != "") general_event[EVENT_ESTOP_ACTIVE] = sound_str;
416
453
nh.getParam("estoppressedsound", sound_str);
417
if (sound_str != "") general_sound[SOUND_ESTOP_PRESSED] = sound_str;
454
if (sound_str != "") general_event[EVENT_ESTOP_PRESSED] = sound_str;
419
456
nh.getParam("estopreleasedsound", sound_str);
420
if (sound_str != "") general_sound[SOUND_ESTOP_RELEASED] = sound_str;
457
if (sound_str != "") general_event[EVENT_ESTOP_RELEASED] = sound_str;
422
459
// start and stop button digital inputs on the interface kit
461
nh.getParam("startbuttonindex", i);
462
if (i>-1) button_index[BUTTON_START] = i;
464
nh.getParam("stopbuttonindex", i);
465
if (i>-1) button_index[BUTTON_STOP] = i;
424
468
std::string str="";
425
nh.getParam("startbuttonindex", i);
426
if (i>-1) button_index[BUTTON_START] = i;
427
469
nh.getParam("startbuttoncommand", str);
428
470
if (str!="") button_command[BUTTON_START] = str;
430
nh.getParam("stopbuttonindex", i);
431
if (i>-1) button_index[BUTTON_STOP] = i;
433
472
nh.getParam("stopbuttoncommand", str);
434
473
if (str!="") button_command[BUTTON_STOP] = str;
475
nh.getParam("estoppressedcommand", str);
476
if (str!="") general_command[EVENT_ESTOP_PRESSED] = str;
478
nh.getParam("estopreleasedcommand", str);
479
if (str!="") general_command[EVENT_ESTOP_RELEASED] = str;
481
nh.getParam("estopactivecommand", str);
482
if (str!="") general_command[EVENT_ESTOP_ACTIVE] = str;
484
nh.getParam("goalarrivedcommand", str);
485
if (str!="") general_command[EVENT_GOAL_ARRIVED] = str;
487
nh.getParam("goalfailedcommand", str);
488
if (str!="") general_command[EVENT_GOAL_FAILED] = str;
436
490
// Button for learning new locations/poses
437
491
std::string placenames = "";