188 if (
rf.check(
"silent"))
190 yInfo (
"Running in silent mode\n");
194 if (
rf.check(
"force_configuration"))
196 yInfo (
"Force configuration option found\n");
200 if (
rf.findGroup(
"INPUTS").check(
"InputsNumber"))
202 num_inputs =
rf.findGroup(
"INPUTS").find(
"InputsNumber").asInt32();
209 yDebug (
"Number of input axes in the configuration options: %d \n",
num_inputs);
213 yError (
"Unable to find number of input axes in the configuration options\n");
220 b =
rf.findGroup(
"INPUTS").findGroup(
"Reverse");
223 for (
int i = 1; i < b.size(); i++)
reverse[i-1] = b.get(i).asInt32();
225 else {yError (
"Configuration error: invalid number of entries 'Reverse'\n");
return false;}
226 b =
rf.findGroup(
"INPUTS").findGroup(
"InputMax");
229 for (
int i = 1; i < b.size(); i++)
inputMax[i-1] = b.get(i).asFloat64();
231 else {yError (
"Configuration error: invalid number of entries 'InputMax'\n");
return false;}
232 b =
rf.findGroup(
"INPUTS").findGroup(
"InputMin");
235 for (
int i = 1; i < b.size(); i++)
inputMin[i-1] = b.get(i).asFloat64();
237 else {yError (
"Configuration error: invalid number of entries 'InputMin'\n");
return false;}
238 b =
rf.findGroup(
"INPUTS").findGroup(
"OutputMax");
241 for (
int i = 1; i < b.size(); i++)
outputMax[i-1] = b.get(i).asFloat64();
243 else {yError (
"Configuration error: invalid number of entries 'OutputMax'\n");
return false;}
244 b =
rf.findGroup(
"INPUTS").findGroup(
"OutputMin");
247 for (
int i = 1; i < b.size(); i++)
outputMin[i-1] = b.get(i).asFloat64();
249 else {yError (
"Configuration error: invalid number of entries 'OutputMin'\n");
return false;}
251 b =
rf.findGroup(
"INPUTS").findGroup(
"Deadband");
254 for (
int i = 1; i < b.size(); i++)
jointDeadband[i-1] = b.get(i).asFloat64();
256 else {yError (
"Configuration error: invalid number of entries 'Deadband'\n");
return false;}
258 if (
rf.findGroup(
"OUTPUTS").check(
"OutputsNumber"))
260 num_outputs =
rf.findGroup(
"OUTPUTS").find(
"OutputsNumber").asInt32();
265 yError (
"Unable to find number of output axes in the configuration options\n");
272 sprintf (tmp,
"Ax%d",i);
273 if (!
rf.findGroup(
"OUTPUTS").check(tmp))
275 yError (
"Error reading [OUTPUT] block, unable to find Ax%d identifier\n",i);
278 b =
rf.findGroup(
"OUTPUTS").findGroup(tmp);
279 if (b.get(1).asString()==
"polar_r_theta")
287 if (b.get(1).asString()==
"cartesian_xyz")
295 if (b.get(1).asString()==
"button_as_axis")
299 yError(
"Configuration error: 'button_as_axis' for Ax%d requires 3 parameters (button_num, low_val, high_val)", i);
308 if (b.get(1).asString()==
"constant")
316 if (b.get(1).asString()==
"string")
326 yError() <<
"Unknown [OUTPUT] property";
333 string output_port_name;
334 if (
rf.findGroup(
"GENERAL").check(
"outputPortName"))
336 output_port_name =
rf.findGroup(
"GENERAL").find(
"outputPortName").asString();
340 output_port_name =
"/joystickCtrl:o";
341 yWarning (
"outputPortName not found, using %s \n", output_port_name.c_str());
350 yError() <<
"Unable to open module ports";
355 Bottle& exec_comm_bottle =
rf.findGroup(
"BUTTONS_EXECUTE");
356 if (!exec_comm_bottle.isNull())
358 yInfo (
"associating the following actions to the buttons: \n");
359 for (
int iii = 0; iii < 20; iii++){
361 sprintf(tmp,
"button%d", iii);
362 if (exec_comm_bottle.check(tmp))
372 Bottle& hats_exec_bottle =
rf.findGroup(
"HATS_EXECUTE");
373 if (!hats_exec_bottle.isNull())
375 yInfo (
"associating the following actions to the hats: \n");
376 for (
int iii = 0; iii < 20; iii++){
378 sprintf(tmp,
"hat%d", iii);
379 if (hats_exec_bottle.check(tmp))
381 hat_actions[iii] = hats_exec_bottle.find(tmp).toString();
391 if ( SDL_InitSubSystem ( SDL_INIT_JOYSTICK ) < 0 )
393 yError (
"Unable to initialize Joystick: %s\n", SDL_GetError() );
400 int joystick_num = SDL_NumJoysticks ();
401 if (joystick_num == 0)
403 yError (
"Error: No joysticks found\n");
return false;
405 else if (joystick_num == 1)
408 yInfo (
"One joystick found \n");
409#if (SDL_MAJOR_VERSION == 2)
410 yInfo (
"Using joystick: %s \n", SDL_JoystickNameForIndex(
joy_id));
412 yInfo (
"Using joystick: %s \n", SDL_JoystickName(
joy_id));
418 yInfo (
"More than one joystick found:\n");
419 for (
int i=0; i<joystick_num; i++)
421#if (SDL_MAJOR_VERSION == 2)
422 yInfo (
"%d: %s\n",i,SDL_JoystickNameForIndex(i));
424 yInfo (
"%d: %s\n",i,SDL_JoystickName(i));
430 if (
rf.findGroup(
"GENERAL").check(
"DefaultJoystickNumber"))
432 joy_id =
rf.findGroup(
"GENERAL").find(
"DefaultJoystickNumber").asInt32();
433 yInfo (
"Multiple joysticks found, using #%d, as specified in the configuration options\n",
joy_id);
437 yWarning (
"No default joystick specified in the configuration options\n");
438 yWarning (
"Which joystick you want to use? (choose number) \n");
447 yError (
"Could not open joystick\n" );
456 yInfo (
"Characteristics of joy %d: \n",
joy_id);
457 yInfo (
"%i Axes\n",
numAxes );
459 yInfo (
"%i Hats\n",
numHats );
466 yError (
"Error: selected joystick has %d Axes?!\n",
numAxes );
474 yWarning (
"Warning: # of joystick axes (%d) differs from # of configured input axes (%d)!\n",
numAxes,
num_inputs );
475 yWarning (
"This probably means that your .ini file does not containt a correct configuration.\n");
476 yWarning (
"Do you want to continue anyway (y/n)?\n");
479 if (input[0]!=
'y' && input[0]!=
'Y')
481 yInfo (
"Quitting...\n");
486 yWarning (
"Overriding the number of axes specified in the configuration file. Using %d axes.\n",
numAxes);
491 yWarning (
"Warning: # of joystick axes (%d) differs from # of configured input axes (%d)!\n",
numAxes,
num_inputs );
492 yWarning (
"This probably means that your .ini file does not containt a correct configuration.\n");
493 yWarning (
"However, --force_configuration option is enabled. This will override the number of axes specified in the configuration file.\n");
494 yWarning (
"Using %d axes.\n",
numAxes);
539 SDL_JoystickUpdate ();
548 for (
int i=0; i <
numHats; ++i )
554 for (
int i=0; i <
numAxes; ++i )
556 rawAxes[i] = (double)SDL_JoystickGetAxis (
joy1, i );
615 yWarning (
"Unknown parameter for JTYPE_POLAR, joint %d\n",i);
642 yWarning (
"Button id out of bounds (%d<%d)",button_idx,
numButtons);
649 yWarning (
"Unknown property, joint %d\n",i);
661 yInfo (
"executing script %d: %s\n", i,
button_actions[i].c_str());
666 yWarning (
"no scripts associated to button %d\n", i);
674 if (
rawHats[i] != SDL_HAT_CENTERED)
683 bool trigger_mode=
true;
698 case SDL_HAT_RIGHTUP:
701 case SDL_HAT_RIGHTDOWN:
702 action +=
"rightdown";
707 case SDL_HAT_LEFTDOWN:
708 action +=
"leftdown";
717 yInfo (
"executing script %d: %s\n", i, action.c_str());
718 int ret = system(action.c_str());
723 yInfo (
"executing script %d: %s\n", i, action.c_str());
724 int ret = system(action.c_str());
729 yWarning (
"no scripts associated to button %d\n", i);
748 axis_data.addFloat64(
rawAxes[i]);