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.
1//Include the TitanQuad Library
2#include <studica/TitanQuad.h>
3
4//Constuct a new instance
5private:
6 studica::TitanQuad motor{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}
1/**
2 * Sets the speed of a motor
3 * <p>
4 * @param speed range -1 to 1 (0 stop)
5 */
6void Example::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.
1//Include the TitanQuad and TitanQuadEncoder Library
2#include <studica/TitanQuad.h>
3#include <studica/TitanQuadEncoder.h>
4
5//Constuct a new instance
6private:
7 studica::TitanQuad motor{TITAN_CAN_ID, TITAN_MOTOR_NUMBER};
8 studica::TitanQuadEncoder encoder{motor, TITAN_MOTOR_NUMBER, TICKS_PER_REV};
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}
1//Include Header
2#include "subsystems/Example.h"
3
4void Example::Example()
5{
6 // Motor flags
7 motor.SetInverted(false); // Set true to invert motor output
8 motor.InvertRPM(); // Inverts the RPM count when the encoder is plugged in
9
10 // Encoder flags
11 encoder.SetReverseDirection(); // Will reverse the encoder count direction
12}
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}
1#pragma once
2
3//Include SubsystemBase
4#include <frc2/command/SubsystemBase.h>
5
6//Include the TitanQuad and TitanQuadEncoder Library
7#include <studica/TitanQuad.h>
8#include <studica/TitanQuadEncoder.h>
9
10class Example : public frc2::SubsystemBase
11{
12 public:
13 Example();
14 void SetMotorSpeed(double speed);
15
16 private:
17 studica::TitanQuad motor(TITAN_CAN_ID, TITAN_MOTOR_NUMBER);
18 studica::TitanQuadEncoder encoder{motor, TITAN_MOTOR_NUMBER, TICKS_PER_REV};
19};
1//Include Header
2#include "subsystems/Example.h"
3
4//Constructor
5Example::Example()
6{
7 // Motor flags
8 motor.SetInverted(false); // Set true to invert motor output
9 motor.InvertRPM(); // Inverts the RPM count when the encoder is plugged in
10
11 // Encoder flags
12 encoder.SetReverseDirection(); // Will reverse the encoder count direction
13}
14
15/**
16 * Sets the speed of a motor
17 * <p>
18 * @param speed range -1 to 1 (0 stop)
19 */
20void Example::SetMotorSpeed(double speed)
21{
22 motor.Set(speed);
23}