Class Module<M extends Module<M>>

java.lang.Object
com.crossbotics.ftchelper.robot.Module<M>
All Implemented Interfaces:
Subsystem
Direct Known Subclasses:
Camera, Hood, Indexer, Intake, Launcher, Lights, MotorPositions, Pieces, PieceSensor, ServoPositions, Turret

public abstract class Module<M extends Module<M>> extends Object implements Subsystem
One kind of mechanism in Robot.java: an Intake, a Lift, a Claw... Each module brings four things: its line in Robot.java, its section in Tunables.java, its usual buttons (the lines Controls.java writes for it; added by themselves only with useStandardButtons() true) and its lines in the simulator robot file.

 lift = add(Lift.slide("lift").bottomSwitch("lift_bottom"));   // in Robot.java's define()
 

The module's numbers come from the Tunables.java section with the device's name in CamelCase: device "intake_deploy" reads Tunables.IntakeDeploy. Pick another section with tunables(String).

<M extends Module<M>> lets each setting below hand back the module's own type, so Lift.slide("lift").tunables("Slide") is still a Lift. Docs: docs/reference/robot-java.md

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    The part's telemetry line; each module adds its own.
    The main device's configuration name, e.g.
    boolean
    True if it was marked optional() in Robot.java.
    boolean
    True if the part is on the robot: false only for an optional() part whose device was not in the configuration at INIT (true before INIT).
    looks(Shape... shapes)
    How the part looks and where it sits (Shape), for the simulator's 3D view and size checks.
    The name shown on the Driver Station and the Tunables section: "Lift", "IntakeDeploy".
    This part may not be on the robot yet.
    part(String catalogId)
    The main device's parts catalog id: a motor (Motors, e.g.
    The parts catalog id given with part(...) in Robot.java, or null.
    tunables(String sectionName)
    Reads this module's numbers from another Tunables.java section.
    This part's zone for an interlock rule (Interlock): between two numbers, read from the rule's Tunables section as <part>From and <part>To (in the part's own units).
    This part's zone from <part>Above up (to the top of its range).
    This part's zone from <part>Below down.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.crossbotics.ftchelper.core.Subsystem

    stop, update
  • Method Details

    • tunables

      public M tunables(String sectionName)
      Reads this module's numbers from another Tunables.java section.
      Parameters:
      sectionName - the section's class name, e.g. "Slide"
      Returns:
      this module
    • part

      public M part(String catalogId)
      The main device's parts catalog id: a motor (Motors, e.g. "gobilda-5203-117") or a servo (Parts.servo(java.lang.String, double, double, double, double), e.g. "gobilda-2000-speed"). The simulator then moves a motor or servo like the real one. For a continuous-rotation (CR) servo the id is only a note in the robot file (the simulator turns every CR servo at one speed).
      Parameters:
      catalogId - the id; a typo stops with the list of known ids
      Returns:
      this module
    • looks

      public M looks(Shape... shapes)
      How the part looks and where it sits (Shape), for the simulator's 3D view and size checks. This part moves them: an intake spins its rollers, a positioner swings its arm.
      Parameters:
      shapes - one or more, e.g. Shape.roller("offset-tubing-90").atMm(200, 0, 50).lengthMm(240)
      Returns:
      this module
    • optional

      public M optional()
      This part may not be on the robot yet. If its device (the name in add(...), e.g. "intake_deploy") is not in the robot configuration, INIT does not stop: it shows one note, and the part is "off" until it is added. Robots are built in steps: write the whole robot in Robot.java now, and each part starts working the day its device is in the configuration.
      
       intakeDeploy = add(Positioner.servo("intake_deploy").part("gobilda-2000-torque").optional());   // Robot.java
       

      While it is off: every command to it is ignored (isPresent() is false), its telemetry line is "-", an Action skips it (and the waits right after it) and goes on, its buttons show "off" on the button map, and an interlock rule with it is off. Its question methods never hold anything up: it counts as done and at its target, and never as running, ready or full. Only its FIRST device decides: if "intake_deploy" is there, every other device of the part must be too (half a part is a wiring mistake: INIT stops and says which). Not for the drive (a robot always drives).

      Returns:
      this module
    • isOptional

      public boolean isOptional()
      True if it was marked optional() in Robot.java.
    • isPresent

      public boolean isPresent()
      True if the part is on the robot: false only for an optional() part whose device was not in the configuration at INIT (true before INIT). Use it for code the library cannot see, e.g. if (robot.intakeDeploy.isPresent()) ...; buttons can use .needs(part).
    • name

      public String name()
      The name shown on the Driver Station and the Tunables section: "Lift", "IntakeDeploy".
      Specified by:
      name in interface Subsystem
    • deviceName

      public String deviceName()
      The main device's configuration name, e.g. "lift".
    • partId

      public String partId()
      The parts catalog id given with part(...) in Robot.java, or null.
    • zone

      public Zone zone()
      This part's zone for an interlock rule (Interlock): between two numbers, read from the rule's Tunables section as <part>From and <part>To (in the part's own units).
      
       keepApart("TurretLift", turret.zone(), lift.zoneAbove());   // Robot.java
       
    • zoneAbove

      public Zone zoneAbove()
      This part's zone from <part>Above up (to the top of its range). See zone().
    • zoneBelow

      public Zone zoneBelow()
      This part's zone from <part>Below down. See zone().
    • addTelemetry

      public void addTelemetry(RobotTelemetry t)
      The part's telemetry line; each module adds its own.
      Specified by:
      addTelemetry in interface Subsystem