1 of 16

FRC Programming

2024 Code Overview

2024 November 7

Georgi Panchev

FRC#2022 TITAN ROBOTICS

2 of 16

Take Attendance and Download Code

  • git clone https://github.com/titan2022/FRC-2024-JAVA
  • Switch to branch preseason2024

3 of 16

Running Code

4 of 16

Building and deploying

  • Connect to robot
    • Over USB, ethernet, or radio (WiFi)
    • Check connection on Driver Station
  • CTRL + SHIFT + P in VSCode for command palette
  • Search for “>WPILib: Deploy Robot Code” and “>WPILib: Build Robot Code”
  • Deploying will automatically build first
  • Read console for status and any errors

5 of 16

Driver Station

  • Close PC Dashboard
  • Set team number to “2022” in settings tab
  • Set dashboard to ShuffleBoard
  • Check battery (should be >12.0v standby)
  • Select mode (teleop/auton) first, enable second
    • Practice is 0:15 auto, 2:15 teleop
    • Test is for testInit and testPeriodic (we don't use them)

6 of 16

Driver Station

  • [Enter] will disable bot, [Space] will emergency shutdown
    • You have to restart bot to get out of emergency mode
  • All 3 lights should be green
    • Can’t deploy if no communication
    • Can’t enable if no robot code
  • Check controllers in USB tab (you can drag reorder them and get their IDs)
  • Press gear above console for extra logging options (we will cover it later)

7 of 16

ShuffleBoard

  • Decent SmartDashboard client (we will switch to a better one)
  • Shows all values that you write into SmartDashboard
    • i.e. “SmartDashboard.putNumber( …”
  • Used for debugging
  • Right click to clear
  • Don’t save layout (it won’t save)

8 of 16

Phoenix Tuner X

9 of 16

Phoenix Tuner X

  • Control dashboard for CTRE devices
    • Falcon 500, Pigeon 2, CANcoders, CANivore, etc
  • Get values and set them
    • Useful to debug motors/encoders
    • NEVER set a motor to over 10-20% on first run
      • Search “Vincident” on Discord (it happens to the best of us)
  • If a device is not shown on Phoenix Tuner, it is not correctly connected (or connected at all)
  • Available on… Android !?

10 of 16

Phoenix Tuner X

  • If connecting by ethernet/WiFi
    • Press left menu
    • Enter team number into input box
      • Radio IP is 10.TE.AM.1
  • If connecting by USB
    • Select “roboRIO USB” in dropdown input
  • Deploy temporary diagnostics server only if your code crashes
    • It will overwrite your code

11 of 16

Phoenix Tuner X

  • [In progress]

12 of 16

Swerve and CTRE Motors

13 of 16

Our swerve code structure

  • SwerveDriveSubsystem inherits from base DriveSubsystem class
    • Uses Phoenix v5
    • Will be replaced by a Phoenix v6 version
  • Implements TranslationalDrivebase and RotationalDrivebase
    • Both are interfaces to set positional and rotational velocities

14 of 16

Translational and rotational drivebase classes

  • This is the public interface for swerve drive control
  • Can only set and get velocity
  • Use these to move robot in your control commands

15 of 16

Swerve modules

  • 2 Falcon 500s per module: 1 rotator 1 drive
  • Control motors using velocity
    • Velocity unit is Falcon ticks per 100ms
    • See constants file for more
  • Get rotation heading of each module using CANcoder values
  • CANcoders have a specific offset
    • Needs to be measured manually and set inside SwerveDriveSubsystem
  • Motor IDs change randomly sometimes
    • Need to be set correctly
    • Locate motors by blinking and look at their IDs in Phoenix Tuner
  • Tuning
    • 2 PID configs: rotation and translation
    • Feed forward for translation (to account for floor friction)
    • Should be reconfigured when robot weight changes

16 of 16

Videos