KCommand: A revolutionary commands library for kotlin teams by 5160

KCommand is a command library that adds various utilities, as well as the buildCommand DSL, to the existing WPILib command-based framework. All of the KCommand classes are designed to make coding command-based robots in kotlin a lot nicer and cleaner overall.

Read the wiki to get started with installation and usage.

Important features include:

  1. BuildCommand DSL: A revolutionary new way to write complex commands.
  2. Various command extensions, including cleaner RunCommand and InstantCommand syntax.
  3. Built-in logging of buildCommands, as well as through the LoggedCommand wrapper.
val builtCommand: Command = buildCommand("BuildCommandName", log = true){
     require(shooter, groundIntake) // subystem requirements
     realRobotOnly {
         val value by getOnceDuringRun { arm.getPosition() }
         loopUntil({noteObserver.state = State.NoteInShooter}){
             shooter.run()
             groundIntake.run()
         }
     }
     loopForDuration(0.4){
         shooter.run()
         groundIntake.run()
     }
     onEnd {
         shooter.setIdle()
         groundIntake.setIdle()
     }
}

val instantCommand = InstantCommand(drivetrain) {
      println("hi")
}
// old syntax
val oldCommand = InstantCommand({ 
      println("hi")
}, drivetrain)

Note: KCommand’s current syntax/features are subject to change, so if you have any suggestions, make sure to message FRC 5160.

4 Likes

I see “Kotlin”, I ping @Tatiman-Dev , I move onto the next thread.

6 Likes

Im hurt you think i wouldn’t have already seen it /j

2 Likes

KCommand v1.0.0-Beta2

This version replaces the old parallel commands(parallelUntilOneEnds, parallelUntilAllEnd, etc.) with the following:

parallel {  }
parallelRace { }
parallel {
     +command.asDeadline()
}

The old methods are deprecated, thus making this a breaking change.
Check out the docs for more information.

KCommand v1.0.0-Beta3

Fixes a critical error with v1.0.0-Beta2 that required a java 20 dependency, preventing it from being deployed onto the roborio(which only supports java 17).

In addition, adds the support for multiple deadlines in a parallel {} block, which causes the command to end when all of the deadlines end.