Package com.studica.frc

## Class Titan

- java.lang.Object
- - com.studica.frc.Titan

    public class Titan
    extends java.lang.Object

Motor controller features for Studica Titan Quad motor controllers

### Nested Class Summary

Nested Classes
`class` `Titan.Encoder` Represents one encoder input on the Titan Quad controller.
`class` `Titan.Motor` Represents one motor output on the Titan Quad controller.

### Field Summary

Fields
`static int` `DEFAULT_FREQUENCY` Default PWM frequency used when none is specified (Hz).
`static int` `NUM_ENCODERS` Total number of encoder inputs on the Titan Quad.
`static int` `NUM_MOTORS` Total number of motor outputs on the Titan Quad.

### Constructor Summary

Constructors
`Titan​(int deviceID)` Initialise the Titan Quad with the default PWM frequency (15600 Hz).
`Titan​(int deviceID, int frequency)` Initialise the Titan Quad with a custom PWM frequency.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `autotuneAll()` Trigger PID autotune on all four motor channels simultaneously.
`void` `destroy()` Stop the background thread and release the CAN handle.
`double` `getControllerTemp()`
`Titan.Encoder` `getEncoder​(int encoderIndex, double distPerTick)` Return the `Titan.Encoder` object for the given encoder index.
`java.lang.String` `getFirmwareVersion()`
`int` `getFrequency()`
`java.lang.String` `getHardwareVersion()`
`int` `getID()`
`Titan.Motor` `getMotor​(int motorIndex)` Return the `Titan.Motor` object for the given motor index.
`java.lang.String` `getSerialNumber()`
`short[]` `getTargetRPMFromDevice()` Request and read back the current target RPM for all four motors.
`void` `setMotorStopMode​(int mode)` Set the global motor stop behaviour for all channels.
`void` `setPIDType​(int type)` Select the PID algorithm type used by the controller.

### Methods inherited from class java.lang.Object

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

### Field Detail

#### DEFAULT_FREQUENCY

    public static final int DEFAULT_FREQUENCY

Default PWM frequency used when none is specified (Hz).

See Also:
  Constant Field Values

#### NUM_MOTORS

    public static final int NUM_MOTORS

Total number of motor outputs on the Titan Quad.

See Also:
  Constant Field Values

#### NUM_ENCODERS

    public static final int NUM_ENCODERS

Total number of encoder inputs on the Titan Quad.

See Also:
  Constant Field Values

### Constructor Detail

#### Titan

    public Titan​(int deviceID,
                 int frequency)

Initialise the Titan Quad with a custom PWM frequency. All four motors are configured to the same frequency; individual motors can be reconfigured afterwards via `Titan.Motor.configure(int)`.

Parameters:
  `deviceID` - CAN device ID of the controller [1, 63]
  `frequency` - PWM frequency for all motors [0, 20000] Hz

#### Titan

    public Titan​(int deviceID)

Initialise the Titan Quad with the default PWM frequency (15600 Hz).

Parameters:
  `deviceID` - CAN device ID of the controller [1, 63]

### Method Detail

#### getMotor

    public Titan.Motor getMotor​(int motorIndex)

Return the `Titan.Motor` object for the given motor index. Objects are cached â€” calling this multiple times with the same index returns the same instance.

Parameters:
  `motorIndex` - Motor index [0, 3]
Returns:
  `Titan.Motor` for that output, implementing `SpeedController`
Throws:
  `java.lang.IllegalArgumentException` - if motorIndex is outside [0, 3]

#### getEncoder

    public Titan.Encoder getEncoder​(int encoderIndex,
                                    double distPerTick)

Return the `Titan.Encoder` object for the given encoder index. Objects are cached â€” calling this multiple times with the same index returns the same instance. The `distPerTick` supplied on the first call is stored in the native driver and used for all subsequent distance calculations.

Parameters:
  `encoderIndex` - Encoder index [0, 3]
  `distPerTick` - Distance per encoder tick (any unit, e.g. metres)
Returns:
  `Titan.Encoder` for that input, implementing `CounterBase`
Throws:
  `java.lang.IllegalArgumentException` - if encoderIndex is outside [0, 3]

#### getID

    public int getID()

Returns:
  CAN device ID reported by the controller

#### getFrequency

    public int getFrequency()

Returns:
  PWM frequency currently set on the controller (Hz)

#### getFirmwareVersion

    public java.lang.String getFirmwareVersion()

Returns:
  Firmware version string, e.g. `"Firmware Version: [1.2.3]"`

#### getHardwareVersion

    public java.lang.String getHardwareVersion()

Returns:
  Hardware description, e.g. `"Hardware: Titan Quad, Version: 2"`

#### getSerialNumber

    public java.lang.String getSerialNumber()

Returns:
  96-bit factory serial number as `"XXXXXXXX-XXXXXXXX-XXXXXXXX"`

#### getControllerTemp

    public double getControllerTemp()

Returns:
  MCU die temperature in Â°C

#### destroy

    public void destroy()

Stop the background thread and release the CAN handle. The object should not be used after this call.

#### setMotorStopMode

    public void setMotorStopMode​(int mode)

Set the global motor stop behaviour for all channels.

Parameters:
  `mode` - Stop mode (device-defined)

#### setPIDType

    public void setPIDType​(int type)

Select the PID algorithm type used by the controller.

Parameters:
  `type` - 1 = advanced PID(off), 1 = standard

#### autotuneAll

    public void autotuneAll()

Trigger PID autotune on all four motor channels simultaneously. Motors must be free-spinning during autotune.

#### getTargetRPMFromDevice

    public short[] getTargetRPMFromDevice()

Request and read back the current target RPM for all four motors. Blocks up to ~200 ms waiting for the device response.

Returns:
  short[4] with target RPMs for motors 0-3, or `null` if the device did not respond