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()==
"constant")
303 if (b.get(1).asString()==
"string")
313 yError() <<
"Unknown [OUTPUT] property";
320 string output_port_name;
321 if (
rf.findGroup(
"GENERAL").check(
"outputPortName"))
323 output_port_name =
rf.findGroup(
"GENERAL").find(
"outputPortName").asString();
327 output_port_name =
"/joystickCtrl:o";
328 yWarning (
"outputPortName not found, using %s \n", output_port_name.c_str());
337 yError() <<
"Unable to open module ports";
342 Bottle& exec_comm_bottle =
rf.findGroup(
"BUTTONS_EXECUTE");
343 if (!exec_comm_bottle.isNull())
345 yInfo (
"associating the following actions to the buttons: \n");
346 for (
int iii = 0; iii < 20; iii++){
348 sprintf(tmp,
"button%d", iii);
349 if (exec_comm_bottle.check(tmp))
359 Bottle& hats_exec_bottle =
rf.findGroup(
"HATS_EXECUTE");
360 if (!hats_exec_bottle.isNull())
362 yInfo (
"associating the following actions to the hats: \n");
363 for (
int iii = 0; iii < 20; iii++){
365 sprintf(tmp,
"hat%d", iii);
366 if (hats_exec_bottle.check(tmp))
368 hat_actions[iii] = hats_exec_bottle.find(tmp).toString();
378 if ( SDL_InitSubSystem ( SDL_INIT_JOYSTICK ) < 0 )
380 yError (
"Unable to initialize Joystick: %s\n", SDL_GetError() );
387 int joystick_num = SDL_NumJoysticks ();
388 if (joystick_num == 0)
390 yError (
"Error: No joysticks found\n");
return false;
392 else if (joystick_num == 1)
395 yInfo (
"One joystick found \n");
396#if (SDL_MAJOR_VERSION == 2)
397 yInfo (
"Using joystick: %s \n", SDL_JoystickNameForIndex(
joy_id));
399 yInfo (
"Using joystick: %s \n", SDL_JoystickName(
joy_id));
405 yInfo (
"More than one joystick found:\n");
406 for (
int i=0; i<joystick_num; i++)
408#if (SDL_MAJOR_VERSION == 2)
409 yInfo (
"%d: %s\n",i,SDL_JoystickNameForIndex(i));
411 yInfo (
"%d: %s\n",i,SDL_JoystickName(i));
417 if (
rf.findGroup(
"GENERAL").check(
"DefaultJoystickNumber"))
419 joy_id =
rf.findGroup(
"GENERAL").find(
"DefaultJoystickNumber").asInt32();
420 yInfo (
"Multiple joysticks found, using #%d, as specified in the configuration options\n",
joy_id);
424 yWarning (
"No default joystick specified in the configuration options\n");
425 yWarning (
"Which joystick you want to use? (choose number) \n");
434 yError (
"Could not open joystick\n" );
443 yInfo (
"Characteristics of joy %d: \n",
joy_id);
444 yInfo (
"%i Axes\n",
numAxes );
446 yInfo (
"%i Hats\n",
numHats );
453 yError (
"Error: selected joystick has %d Axes?!\n",
numAxes );
461 yWarning (
"Warning: # of joystick axes (%d) differs from # of configured input axes (%d)!\n",
numAxes,
num_inputs );
462 yWarning (
"This probably means that your .ini file does not containt a correct configuration.\n");
463 yWarning (
"Do you want to continue anyway (y/n)?\n");
466 if (input[0]!=
'y' && input[0]!=
'Y')
468 yInfo (
"Quitting...\n");
473 yWarning (
"Overriding the number of axes specified in the configuration file. Using %d axes.\n",
numAxes);
478 yWarning (
"Warning: # of joystick axes (%d) differs from # of configured input axes (%d)!\n",
numAxes,
num_inputs );
479 yWarning (
"This probably means that your .ini file does not containt a correct configuration.\n");
480 yWarning (
"However, --force_configuration option is enabled. This will override the number of axes specified in the configuration file.\n");
481 yWarning (
"Using %d axes.\n",
numAxes);
526 SDL_JoystickUpdate ();
535 for (
int i=0; i <
numHats; ++i )
541 for (
int i=0; i <
numAxes; ++i )
543 rawAxes[i] = (double)SDL_JoystickGetAxis (
joy1, i );
602 yWarning (
"Unknown parameter for JTYPE_POLAR, joint %d\n",i);
616 yWarning (
"Unknown property, joint %d\n",i);
628 yInfo (
"executing script %d: %s\n", i,
button_actions[i].c_str());
633 yWarning (
"no scripts associated to button %d\n", i);
641 if (
rawHats[i] != SDL_HAT_CENTERED)
650 bool trigger_mode=
true;
665 case SDL_HAT_RIGHTUP:
668 case SDL_HAT_RIGHTDOWN:
669 action +=
"rightdown";
674 case SDL_HAT_LEFTDOWN:
675 action +=
"leftdown";
684 yInfo (
"executing script %d: %s\n", i, action.c_str());
685 int ret = system(action.c_str());
690 yInfo (
"executing script %d: %s\n", i, action.c_str());
691 int ret = system(action.c_str());
696 yWarning (
"no scripts associated to button %d\n", i);
715 axis_data.addFloat64(
rawAxes[i]);