Skip to content

Useful Things to Know

Sendable

For logging data, you may extend from the Sendable class when creating classes or objects. Sendable classes can be initialized like this:

override fun initSendable(builder: SendableBuilder?) {
    builder!! // null assertion operator - tells Kotlin the builder will not be null
    builder.addDoubleProperty("exampleDouble", { getExampleValue }, {})
    builder.addBooleanProperty("exampleBoolean", { getExampleBoolean }, {})
}
Each property added to builder takes a name, a getter function, and a setter function. Setter functions aren't as common and can be left blank. Sendable classes must be added to NetworkTables manually. It is nice to do this in Robot.kt's init function, which looks like this:
Shuffleboard.getTab("Subsystems").add(ExampleSubsystem)

Interpolation Tables

Interpolation tables provide an easy way of interpolating between values in a dataset, and can be used in place of complex math. They are perfect for things like shooting game objects, as you don't need to calculate complicated physics. Instead, you can try shooting the object from different distances and test what angle works best.

There are really only two cons of using an interpolation table:

  • You need to measure scoring data manually, which can take time.
  • Changing variables (like drivetrain velocity) may cause inconsistencies and require stationary mechanisms, calculations using physics are more robust in this regard.

For example: an angle of 20 degrees works for a distance of 3 meters, but an angle of 40 degrees works for a distance of 5 meters. If you asked the interpolation table for an angle that works from 4 meters away, it will choose an angle of 30 degrees.

First, gathering data can be organized into pairs like this:

val distanceToShooterAngleData = listOf(
    // distance (meters) to angle (radians)
    0.0 to 0.0,
    1.0 to 0.2,
    1.5 to 0.3,
    2.0 to 0.5,
    3.0 to 1.0
)
After this, an Interpolating Tree Map can be initialized with these values.
val distanceToShooterTable = InterpolatingDoubleTreeMap().apply { 
    for ((distance, shooterAngle) in distanceToShooterAngleData)
        put(distance, shooterAngle)
}
And you can grab from the Tree Map with distanceToShooterTable.get(distanceFromTarget). This will return the optimal shooter angle for the robot based on the distance from the target.

CTRE Swerve Generation

This is what I recommend you use for all swerve code, assuming CTRE is what your drivetrain uses. Using Phoenix Tuner X while connected to a CTRE-powered swerve drivetrain will allow you to create swerve code both simply and effectively.

Read more at the CTRE Docs.

Orbit Software Sessions

These are by far the most useful videos I've ever watched for FRC programming.

Orbit Software Session 1

Orbit Software Session 2