Interface Devices

All Known Implementing Classes:
PretendDevices

public interface Devices
Where the modules find their motors, servos and sensors by configuration name. On the robot it is the OpMode's hardwareMap (of(HardwareMap)); tests give pretend devices instead.

You rarely need it yourself: RobotDefinition hands it to every module. Docs: docs/reference/robot-java.md

  • Method Summary

    Modifier and Type
    Method
    Description
    The battery's voltage for code that runs every loop (the launcher's battery compensation): on the robot Hw.batteryReader(com.qualcomm.robotcore.hardware.HardwareMap), which asks the hubs on the library's helper thread and never waits; in tests (no hardwareMap) it asks batteryVolts() directly.
    default double
    The battery's voltage now (volts), from the hubs (Hw.batteryVolts(com.qualcomm.robotcore.hardware.HardwareMap)); NaN with no voltage sensor (tests).
    <T> T
    get(Class<? extends T> type, String name)
    The device with this name and type.
    default com.qualcomm.robotcore.hardware.HardwareMap
    The OpMode's hardwareMap, for code that needs it whole (a path follower); null in tests.
    default boolean
    has(String name)
    True if the configuration has a device with this name, of any type.
    static Devices
    of(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap)
    The robot's devices, from the OpMode's hardwareMap.
    <T> T
    tryGet(Class<? extends T> type, String name)
    The device with this name and type, or null if there is none (for optional parts).
  • Method Details

    • get

      <T> T get(Class<? extends T> type, String name)
      The device with this name and type. Stops with a clear message (the names that DO exist) if it is not in the configuration.
      Parameters:
      type - the device type, e.g. DcMotorEx.class
      name - the configuration name (exact, case matters)
    • tryGet

      <T> T tryGet(Class<? extends T> type, String name)
      The device with this name and type, or null if there is none (for optional parts).
    • has

      default boolean has(String name)
      True if the configuration has a device with this name, of any type. Used for parts marked Module.optional(): one whose device is not there is left off instead of stopping INIT. Default: asks the hardwareMap; with no hardwareMap (pretend devices in tests) every name is there.
      Parameters:
      name - the configuration name (exact, case matters)
    • hardwareMap

      default com.qualcomm.robotcore.hardware.HardwareMap hardwareMap()
      The OpMode's hardwareMap, for code that needs it whole (a path follower); null in tests.
    • batteryVolts

      default double batteryVolts()
      The battery's voltage now (volts), from the hubs (Hw.batteryVolts(com.qualcomm.robotcore.hardware.HardwareMap)); NaN with no voltage sensor (tests). Each call asks the hubs and waits (a few milliseconds): not for the loop. The launcher uses batteryReader() instead.
    • batteryReader

      default DoubleSupplier batteryReader()
      The battery's voltage for code that runs every loop (the launcher's battery compensation): on the robot Hw.batteryReader(com.qualcomm.robotcore.hardware.HardwareMap), which asks the hubs on the library's helper thread and never waits; in tests (no hardwareMap) it asks batteryVolts() directly.
    • of

      static Devices of(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap)
      The robot's devices, from the OpMode's hardwareMap.
      Parameters:
      hardwareMap - the OpMode's hardwareMap