So , in last year we use OI to configurate pads. In this year OI is replace by RobotContainer but when we use Joystick pad1 = new Joystick(1) in configureButtonBindings() we can’t use it commands .
configueButtonBindings()
is a method, so any declared variables won’t be directly accessible outside that method. Just like with OI, you declare your Joysticks in the RobotContainer
class. You setup all your JoystickButton
s and other Trigger
s in the configureButtonBindings()
method, just like most would do in the OI
's constructor in the old framework.
The new framework also heavily encourages the use of Dependancy Injection instead of accessing objects directly from other classes. So instead of going RobotContainer.drivetrain.drive()
You’d pass the drivetrain
subsystem object to the Command’s Constructor. For things like joystick axis values, they recommend the use of Java’s Lambda functions, also called Supplier
s. Where you create a sort of wrapper function to pass or smuggle a single method from another class instead of having to pass the whole object. So if a Command needed my Joystick
s axis 3, you could pass it as a DoubleSupplier
lambda object to the Command like so () -> driverStick.getRawAxis(3)
through the constructor, then save it to a variable like, joystickAxis
in the Command and use it later in execute()
or any of the other Command
methods like so joystickAxis.getAsDouble()
, instead of something like RobotContainer.driverStick.getRawAxis(3)
. The idea for all this is that you can make your Commands more generic by not tightly coupling them to other classes containing the required external resources, you can set it up to accept those resources instead.
I highly suggest taking a look at the WPILIB Command-Based Example projects to see how/where they set things up. I personally have mostly been using the HatchbotTraditional example for figuring out how they intend you to organize your project with the new framework. https://docs.wpilib.org/en/latest/docs/software/examples-tutorials/wpilib-examples.html#command-based-examples
Any variables declared in a method will not be seen anywhere other than that method. You need to instantiate them under your subsystems.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.