Running Your Code
Where our commands meet our subsystems
Starting Points
From the little Android driver station, here's where we select our autonomous or teleop opModes. Our autonomous entry point can have some options to indicate where the robot is starting on the field and any decisions about scoring that need to be made.
The teleop kick-off is much simpler:
These two opModes go to the same place but get there using different constructors. The robot knows whether to run autonomous or teleop based on which constructor is being called.
MyRobot
This is where Commands get lined up for autonomous mode or bound to controller inputs in teleop. MyRobot
is a soulless filename; typically, we'll rename this file each year after our robot.
Two Constructors
One for teleop, requiring only the
opMode
object.Another for autonomous, taking additional parameters so we know our starting position and what script to run (
isRed
,isLeft
,goForBoard
)
initTele
Default Command
Once our drive train drive
is registered, we give it a default command, DriveCommand
defaultCommand
is a special command assigned to a subsystem that continuously runs unless interrupted by another higher-priority command.The
DriveCommand
will constantly watch joystick inputs as well as apply dead zones and field-orientated driveIf you press a button that triggers another command for the drive system (e.g., rotating), that command will interrupt the
DriveCommand
temporarily until it finishes.Once the other command finishes, the
DriveCommand
automatically resumes as thedefaultCommand
, listening to joystick inputs again.
Keybindings
The MyRobot
code demonstrates different ways to connect gamepad buttons with robot actions using FTCLib. Here's a breakdown of the standard methods and how they translate to gameplay scenarios:
1. whenPressed
:
Definition: Executes a command once when the button is initially pressed.
Example: Pressing the A button on Gamepad 1 toggles the driving mode.
FTC Gameplay:
Use this for actions that only need to happen once per button press, like activating a boost ability or triggering a quick arm movement.
2. whenReleased
:
Definition: Executes a command once when the button is released.
Example: Releasing the B button on Gamepad 2 closes the arm claw.
FTC Gameplay:
This is useful for actions that occur when you stop pressing the button, like stopping arm movement or ending a special ability.
3. whileHeld
:
Definition: Continuously executes a command while the button is held down.
Example: Holding the d-pad on Gamepad 2 raises or lowers the arm's wrist.
4. toggleWhenActive
:
Definition: Starts/stops a command each time the button is pressed, regardless of previous state.
Example: Not used in the provided code, but it could be used for toggling a light or other on/off functionality.
FTC Gameplay:
This is helpful for quickly activating and deactivating abilities without keeping the button held down.
Here's an example of how to link a button with a command using whileHeld
:
This code creates a button listener for the up d-pad on Gamepad 2. When held down, it continuously executes a command that raises the arm's wrist.
initAuto
In MyRobot
's initAuto
function, the autonomous script takes shape. But how do you structure your commands? Let's delve into the options:
1. Sequential Commands:
Commands execute one after another, completing before the next starts.
Think of it as a step-by-step recipe: scan for the prop, turn towards it, open the claw, move closer, etc.
Benefits:
Easy to understand and troubleshoot.
Ensures each action finishes cleanly before proceeding.
Drawbacks:
Might be slower if some actions could happen simultaneously.
Less flexibility for complex maneuvers involving interactions or timing dependencies.
2. Concurrent Commands:
Multiple commands run simultaneously, sharing resources and potentially interacting dynamically.
Imagine multitasking: turning while moving closer or raising the wrist while opening the claw.
Benefits:
Can be more efficient if actions don't rely on each other's completion.
Offers greater flexibility for intricate robot behaviors.
Drawbacks:
Requires careful planning to avoid conflicts and ensure smooth coordination.
Debugging can be more challenging.
Writing the Script:
initAuto
provides flexibility:
Within
initAuto
: You can build your entire autonomous sequence directly in our robot file using anew SequentialCommandGroup()
with nested commands. This approach keeps everything centralized and concise.Separate File: Files are kept shorter if we keep the autonomous procedure in its own SequentialCommandGroup file. This means a programmer tasked with this job could push changes to our GitHub repo with less concern for conflicts. 🤝
Last updated