Skip to content

Mubotics7157/a2-getting-started

Repository files navigation

Assignment 2: Getting started with simulation

Overview

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.

Learning Objectives

  • 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

What You'll Build

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.

Step 1: Modify the Drive Command

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.

Step 2: Set Up the Button Trigger

In RobotContainer.java, create a trigger for the training mode

Step 3: Test in Simulation

  1. Run the simulation: WPILIB: Simlulate robot code
  2. Open AdvantageScope and connect to the simulation
  3. Drive with the controller normally
  4. Hold the selected button and see if your driving speed changes
  5. Watch your logged fields in Advantage Scope and see if they correspond to your expectations.

How It Works

The Command Pattern

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

Key Concepts

  1. BooleanSupplier: A functional interface that supplies a boolean value

    • () -> true always returns true
    • () -> controller.a() returns true or false based on button state
  2. Trigger: Represents a button or condition

    • controller.a() creates a trigger for that button
  3. Speed Multiplication: Applied to all movement

    • Translation (X/Y movement)
    • Rotation (turning)
    • Ensures proportional control at lower speeds

Solution

https://youtu.be/gT9PGrjxgv8

Extension Challenges

Challenge 1: Multiple Speed Modes

Add three modes: Training (30%), Normal (100%), Turbo (120%)

// Hint: Use multiple buttons

Challenge 2: Smooth Transitions

Use 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)

Key Takeaways

  • 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)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages