Package com.studica.frc.jni

## Class TitanJNI

- java.lang.Object
- - com.studica.frc.jni.StudicaJNIWrapper
  - - com.studica.frc.jni.TitanJNI

    public class TitanJNI
    extends StudicaJNIWrapper

JNI wrapper for the unified Titan motor controller native driver.

### Constructor Summary

Constructors
`TitanJNI()`

### Method Summary

All Methods Static Methods Concrete Methods
`static void` `c_Titan_autotuneAll​(long handle)` Trigger PID autotune on all four channels simultaneously.
`static void` `c_Titan_configureMotor​(long handle, int motor, int frequency)` Configure a motor's PWM frequency.
`static long` `c_Titan_create​(int deviceID, int frequency)` Initialise the Titan controller, configure all four motors, and start the single background enable/disable thread.
`static void` `c_Titan_destroy​(long handle)` Stop the background thread and release the CAN handle.
`static void` `c_Titan_disableMotor​(long handle, int motor)` Disable a single motor output.
`static double` `c_Titan_getControllerTemp​(long handle)`
`static double` `c_Titan_getCypherPosition​(long handle, int port)` Read an absolute-encoder (Cypher Max) position.
`static int` `c_Titan_getEncoderCount​(long handle, int encoder)`
`static double` `c_Titan_getEncoderDistance​(long handle, int encoder)`
`static double` `c_Titan_getEncoderRaw​(long handle, int encoder)`
`static short` `c_Titan_getEncoderSpeed​(long handle, int encoder)`
`static java.lang.String` `c_Titan_getFirmwareVersion​(long handle)`
`static int` `c_Titan_getFrequency​(long handle)`
`static java.lang.String` `c_Titan_getHardwareVersion​(long handle)`
`static int` `c_Titan_getID​(long handle)`
`static int` `c_Titan_getLimitSwitch​(long handle, int motor, boolean direction)` Read a limit switch state.
`static short` `c_Titan_getRPM​(long handle, int motor)`
`static java.lang.String` `c_Titan_getSerialNumber​(long handle)`
`static short[]` `c_Titan_getTargetRPMFromDevice​(long handle)` Request and read back the target RPM for all four motors.
`static void` `c_Titan_resetEncoder​(long handle, int encoder)` Zero an encoder's tick count on the controller.
`static void` `c_Titan_setCurrentLimit​(long handle, int channel, float limitAmps)` Set the motor current limit in amperes.
`static void` `c_Titan_setCurrentLimitMode​(long handle, int channel, int mode)` Set the current-limit mode: 0 = disabled, 1 = enabled.
`static void` `c_Titan_setEncoder​(long handle, int encoder, double distPerTick)` Store the distance-per-tick conversion factor for an encoder in the native driver.
`static void` `c_Titan_setEncoderResolution​(long handle, int channel, int cpr)` Set the encoder counts-per-revolution (CPR).
`static void` `c_Titan_setMotorSpeed​(long handle, int motor, double speed)` Set a motor's output speed.
`static void` `c_Titan_setMotorStopMode​(long handle, int mode)` Set the global motor stop behaviour mode.
`static void` `c_Titan_setPIDType​(long handle, int type)` Select PID algorithm type: 0 = standard, 1 = alternate.
`static void` `c_Titan_setPositionHold​(long handle, int motor, boolean hold)` Enable or disable position-hold mode for a motor.
`static void` `c_Titan_setSensitivity​(long handle, int motor, int sensitivity)` Set velocity-control sensitivity [0, 10] for a motor.
`static void` `c_Titan_setTargetAngle​(long handle, int motor, double angleDeg)` Set closed-loop target angle [0.0, 360.0] degrees.
`static void` `c_Titan_setTargetDistance​(long handle, int motor, int distanceCounts)` Set closed-loop target distance in encoder counts.
`static void` `c_Titan_setTargetVelocity​(long handle, int motor, short velocityRpm)` Set closed-loop target velocity.
`static boolean` `c_Titan_tryGetRPM​(long handle, int motor, short[] outRpm)` Non-blocking RPM read.

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

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

