Robotpy PC Controller Joysticks


#1

Hi - having trouble with a PC controller reading the second joystick. Looking at the Simulator it shows left Joystick on X and Y axes of Stick 0, but Joystick 2 is showing up also as Stick 0 but as Z and T axes. As such getX() and getY() only returns the left axis movement. There is no getT() function, and functions like getRawAxis seems to be deprecated.

Any ideas on how to read the Z and T axis from joystick 0 ?


#2

What platform? Windows, OSX, Linux? We use pygame for reading from the joystick, but currently we just take whatever default configuration it gives us.

It seems like it would be straightforward for someone to provide a way to remap axes. pyfrc doesn’t currently do that, but it could be something we add to the sim config json. The code is at https://github.com/robotpy/pyfrc/blob/master/lib/pyfrc/sim/pygame_joysticks.py

Filed an issue at https://github.com/robotpy/pyfrc/issues/148 so we don’t lose track of it.


#3

Yes - am using windows and pygame. Both joysticks respond on stick 0 output. I did manage to use stick.getAxis(1) and stick.getAxis(4) to retrieve the values late last night. Not sure if this is the most elegant/correct approach, but it is essentially remapping the left and right joysticks. I guess if it works, use use it right? Thanks for the help.


#4

Another approach you can use is something like

if wpilib.RobotBase.isSimulation():
   # retrieve values for sim
else:
   # retrieve values for real robot

#5

Oh - so it may behave differently when running on the robot? We have not uploaded code yet, so if that is an issue this a great suggestion. Thanks


#6

Yeah, pygame’s joystick mappings will almost certainly not match what the driverstation will provide.