DriveTrain

For the autonomous to work a subsystem needs to be defined and implemented. For this example only a single motor needs to be created and a way to set the motor speed.

 1package frc.robot.subsystems;
 2
 3//Vendor imports
 4import com.studica.frc.TitanQuad;
 5
 6//WPI imports
 7import edu.wpi.first.wpilibj2.command.SubsystemBase;
 8import frc.robot.Constants;
 9
10/**
11 * DriveTrain class
12 * <p>
13 * This class creates the instance of the Titan and enables and sets the speed of the defined motor.
14 */
15public class DriveTrain extends SubsystemBase
16{
17    /**
18     * Motors
19     */
20    private TitanQuad motor;
21
22    /**
23     * Constructor
24     */
25    public DriveTrain()
26    {
27        //Motors
28        motor = new TitanQuad(Constants.TITAN_ID, Constants.MOTOR);
29    }
30
31    /**
32     * Sets the speed of the motor
33     * <p>
34     * @param speed range -1 to 1 (0 stop)
35     */
36    public void setMotorSpeed(double speed)
37    {
38        motor.set(speed);
39    }
40}
  • Lines 4 - 8 are the imports required. The TitanQuad library for the motor, SubsystemBase for the subsystem, and Constants for the motor parameters.

  • Line 20 is the creation of the motor object.

  • Lines 25 - 29 is the constructor required for creating an instance of the subsystem.

  • Line 28 creates a new instance of the TitanQuad and assigns that instance to the M2 port.

  • Line 36 - 39 is the mutator method to set the speed of the motor.