### Constructor Detail

#### TitanJNI

    public TitanJNI()

### Method Detail

#### c_Titan_create

    public static long c_Titan_create​(int deviceID,
                                      int frequency)

Initialise the Titan controller, configure all four motors, and start the single background enable/disable thread.

Parameters:
  `deviceID` - CAN device ID [1, 63]
  `frequency` - PWM frequency for all motors [0, 20000] Hz
Returns:
  CAN handle, or 0 on failure

#### c_Titan_destroy

    public static void c_Titan_destroy​(long handle)

Stop the background thread and release the CAN handle.

Parameters:
  `handle` - CAN handle returned by `c_Titan_create(int, int)`

#### c_Titan_getID

    public static int c_Titan_getID​(long handle)

Returns:
  CAN device ID reported by the controller

#### c_Titan_getFrequency

    public static int c_Titan_getFrequency​(long handle)

Returns:
  PWM frequency currently set on the controller

#### c_Titan_getFirmwareVersion

    public static java.lang.String c_Titan_getFirmwareVersion​(long handle)

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

#### c_Titan_getHardwareVersion

    public static java.lang.String c_Titan_getHardwareVersion​(long handle)

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

#### c_Titan_getSerialNumber

    public static java.lang.String c_Titan_getSerialNumber​(long handle)

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

#### c_Titan_getControllerTemp

    public static double c_Titan_getControllerTemp​(long handle)

Returns:
  MCU die temperature in Â°C

#### c_Titan_setMotorSpeed

    public static void c_Titan_setMotorSpeed​(long handle,
                                             int motor,
                                             double speed)

Set a motor's output speed.

Parameters:
  `handle` - CAN handle
  `motor` - Motor index [0, 3]
  `speed` - Normalised speed [-1.0, 1.0]

#### c_Titan_configureMotor

    public static void c_Titan_configureMotor​(long handle,
                                              int motor,
                                              int frequency)

Configure a motor's PWM frequency.

Parameters:
  `handle` - CAN handle
  `motor` - Motor index [0, 3]
  `frequency` - PWM frequency [0, 20000] Hz

#### c_Titan_disableMotor

    public static void c_Titan_disableMotor​(long handle,
                                            int motor)

Disable a single motor output.

Parameters:
  `handle` - CAN handle
  `motor` - Motor index [0, 3]

#### c_Titan_getRPM

    public static short c_Titan_getRPM​(long handle,
                                       int motor)

Parameters:
  `handle` - CAN handle
  `motor` - Motor index [0, 3]
Returns:
  signed RPM

#### c_Titan_getLimitSwitch

    public static int c_Titan_getLimitSwitch​(long handle,
                                             int motor,
                                             boolean direction)

Read a limit switch state.

Parameters:
  `handle` - CAN handle
  `motor` - Motor index [0, 3]
  `direction` - `false` = forward limit, `true` = reverse limit
Returns:
  0 = open, 1 = closed

#### c_Titan_getCypherPosition

    public static double c_Titan_getCypherPosition​(long handle,
                                                   int port)

Read an absolute-encoder (Cypher Max) position.

Parameters:
  `handle` - CAN handle
  `port` - Cypher Max port [0, 3]
Returns:
  Position value

#### c_Titan_setEncoder

    public static void c_Titan_setEncoder​(long handle,
                                          int encoder,
                                          double distPerTick)

Store the distance-per-tick conversion factor for an encoder in the native driver. Must be called before `c_Titan_getEncoderDistance(long, int)`.

Parameters:
  `handle` - CAN handle
  `encoder` - Encoder index [0, 3]
  `distPerTick` - Distance (any unit) per encoder tick

#### c_Titan_getEncoderDistance

    public static double c_Titan_getEncoderDistance​(long handle,
                                                    int encoder)

