Programming the Titan

Motor Setup

1//import the TitanQuad Library
2import com.studica.frc.TitanQuad;
3
4//Create the TitanQuad Object
5private TitanQuad motor;
6
7//Constuct a new instance
8motor = new TitanQuad(TITAN_CAN_ID, TITAN_MOTOR_NUMBER);

Note

TITAN_CAN_ID is the CAN id for the Titan, by defualt it is 42. TITAN_MOTOR_NUMBER is the motor port to be used. Valid range is 0 - 3, this corresponds to the M0 - M3 on the Titan.

Setting Motor Speed

1/**
2 * Sets the speed of a motor
3 * <p>
4 * @param speed range -1 to 1 (0 stop)
5 */
6public void setMotorSpeed(double speed)
7{
8    motor.set(speed);
9}

Encoder Setup

Encoder setup code for when the encoders are plugged into the Titan and not the VMX.

 1package frc.robot.subsystems;
 2
 3//Subsystem Base import
 4import edu.wpi.first.wpilibj2.command.SubsystemBase;
 5
 6//Titan import
 7import com.studica.frc.TitanQuad;
 8
 9//Titan Encoder import
10import com.studica.frc.TitanQuadEncoder;
11
12public class Example extends SubsystemBase
13{
14    /**
15     * Motors
16     */
17    private TitanQuad motor;
18
19    /**
20     * Encoders
21     */
22    private TitanQuadEncoder encoder;
23
24    public Example()
25    {
26        //Motors
27        motor = new TitanQuad(TITAN_CAN_ID, TITAN_MOTOR_NUMBER);
28
29        //Encoder
30        encoder = new TitanQuadEncoder(motor, TITAN_MOTOR_NUMBER, TICKS_PER_REV);
31    }
32}

Note

motor is the TitanQuad motor object that was created before. TITAN_MOTOR_NUMBER is the motor number the encoder is plugged into. TICKS_PER_REV is the distance traveled per tick of the encoder. Refer to the Encoder section in Sensors to understand more.

Motor and Encoder Flags

There are some motor and encoder flags that can be set to ensure smooth operations. Its best for these flags to be set in the constructor.

 1package frc.robot.subsystems;
 2
 3//Subsystem Base import
 4import edu.wpi.first.wpilibj2.command.SubsystemBase;
 5
 6//Titan import
 7import com.studica.frc.TitanQuad;
 8
 9//Titan Encoder import
10import com.studica.frc.TitanQuadEncoder;
11
12public class Example extends SubsystemBase
13{
14    /**
15     * Motors
16     */
17    private TitanQuad motor;
18
19    /**
20     * Encoders
21     */
22    private TitanQuadEncoder encoder;
23
24    public Example()
25    {
26        //Motors
27        motor = new TitanQuad(TITAN_CAN_ID, TITAN_MOTOR_NUMBER);
28
29        //Encoder
30        encoder = new TitanQuadEncoder(motor, TITAN_MOTOR_NUMBER, TICKS_PER_REV);
31
32        //Motor Flags
33        motor.setInverted(false); // Set to true to invert motor ouput
34        motor.invertRPM(); // Invert the RPM count when the encoder is plugged in
35
36        //Encoder Flags
37        encoder.setReverseDirection(); // Will reverse the encoder count direction
38    }
39}

Full Example

 1package frc.robot.subsystems;
 2
 3//Subsystem Base import
 4import edu.wpi.first.wpilibj2.command.SubsystemBase;
 5
 6//Titan import
 7import com.studica.frc.TitanQuad;
 8
 9//Titan Encoder import
10import com.studica.frc.TitanQuadEncoder;
11
12public class Example extends SubsystemBase
13{
14    /**
15     * Motors
16     */
17    private TitanQuad motor;
18
19    /**
20     * Encoders
21     */
22    private TitanQuadEncoder encoder;
23
24    public Example()
25    {
26        //Motors
27        motor = new TitanQuad(TITAN_CAN_ID, TITAN_MOTOR_NUMBER);
28
29        //Encoder
30        encoder = new TitanQuadEncoder(motor, TITAN_MOTOR_NUMBER, TICKS_PER_REV);
31
32        //Motor Flags
33        motor.setInverted(false); // Set to true to invert motor ouput
34        motor.invertRPM(); // Invert the RPM count when the encoder is plugged in
35
36        //Encoder Flags
37        encoder.setReverseDirection(); // Will reverse the encoder count direction
38    }
39
40    /**
41     * Sets the speed of a motor
42     * <p>
43     * @param speed range -1 to 1 (0 stop)
44     */
45    public void setMotorSpeed(double speed)
46    {
47        motor.set(speed);
48    }
49}