Galaxia5987 / Recode2024

Recode of the 2024 robot code in Kotlin
Other
4 stars 1 forks source link

Potential Cause of Command Scheduler Overruns: Repeated Execution Of Commands? #27

Open rakrakon opened 2 months ago

rakrakon commented 2 months ago

Issue Description

In many places in our codebase, the setAngle function or similiar set functions are implemented like this:

fun setAngle(angle: Measure<Angle>): Command {
    return run { 
        angleSetpoint = angle
        io.setAngle(angle)
    }.withName("Set Angle Hood")
}

Use of run { ... } in Commands

The run { ... } construct creates a RunCommand, which repeatedly executes the specified action in every cycle until the command ends. This continuous execution may lead to our Command Scheduler overruns.

Fix:

@katzuv Please correct me if I misread documentation or am missing something here.

katzuv commented 2 months ago

First, great issue! Well written.

To your question, this might be a problem, although I believe some optimizations are in place: IIRC, AdvantageKit won't log again values which haven't changed, and Talon FX code won't send an additional command if the command didn't change. A few years back it was problematic to not send a command in every loop (the watchdog would kick in and disable the motor for safety reasons) but I believe this is not a problem nowadays.

You can always open VisualVM and compare the performance.

Note also that instead of using until we'll need to run a waitUntil after the command because it'll end immediately.

Do some testing and report back! 😃