Parameters:
  `handle` - CAN handle
  `encoder` - Encoder index [0, 3]
Returns:
  Raw ticks Ã— distPerTick in the configured unit

#### c_Titan_resetEncoder

    public static void c_Titan_resetEncoder​(long handle,
                                            int encoder)

Zero an encoder's tick count on the controller.

Parameters:
  `handle` - CAN handle
  `encoder` - Encoder index [0, 3]

#### c_Titan_getEncoderRaw

    public static double c_Titan_getEncoderRaw​(long handle,
                                               int encoder)

Parameters:
  `handle` - CAN handle
  `encoder` - Encoder index [0, 3]
Returns:
  Signed raw tick count

#### c_Titan_getEncoderSpeed

    public static short c_Titan_getEncoderSpeed​(long handle,
                                                int encoder)

Parameters:
  `handle` - CAN handle
  `encoder` - Encoder index [0, 3]
Returns:
  Signed speed in RPM

#### c_Titan_getEncoderCount

    public static int c_Titan_getEncoderCount​(long handle,
                                              int encoder)

Parameters:
  `handle` - CAN handle
  `encoder` - Encoder index [0, 3]
Returns:
  Signed raw tick count as int (no double conversion)

#### c_Titan_setTargetVelocity

    public static void c_Titan_setTargetVelocity​(long handle,
                                                 int motor,
                                                 short velocityRpm)

Set closed-loop target velocity. Negative = reverse.

#### c_Titan_setTargetDistance

    public static void c_Titan_setTargetDistance​(long handle,
                                                 int motor,
                                                 int distanceCounts)

Set closed-loop target distance in encoder counts.

#### c_Titan_setTargetAngle

    public static void c_Titan_setTargetAngle​(long handle,
                                              int motor,
                                              double angleDeg)

Set closed-loop target angle [0.0, 360.0] degrees.

#### c_Titan_setPositionHold

    public static void c_Titan_setPositionHold​(long handle,
                                               int motor,
                                               boolean hold)

Enable or disable position-hold mode for a motor.

#### c_Titan_setEncoderResolution

    public static void c_Titan_setEncoderResolution​(long handle,
                                                    int channel,
                                                    int cpr)

Set the encoder counts-per-revolution (CPR).

#### c_Titan_setCurrentLimit

    public static void c_Titan_setCurrentLimit​(long handle,
                                               int channel,
                                               float limitAmps)

Set the motor current limit in amperes.

#### c_Titan_setCurrentLimitMode

    public static void c_Titan_setCurrentLimitMode​(long handle,
                                                   int channel,
                                                   int mode)

Set the current-limit mode: 0 = disabled, 1 = enabled.

#### c_Titan_setMotorStopMode

    public static void c_Titan_setMotorStopMode​(long handle,
                                                int mode)

Set the global motor stop behaviour mode.

#### c_Titan_setPIDType

    public static void c_Titan_setPIDType​(long handle,
                                          int type)

Select PID algorithm type: 0 = standard, 1 = alternate.

#### c_Titan_autotuneAll

    public static void c_Titan_autotuneAll​(long handle)

Trigger PID autotune on all four channels simultaneously.

#### c_Titan_setSensitivity

    public static void c_Titan_setSensitivity​(long handle,
                                              int motor,
                                              int sensitivity)

Set velocity-control sensitivity [0, 10] for a motor.

#### c_Titan_tryGetRPM

    public static boolean c_Titan_tryGetRPM​(long handle,
                                            int motor,
                                            short[] outRpm)

Non-blocking RPM read. Writes the result into `outRpm[0]`.

Parameters:
  `outRpm` - short[1] output array
Returns:
  `true` if a valid CAN frame was available

#### c_Titan_getTargetRPMFromDevice

    public static short[] c_Titan_getTargetRPMFromDevice​(long handle)

Request and read back the target RPM for all four motors.

Returns:
  short[4] with target RPMs for motors 0-3, or `null` on failure