Skip to content

Activity 4.8: Trace a New Button

🎯 Goal

By the end of this activity you will have:

  • Chosen a button binding that hasn’t been traced yet (A button jostle or B button elevator)
  • Followed the complete execution path from controller press to motor output
  • Documented your trace using the CodeTrace format
  • Compared your chosen binding type to the ones traced in Units 2–3

What’s Already Been Traced

In Units 2–3, you traced two button bindings:

ButtonBinding TypeWhat It DoesWhere You Traced It
X buttontoggleOnTrueIntake deploy + rollersActivity 2.4
Y buttontoggleOnTrueShoot sequenceLesson 2.3

That leaves two buttons you haven’t traced:

ButtonBinding TypeWhat It Does
A buttonwhileTrueJostle the intake
B buttononTrueElevator command

Pick one and trace it completely. Both are good choices — they use different binding types than X and Y, so you’ll learn something new either way.


Step 1: Find Your Button Binding

Open RobotContainer.java and search for your chosen button:

  • For the A button: search for controller.a()
  • For the B button: search for controller.b()

Read the binding carefully. Before you start tracing, answer these questions:

  1. What binding type does it use? (whileTrue, onTrue, toggleOnTrue, etc.)
  2. What command or command group does it trigger?
  3. Which subsystem(s) are involved?

The A button uses whileTrue — the command runs only while the button is held down. When you release A, the command stops immediately. This is different from toggleOnTrue (X and Y buttons), where you press once to start and again to stop.

The jostle command likely calls a method on IntakeSubsystem that vibrates or shakes the intake to settle a game piece. Look for a jostle() method or similar.

The B button uses onTrue — the command runs once when the button is pressed. It doesn’t toggle, and holding the button doesn’t matter. The command runs to completion (or until isFinished() returns true).

The elevator command involves ClimberSubsystem and controls the elevator mechanism for endgame climbing.


Step 2: Trace the Execution Path

Follow the same process you used in Activity 5.8:

  1. Start at the binding — What does the trigger do when the button state changes?
  2. Follow the command — What methods does the command call? Is it inline or a standalone class?
  3. Enter the subsystem — What do those methods actually do to the hardware?
  4. Identify the motors — What CAN IDs are involved? What speed/direction are they set to?

Open the relevant subsystem file alongside RobotContainer:

Write Down Each Step

As you trace, document each step in this format:

StepFileLocationWhat Happens
1RobotContainer.javacontroller.a() or controller.b()Button trigger fires
2RobotContainer.javaCommand creationWhat command is created?
3SubsystemFile.javaMethod callWhat method runs?
4SubsystemFile.javaMotor controlWhat motors move? At what speed?

Step 3: Understand the Binding Type Difference

This is the key learning moment. You’ve now seen three different binding types:

Binding TypeBehaviorButtons That Use It
toggleOnTruePress once → start. Press again → stop.X (intake), Y (shoot)
whileTrueRuns only while button is held. Stops on release.A (jostle)
onTrueRuns once when pressed. Runs to completion.B (elevator)

Think about why each button uses its specific binding type:

  • Intake (toggleOnTrue): The driver wants to start the intake and focus on driving. They don’t want to hold a button the whole time. Press X to start, press X again when the game piece is collected.
  • Jostle (whileTrue): Jostling is a quick adjustment — shake the game piece into position. The driver holds A for a moment, then releases. It shouldn’t keep running.
  • Elevator (onTrue): The elevator moves to a position and stops. It’s a one-shot action — press B, the elevator moves, done.
Checkpoint: Binding Type Analysis
Explain in your own words: (1) What would go wrong if the jostle command used toggleOnTrue instead of whileTrue? (2) What would go wrong if the elevator command used whileTrue instead of onTrue?
  1. Jostle with toggleOnTrue: The intake would keep jostling after the driver releases the A button. The driver would have to remember to press A again to stop it. During a match, they might forget — the intake would vibrate continuously, wasting power and potentially damaging the mechanism.

  2. Elevator with whileTrue: The driver would have to hold B the entire time the elevator is moving. If they release too early, the elevator stops mid-travel. During the endgame rush, holding a button while also trying to drive and align is difficult. onTrue lets the elevator complete its motion automatically.


Step 4: Create Your CodeTrace

Now build a complete CodeTrace for your chosen button. Here’s an example structure for the A button — adapt it for whichever button you traced:

Jostle Button Trace: A Button → IntakeSubsystem
🟢 Driver presses and holds the A button on the controller
RobotContainer.java controller.a().whileTrue(...)
A button trigger fires. whileTrue starts the command and keeps it running as long as the button is held.
RobotContainer.java RunCommand or method call
The command calls a jostle method on IntakeSubsystem. This runs every 20ms while the button is held.
IntakeSubsystem.java jostle() method
The jostle method sets the intake rollers to alternate directions or a specific vibration pattern to settle the game piece.
RobotContainer.java whileTrue — button released
When the driver releases A, whileTrue cancels the command. The command's end() or finallyDo() cleanup runs, stopping the motors.
🔵 Intake jostles while A is held, stops immediately on release

Step 5: Compare All Four Buttons

Now that you’ve traced a third button, fill in this comparison table:

AspectX (Intake)Y (Shoot)Your Button
Binding typetoggleOnTruetoggleOnTrue?
Command typeSequentialCommandGroup??
Subsystem(s)IntakeSubsystemShooterSubsystem, TurretSubsystem?
Has cleanup?Yes (finallyDo)??
Motor count4 (2 rollers + 2 deploy)??

Bonus: Trace the Other Button Too

If you traced the A button, try the B button next (or vice versa). Having all four buttons traced gives you a complete picture of how your team’s driver controls work. Save your traces — they’ll be useful reference material for the rest of the season.


What’s Next?

You’ve now traced three of the four driver button bindings and understand how different binding types (toggleOnTrue, whileTrue, onTrue) change the driver experience. This is a core skill — every time your team adds a new button binding, you’ll be able to read and understand it immediately.

In Lesson 4.9: NetworkTables Basics, you’ll learn about the data layer that connects your robot code to the Driver Station, dashboards, and vision cameras. NetworkTables is how your robot communicates with the outside world.

In Lesson 4.9: NetworkTables Basics, you’ll learn about the data layer that connects your robot code to the Driver Station, dashboards, and vision cameras. NetworkTables is how your robot communicates with the outside world.