Package com.studica.frc

## Class Titan.Motor

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

All Implemented Interfaces:
  `edu.wpi.first.wpilibj.PIDOutput`, `edu.wpi.first.wpilibj.SpeedController`

Enclosing class:
  Titan

    public class Titan.Motor
    extends java.lang.Object
    implements edu.wpi.first.wpilibj.SpeedController

Represents one motor output on the Titan Quad controller.

Obtain an instance via `Titan.getMotor(int)` rather than constructing directly.

Implements `SpeedController` so it can be used anywhere WPILib expects a speed controller (PID, drive trains, etc.).

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `configure​(int frequency)` Configure this motor's PWM frequency independently of the others.
`void` `disable()` Disable this motor output (sets it to the controller's disabled state).
`double` `get()`
`double` `getCypherPosition()` Read the Cypher Max absolute-encoder position for this motor's port.
`boolean` `getInverted()`
`int` `getLimitSwitch​(boolean direction)` Read a limit switch attached to this motor's channel.
`int` `getMotorIndex()`
`int` `getRPM()`
`void` `invertRPM()` Invert the sign of RPM readings returned by `getRPM()`.
`void` `pidWrite​(double output)`
`void` `set​(double speed)` Set the motor output speed.
`void` `setCurrentLimit​(float limitAmps)` Set the current limit for this motor channel.
`void` `setCurrentLimitMode​(int mode)` Set the current-limit enforcement mode for this motor channel.
`void` `setEncoderResolution​(int cpr)` Set the encoder counts-per-revolution (CPR) for this motor's channel.
`void` `setInverted​(boolean isInverted)`
`void` `setPositionHold​(boolean hold)` Enable or disable position-hold mode.
`void` `setSensitivity​(int sensitivity)` Set velocity-control sensitivity for this motor.
`void` `setTargetAngle​(double angleDeg)` Set closed-loop target angle for a Cypher Max equipped motor.
`void` `setTargetDistance​(int distanceCounts)` Set closed-loop target distance in encoder counts.
`void` `setTargetVelocity​(short velocityRpm)` Set closed-loop target velocity (RPM).
`void` `stopMotor()` Stop this motor by setting its speed to 0.
`int` `tryGetRPM()` Non-blocking RPM read.

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

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

### Methods inherited from interface edu.wpi.first.wpilibj.SpeedController

`setVoltage`

### Method Detail

#### set

    public void set​(double speed)

Set the motor output speed.

Specified by:
  `set` in interface `edu.wpi.first.wpilibj.SpeedController`
Parameters:
  `speed` - Normalised speed [-1.0, 1.0]; 0.0 = stopped

#### get

    public double get()

Specified by:
  `get` in interface `edu.wpi.first.wpilibj.SpeedController`
Returns:
  last speed value sent to this motor (after inversion is applied)

#### setInverted

    public void setInverted​(boolean isInverted)

Specified by:
  `setInverted` in interface `edu.wpi.first.wpilibj.SpeedController`

#### getInverted

    public boolean getInverted()

Specified by:
  `getInverted` in interface `edu.wpi.first.wpilibj.SpeedController`

#### disable

    public void disable()

Disable this motor output (sets it to the controller's disabled state).

Specified by:
  `disable` in interface `edu.wpi.first.wpilibj.SpeedController`

#### stopMotor

    public void stopMotor()

Stop this motor by setting its speed to 0.

Specified by:
  `stopMotor` in interface `edu.wpi.first.wpilibj.SpeedController`

#### pidWrite

    public void pidWrite​(double output)

Specified by:
  `pidWrite` in interface `edu.wpi.first.wpilibj.PIDOutput`

#### configure

    public void configure​(int frequency)

Configure this motor's PWM frequency independently of the others.

Parameters:
  `frequency` - PWM frequency [0, 20000] Hz

#### invertRPM

    public void invertRPM()

Invert the sign of RPM readings returned by `getRPM()`. Does not affect motor direction â€” use `setInverted(boolean)` for that.

#### getRPM

    public int getRPM()

Returns:
  Current shaft speed in RPM (sign may be inverted by `invertRPM()`)

#### tryGetRPM

    public int tryGetRPM()

Non-blocking RPM read. Returns the RPM value if a CAN frame was available, or `Integer.MIN_VALUE` if the blackboard had no frame yet.

Returns:
  signed RPM, or `Integer.MIN_VALUE` if no data available

#### getLimitSwitch

    public int getLimitSwitch​(boolean direction)

Read a limit switch attached to this motor's channel.

Parameters:
  `direction` - `false` = forward limit, `true` = reverse limit
Returns:
  0 = open, 1 = closed

#### getCypherPosition

    public double getCypherPosition()

Read the Cypher Max absolute-encoder position for this motor's port. Requires a Cypher Max to be set using the Studica Hardware Manager and a Cypher Max to be plugged into the motor port instead of the motors Encoder.

Returns:
  Position in degrees [0 - 360]

#### getMotorIndex

    public int getMotorIndex()

Returns:
  Motor index [0, 3] within the controller

#### setTargetVelocity

    public void setTargetVelocity​(short velocityRpm)

Set closed-loop target velocity (RPM). Negative values command reverse rotation. Requires firmware >= 2.0.0.

Parameters:
  `velocityRpm` - Target RPM (signed)

#### setTargetDistance

    public void setTargetDistance​(int distanceCounts)

Set closed-loop target distance in encoder counts. Requires firmware >= 2.0.0.

Parameters:
  `distanceCounts` - Signed encoder tick target

#### setTargetAngle

    public void setTargetAngle​(double angleDeg)

Set closed-loop target angle for a Cypher Max equipped motor. Clamped to [0.0, 360.0] degrees. Requires firmware >= 2.0.0.

Parameters:
  `angleDeg` - Target angle in degrees

#### setPositionHold

    public void setPositionHold​(boolean hold)

Enable or disable position-hold mode. When enabled the controller actively maintains the last commanded position. Requires firmware >= 2.0.0.

Parameters:
  `hold` - `true` to hold, `false` to release

#### setSensitivity

    public void setSensitivity​(int sensitivity)

Set velocity-control sensitivity for this motor. Higher values increase responsiveness but may cause oscillation. Requires firmware >= 2.0.0.

Parameters:
  `sensitivity` - Sensitivity level [0, 10]

#### setCurrentLimit

    public void setCurrentLimit​(float limitAmps)

Set the current limit for this motor channel. Requires firmware >= 2.0.0.

Parameters:
  `limitAmps` - Maximum current in amperes (>= 0)

#### setCurrentLimitMode

    public void setCurrentLimitMode​(int mode)

Set the current-limit enforcement mode for this motor channel. Requires firmware >= 2.0.0.

Parameters:
  `mode` - 0 = disabled, 1 = enabled

#### setEncoderResolution

    public void setEncoderResolution​(int cpr)

Set the encoder counts-per-revolution (CPR) for this motor's channel. Used by the device to scale PID calculations. It is better to set this in the Studica Hardware Manager. Requires firmware >= 2.0.0.

Parameters:
  `cpr` - Counts per revolution