Skip to main content

Architecture

The pattern​

The whole robot is a conversation of requests between layers, each with its own state machine:

  1. Driver. SuperStructureCommands.manageRequests(...) is the SuperStructure's default command: it reads the buttons every cycle and writes a RobotRequest through a priority table (the first true row wins).
  2. SuperStructure. The overall state machine (SuperStructureBase) decides the robot's state. bindRequest(request, entryState, statesThatAlreadyServeIt...) says which state it enters to serve each request. In each overall state's onEnter, it sets each subsystem's request.
  3. Subsystems. Each one is a StateSubsystem<Request, State, Inputs, IO> with its own state machine (fsm.state(...), bindRequest(...)). atGoal() says whether the requested state has been reached, and the SuperStructure uses that in its transitions.
  4. Relay. Each subsystem's default command is generated by @AutoCommandFactory (XxxCommands.defaultCommand(superStructure, xxx)): it copies superStructure.getXxxRequest() into the subsystem every cycle.
  5. Co-driver. The manual backup: XxxCommands.<request>(xxx) overrides a subsystem's request while the button is held (override, which lasts one cycle and is renewed by the command). The SuperStructure's request is still stored and atGoal() is still relative to it, so the overall FSM never advances because of an override. Release the button, and the subsystem goes back to following the SuperStructure on its own.
  6. Hardware only through IO. A subsystem never talks to a motor directly: it calls io.controlXxx(), which returns a MotorController. In replay the IO is empty and inputs come from the log, so the same code runs on the robot, in simulation and in replay.

State machine features​

All in org.ciprix.interfaces.fsm.StateMachine:

FeatureUse
transitionTo(target, condition)A local state transition
transitionTo(target, condition, seconds)Only fires once the condition has held true for that long (debounce)
waitFor(condition) / waitFor(seconds)Waits before moving to the next state
timeoutAfter(seconds[, safetyState])A state that takes too long falls back to the safety state
transitionToSecurityState(condition) and addSecurityTransition(condition)Failure paths; the request that failed stays blocked until it's released, so the FSM doesn't return straight to the state that just failed
regularTime(min, max)A state's normal duration, with per-state statistics in the log
inState(...)A Trigger active in one or more states (LEDs, controller rumble)
toMermaid()A diagram of the machine, also logged once

Library vs. robot​

Ciprix holds what serves any team: FSM, StateSubsystem, motors with intent and health, physics simulation, vision, power management, self-test, 3D visualization and utilities. Each team's robot project holds what's theirs: the subsystems, the season's SuperStructure, shot tables, vision standard-deviation maps and button bindings.

Rule of thumb: if another team would use it the same way, it belongs in the library; if it depends on the robot or the game, it stays in the robot project.

Creating a subsystem​

The step-by-step guide, with a compiling example, is in the skeleton.

Motors​

Ciprix's motors remember the code's intent:

  • A command only goes to the hardware when it changes, and is resent every 0.5 s. A state that repeats runVelocity(...) every cycle doesn't flood the CAN bus.
  • A motor that never received a command (a follower, for example) is never touched.
  • Automatic un-jam (withStallReversal(...)) reverses the motor briefly, then restores the last command the code actually requested.
  • Health (connected, faults, stalled, free-spinning, temperature) comes through the inputs and the alerts.

The same MotorConfig works for Talon FX, Talon FXS, SPARK MAX/Flex, Talon SRX/Victor SPX, PWM and the simulated motor.