- Required Robot: Any (Testbed or Competition)
This challenge builds upon basic drivetrain control by introducing speed scaling and toggle functionality. Learning to implement speed modifiers is essential for precise robot control during critical game operations like scoring or navigating tight spaces. This challenge teaches state management, button input handling, and how to modify existing drivetrain commands without breaking their core functionality.
Modify your existing drivetrain control system to include a "slow mode" feature. When activated via a button toggle, the robot should operate at 50% of its normal speed. The slow mode should persist until toggled off, and there should be clear visual feedback indicating when slow mode is active. This feature should work with whatever drive control method you're currently using (tank drive, arcade drive, etc.).
- Drivetrain: 4 Swerve modules with NEO motors and SparkMax controllers
- IMU: NavX (CAN ID: 0)
- Controller: Xbox Controller (Port: 0)
- Toggle Button: Recommended - Right Bumper (RB)
- Motors:
- Front Left: TalonSRX (CAN ID: 20)
- Back Left: VictorSPX (CAN ID: 21)
- Front Right: TalonSRX (CAN ID: 22)
- Back Right: VictorSPX (CAN ID: 23)
- Controller: Xbox Controller (Port: 0)
- Toggle Button: Recommended - Right Bumper (RB)
- Add a boolean instance variable to track slow mode state in your drivetrain subsystem
- Create a method in your drivetrain subsystem to toggle slow mode on/off
- Modify your existing drive command to apply speed scaling when slow mode is active
- Create a command to toggle slow mode and bind it to a controller button
- Add telemetry to display the current slow mode state on SmartDashboard
- Test the toggle functionality and verify speed reduction works correctly
- Button press toggles slow mode on/off (not just while held)
- When slow mode is active, robot moves at approximately 50% of normal speed
- Slow mode affects all drivetrain movement (forward, backward, turning)
- SmartDashboard displays current slow mode state clearly
- Toggle works consistently without requiring multiple button presses
- Normal driving resumes when slow mode is disabled
- For Step 1: Add
private boolean slowModeEnabled = false;as an instance variable in your drivetrain subsystem. This will persist the state between command executions. - For Step 2: Create a method like
public void toggleSlowMode() { slowModeEnabled = !slowModeEnabled; }in your drivetrain subsystem. Consider also adding getter/setter methods for better encapsulation. - For Step 3: In your drive command's execute() method, multiply your joystick inputs by a scale factor. Example:
double speedMultiplier = drivetrain.isSlowModeEnabled() ? 0.5 : 1.0;then apply this to your drive inputs. - For Step 4: Use
InstantCommandto create the toggle command:new InstantCommand(() -> drivetrain.toggleSlowMode(), drivetrain). Bind it using.onTrue()in RobotContainer:driverController.rightBumper().onTrue(new InstantCommand(() -> drivetrain.toggleSlowMode(), drivetrain)); - For Step 5: In your drivetrain's
periodic()method, addSmartDashboard.putBoolean("Slow Mode", slowModeEnabled);to display the state. - For Step 6: Test by driving at normal speed, pressing the toggle button, and verifying the robot moves noticeably slower. The robot should maintain the same control responsiveness but at reduced maximum speed.
- Common Error: Using
.whileTrue()instead of.onTrue()will cause the command to repeatedly execute while the button is held, potentially toggling multiple times per button press. - Common Error: Forgetting to require the drivetrain subsystem in the toggle command will cause scheduling conflicts.
- Scaling All Axes: Make sure to apply the speed multiplier to both translational movement (forward/backward, left/right) and rotational movement (turning).
- Multiple Speed Modes: Create 25%, 50%, and 75% speed modes that cycle through with button presses.
- Gradual Speed Transition: Instead of instant speed changes, gradually ramp between normal and slow speeds over 0.5 seconds.
- Visual Feedback: Use different colored LEDs or dashboard indicators to show when slow mode is active.
- Smart Slow Mode: Automatically enable slow mode when the robot is within a certain distance of field elements (requires vision or sensors).
- Per-Axis Control: Allow separate speed scaling for forward/backward movement vs. turning movement.
- Speed Presets: Allow drivers to set custom slow mode percentages via dashboard sliders.
- WPILib Documentation: Command-Based Programming
- WPILib Documentation: Binding Commands to Triggers
- WPILib Documentation: InstantCommand
- WPILib Documentation: SmartDashboard
- REV Robotics: Swerve Drive Programming
- YAGSL (Yet Another Generic Swerve Library) Examples
- GitHub Example: Tank Drive Control
- GitHub Example: Arcade Drive Control
- FRC Team 364 - BaseFalconSwerve
- Chief Delphi: Driver Control Best Practices