We often switch between controllers when testing the code, so this year we tried to add code that automatically switches the button/axis IDs depending on the controller. The issue is that (and we’ve had this problem with past versions of WPILib as well) when we call the .getJoystickName() function, the watcher in the debugger returns " “” ". Anyone have any ideas? I copy/pasted part of our code below for reference.
if (DriverStation.getJoystickName(ElectronicsIDs.DriverControllerPort).equals(“Logitech Extreme 3D”)) {
driveSub.setDefaultCommand(
// The left stick controls translation of the robot.
// Turning is controlled by the X axis of the right stick.
new DriveRobot(
driveSub,
driverController,
LogitechExtreme3DConstants.AxisX, LogitechExtreme3DConstants.AxisY, LogitechExtreme3DConstants.AxisZRotate,
true));
That is called from robotInit(). Joysticks are very likely not valid at that point. You have to keep continuously checking to see if a value actually exists as code is running.
If you want, we implemented something quite similar this past offseason. We currently have 2 versions of it, the first one does work but the other, GenericGamepad2.java hasn’t been fully tested yet (oops). Feel free to take a look, or even yoink the code for yourself. I hope you’re having a good day/night!
100 use a control proxy that queries the controller name periodically and switches the delegate to match. you can’t count on the controller names at startup.