Hi I need to make something in wpilib that if I press a trigger in an Xbox controller it turns on an engine. i dont really know how wpilib works so a short explanation will help if possible thank you.
Take a look at the RapidReactCommandBot example project:
Binding actions to triggers takes place in the configureBindings()
method. Code that runs the motors is defined in Subsystem
scope and is exposed through methods that return Command
s that can be bound to Trigger
s (e.g. as returned from the CommandXboxController
class).
So if for example I press the X button on the Xbox controller an engine will turn on using this code?
Sort of, but you can’t just copy and paste it.
For the motors in a Subsystem to turn on using this code you need the following:
- The Subsystem
- A method in the subsystem that returns a Command that is running the motors
- A trigger defined and bound to the specific button, and for how long etc. (whileTrue, onTrue, on False)
From there you should make sure that once your motors turn on, that they also turn off safely.
The linked example code will show you how to do all of those things in your code.
I highly recommend you spend some time reading the documentation. It sounds like you’re brand new and trying to jump straight to the endgame.
ye our progrraming mentor just said to do it and google it something do you have a video or something that can help explain to me what to do
You don’t need to google it, the documentation is at the link above. WPILib, the library we use for FRC, is documented pretty well.
Did you read it and still have questions, or are you just not interested in reading it?
im reading it rn thank you.
i managed to get it to display the axis of a button when i press it on the controller how do i make it so that when i press the controller instead of just displaying the axis it executes a code i wrote?
- Write a subsystem that knows how to make the motor run.
- Write the code that does what you want to trigger as a command.
- Bind the controller button to the command.
If you are looking for video and starting from scratch, the series “FRC 0 to Autonomous” is pretty good. You don’t need to get to autonomous, so you probably only need the first few videos.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.