This lesson is intended to get you familiar with the basic UI and code procedures with runnng a project, as well as implementing a simple, standard trigger function on the robot's drivetrain.
This project is a standard, clean FRC repo based on our base project template. In the upcoming lessons, we will use this as a scaffold to work in, until you are eventually able to understand/code most of this yourself.
- Understand command-based robot programming
- Learn how to modify drive commands with parameters
- Use button triggers for mode switching
- Add telemetry for debugging and visualization
- See real-time changes in AdvantageScope
A training mode that:
- Toggles on/off with the a button
- Limits robot speed to 30% when active
- Shows status in telemetry
- Works seamlessly with existing drive code
General Step-by-Step Implementation (try doing this by yourself, else follow along with the solution video)
Make sure to create a NEW BRANCH with the feature implementation and create a PR as in the last assignment.
First, we need to add support for variable speed to our drive command. In DriveCommands.java, add an overloaded drive function that accepts a new supplier. Add any logging you think may be helpful.
In RobotContainer.java, create a trigger for the training mode
- Run the simulation:
WPILIB: Simlulate robot code - Open AdvantageScope and connect to the simulation
- Drive with the controller normally
- Hold the selected button and see if your driving speed changes
- Watch your logged fields in Advantage Scope and see if they correspond to your expectations.
FRC uses a command-based architecture where:
- Commands define robot actions (like driving)
- Triggers respond to button inputs
- Suppliers provide values that can change over time
-
BooleanSupplier: A functional interface that supplies a boolean value
() -> truealways returns true() -> controller.a()returns true or false based on button state
-
Trigger: Represents a button or condition
controller.a()creates a trigger for that button
-
Speed Multiplication: Applied to all movement
- Translation (X/Y movement)
- Rotation (turning)
- Ensures proportional control at lower speeds
Add three modes: Training (30%), Normal (100%), Turbo (120%)
// Hint: Use multiple buttonsUse a SlewRateLimiter to gradually change speeds Recommended reading: (WPILib SlewRateLimiter docs)[https://docs.wpilib.org/en/stable/docs/software/advanced-controls/filters/slew-rate-limiter.html#slew-rate-limiter]
SlewRateLimiter speedLimiter = new SlewRateLimiter(2.0); // 2 units/sec
// In command: speedLimiter.calculate(targetMultiplier)- Separation of Concerns: Drive logic stays in DriveCommands, button mapping in RobotContainer
- Functional Programming: Suppliers allow dynamic values without complex state management
- Telemetry First: Always add logging for debugging and analysis
- Incremental Development: Start simple (hold button) then add complexity (toggle, multiple modes)