Skip to main content

Programming the Titan

note

With the 2.0.0 WPILib release a lot of new changes resulted in breaking changes for previous code. Note the examples below for how to do new things.

Adding the Library​

import com.studica.frc.Titan;

Objects and Instances​


/**
* Declare the main Titan object
*/
private Titan m_titan0;
private Titan m_titan1;

/**
* Declare the motors of each Titan
* Each object conforms with WPILib SpeedController class for integration with built-in libs
*/
private Titan.Motor m_leftMotor0;
private Titan.Motor m_leftMotor1;
private Titan.Motor m_rightMotor0;
private Titan.Motor m_rightMotor1;
private Titan.Motor m_armMotor0;
private Titan.Motor m_armMotor1;
private Titan.Motor m_armMotor2;
private Titan.Motor m_armMotor3;

/**
* Declare the encoders of each Titan
* Each object conforms with WPILib Encoder class for integration with built-in libs
*/
private Titan.Encoder m_leftEncoder0;
private Titan.Encoder m_leftEncoder1;
private Titan.Encoder m_rightEncoder0;
private Titan.Encoder m_rightEncoder1;

/**
* Constructor
*/
public DriveTrain()
{
/**
* Create the main Titan instances
*/
m_titan0 = new Titan(42);
m_titan1 = new Titan(25);

/**
* Get motor instances and assign to objects
*/
m_leftMotor0 = m_titan0.getMotor(0);
m_leftMotor1 = m_titan0.getMotor(1);
m_rightMotor0 = m_titan0.getMotor(2);
m_rightMotor1 = m_titan0.getMotor(3);
m_armMotor0 = m_titan1.getMotor(0);
m_armMotor1 = m_titan1.getMotor(1);
m_armMotor2 = m_titan1.getMotor(2);
m_armMotor3 = m_titan1.getMotor(3);

/**
* Get encoder instances and assign to objects
*/
m_leftEncoder0 = m_titan0.getEncoder(0, kDistPerTick);
m_leftEncoder1 = m_titan0.getEncoder(1, kDistPerTick);
m_rightEncoder0 = m_titan0.getEncoder(2, kDistPerTick);
m_rightEncoder1 = m_titan0.getEncoder(3, kDistPerTick);
}

Motor Outputs​

Set()​

Set a proportional speed from -1.0 to 1.0, where 0.0 stops the motor.

m_leftMotor0.set(speed);

SetTargetVelocity()​

Set the internal S-Curve algorithm to control the output of the motor. The algorithm will attempt to hit the desired speed with the configured smoothness settings.

m_leftMotor0.setTargetVelocity((short)80.0); // Target 80 rpm

SetTargetAngle()​

When using the Cypher Max as an encoder input, the absolute feature allows direct angle targeting. Set the desired angle for the motor to turn to.

m_leftMotor0.setTargetAngle(90.0); // 90 degrees

Motor Settings​

SetPIDType()​

Sets the PID to Manual configured in the App or using S-Curve.

m_leftMotor0.setPIDType(0); // Set to Manual Configured
note

Use Manual Type: 0 when using Set(). When using SetTargetVelocity() or SetTargetAngle() use Type: 1.

SetPositionHold()​

When enabled the controller actively maintains the last commanded position.

m_leftMotor0.setPositionHold(true); // use false to release

SetSensitivity()​

Control the S-Curve velocity control smoothness. Higher values increase smoothness. Range 0 (off) - 10 (full smoothness).

m_leftMotor0.setSensitivity(10);
important

At full sensitivity, the acceleration and deceleration become hyper smooth, which can cause problems such as reduced distance control accuracy.

SetCurrentLimit()​

Sometimes you just want to control the current going to a motor.

m_leftMotor0.setCurrentLimit(20); // in Amps

SetCurrentLimitMode()​

Enables or disables the current limit.

m_leftMotor0.setCurrentLimitMode(0); // disabled, 1 for enabled

InvertRPM()​

Inverts the RPM readings.

m_leftMotor0.invertRPM();

Motor Inputs​

GetRPM()​

Gets the current RPM reported by the Titan.

m_leftMotor0.getRPM();

GetLimitSwitch()​

Gets the value of the limit switch inputs on the Titan.

note

These inputs support normal digital input operation. Just disable the limit switch function in SHM.

m_leftMotor0.getLimitSwitch(false); // false for forward limit and true for reverse limit

GetCypherPosition()​

Get the current angle reported by a Cypher Max.

m_leftMotor0.getCypherPosition();

Encoder Inputs​

GetDistance()​

Reports the distance traveled by the encoder. Set kDistPerTick correctly before using this feature.

m_leftEncoder0.getDistance();

GetRaw()​

Reports the raw count from the Titan.

m_leftEncoder0.getRaw();

GetCount()​

Same as GetRaw() but provides higher accuracy because it avoids double conversion.

m_leftEncoder0.getCount();

GetSpeed()​

Same as GetRPM(), but needed for encoder interface.

m_leftEncoder0.getRPM();

Encoder Settings​

InvertSpeed()​

Same as InvertRPM(), needed for encoder interface.

m_leftEncoder0.invertSpeed();

SetReverseDirection()​

Invert the count direction.

m_leftEncoder0.setReverseDirection();

Reset()​

Resets the encoder count back to 0.

m_leftEncoder0.reset();