Hello java programmers, our team currently has a few different types of controllers in use by different drivers, and has a corresponding default drive command for each one. Currentlly we switch what default command to use in code for each driver, but I was wondering if there was a way to detect which type of joystick is plugged in at runtime, and then decided using that information.
Example of what my goal is:
SwerveDriveControlBaseCommand control;
CommandGenericHID driverController = new CommandGenericHID(DriverConstants.DRIVER_JOYSTICK_PORT);
if (driverController.isType(XboxController)) {
control = new SwerveDriveJoystickControl(drivetrain, (CommandJoystick)driverController);
}
if (driverController.isType(XboxController)) {
control = new SwerveDriveXboxControl(drivetrain, (CommandXboxController)driverController);
}
drivetrain.setDefaultCommand(control);
Here is some code we used in our PR demo bot. We could use two different sticks and had to update some minor code based off it. Basically during the init you read the name of the joystick.
private final Joystick m_stick = new Joystick(0);
private final String Logitech_Jotstick = "Logitech Attack 3";
private final String Thrustmaster_Joystick = "T.16000M";
...
//Determine if Logitech joysticks are in use or the Thrustmaster
if (Logitech_Jotstick.equals(m_stick.getName()))
{
System.out.println("Logitech Joystick Detected");
}
else if (Thrustmaster_Joystick.equals(m_stick.getName()))
{
System.out.println("Thrustmaster Joystick Detected");
isThrustmaster_Joystick = true;
}
else
{
System.out.println("Unknown Joystick Detected - ["+m_stick.getName()+"]");
}