i am trying to use the Dpad at the box controller but I didn’t understand how to use it correctly so I searched and found out that there was a workaround but it doesn’t work. does anyone have an idea how to use the Dpad (in java)
The Dpad is called POV by the functions on the HID classes.
can you give an example?
when i try:
public static final Trigger DPadUP = xboxController.povDown();
I get an error because I need an event loop which I didn’t understand what needed.
If you’re using command-based, use CommandXboxController
’s povDown
etc methods.
If you’re not, use getPOV()
and compare to the angle you want to check.
Aside, do not use static
. It causes so many problems.
Don’t use static
for objects that are looped over a bunch of times. Essentially, since the xboxcontroller is repeatedly called upon for input, or “iterated” in programmer-ese, you can’t declare it as a static object. On the flip side, objects that don’t change states (like a Constant) should be declared as static
, so that you don’t have to instantiate it in every new case you use it. Essentially, static
objects exist as unchanging things (hence the type name “static”), so something like an Xbox controller that changes between multiple states shouldn’t be static.
This is most likely what your event loop error is coming from, too. Since something like xboxController.povDown()
could be considered an event, that normally exists within a scheduler loop, the code is looking for an object to iterate against. Since you declared your controller as static
, you’ve essentially frozen Han Solo in carbonite then told him to fly the Falcon.
Out of curiosity why isn’t this just called DPad?
This is not correct. Internal state of static objects is mutable; their references are often made immutable with the final
keyword.
It’s advisable to avoid static allocation because static initialization and global access are big footguns.
In Java static means it is accessable at the class not object/instance level. Meaning there is only one copy of the reference regardless of the number of instances of the object. You can also change static references to make them immutable they need to be final. A reference can be static and not final, final and not static, or both static and final.
As you said even it static and final the internals of the object may still be mutated just not the reference
i have changed from static but again i don’t understand what am i supposed to put in the brackets of povDown
I could be wrong since wpi may have updated since I last worked, but if my memory is correct an example would be
if(controller.getPov() == 0){
//this is up
}else if(controller.getPov() == 90){
//this is right
}
and so on
Is your team using the command-based pattern? If so, what you have should work. But given the error you mentioned about needing an event loop, I’m inclined to believe you’re not. If you’re not, then you should be doing what @Spaceturtle suggested