I’ve been using getRawAxis and getRawButton for a while to get my inputs from an xbox controller and it had been working quite well. However right now after wpilibj’s change, those 2 methods have been deprecated, the xboxcontroller class still uses those methods so I can’t use that, the Joystick class now looks like a mess to me (I’m not very experienced). I’m really lost right now and would appreciate any help
The methods are still there and you can still use them. Deprecated does not mean “doesn’t work”, it means “might be removed in a future year”. And from looking at the source, they don’t even appear to be deprecated (at least in GenericHID).
well when i tried using them and print out the input, it’s always a constant number and doesn’t respond to the controller. I’ve checked controller port and it is correct
If you just plug in your controller to a computer with the FRC Driverstation software and select the controller, do you see the joystick axis values changes as you physically move them?
yes I do
Alright, so the next question would be where and how are you trying to print out the output of your controller?
We are currently creating a Joystick using
Joystick stick = new Joystick(1);
(Assuming it’s in port 1)
and accessing it using
double x = stick.getRawAxis(0);
(Assuming you want axis 0)
None of these functions show as deprecated for me.
One thing I can think of is that you have the wrong class, I remember having trouble with that when I initially started this season.
This is the one I’m using
import edu.wpi.first.wpilibj.Joystick;
At least for Java anyway.
well I print it out in teleop execute and to driverstation’s console
So this is how my OI file look like
import edu.wpi.first.wpilibj.Joystick
object OI {
val DriverController: Joystick = Joystick(0)
val throttle = DriverController.getRawAxis(5)
val turn = DriverController.getRawAxis(6)
val leftTrigger = DriverController.getRawAxis(7)
val rightTrigger = DriverController.getRawAxis(8)
val quickTurn: Boolean = (leftTrigger + rightTrigger) > 0
}
That code is just storing your throttle values when you construct your OI object. You can’t do that. You need to reread the values from your DriverController during your driving loop. You can’t store them.
but can’t you just go OI.throttle in teleop and a new value will be read? This was also what I did for last year and it worked
I’m not familiar with Kotlin, but I assume not. Maybe if it’s val throttle: DriverController.getRawAxis(5)
(note the colon instead of equals) it creates a functor so it works that way?
hm that makes sense I’ll try that
ye thanks dude that just worked lol, like the not store but have to reread every cycle thingie
In Kotlin colons are for type annotations. To read from the controller each time the property is read, you want a getter.
This code should do the trick:
import edu.wpi.first.wpilibj.Joystick
object OI {
val DriverController: Joystick = Joystick(0)
val throttle get() = DriverController.getRawAxis(5)
val turn get() = DriverController.getRawAxis(6)
val leftTrigger get() = DriverController.getRawAxis(7)
val rightTrigger get() = DriverController.getRawAxis(8)
val quickTurn: Boolean get() = (leftTrigger + rightTrigger) > 0
}
o god thank you so much, this is better than having an update method