You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/programming/driving_robot.md
+84-88Lines changed: 84 additions & 88 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,26 +23,24 @@ Before we begin we must create the class file for the drivetrain subsystem. See
23
23
24
24
In the Drivetrain class we will tell the subsystem what type of components it will be using.
25
25
26
-
- A Drivetrain needs motor controllers. In our case we will use 4 SparkMax Neos (a brand of controller for motors made by Rev Robotics).
27
-
- You could use other motor controllers such as Victor SPs or Talon SRXs but we will be using SparkMax Neos.
28
-
- If you are using other motor controllers, replace SparkMax with TalonSRX, Victor, or VictorSP in the code you write depending on the type you use.
29
-
- You can use 2 motors (left and right), but for this tutorial we will use 4 since that is what the base Kitbot uses.
26
+
- A Drivetrain needs motor controllers. In our case we will use 4 Talon SRs (a brand of controller for motors).
27
+
- You could use other motor controllers such as Victor SPs or Talon SRXs but we will be using Talon SRs
28
+
- If you are using other motor controllers, replace Talon with TalonSRX, Victor, or VictorSP in the code you write depending on the type you use.
29
+
- You can use 2 motors (left and right), but for this tutorial we will use 4.
30
30
31
31
!!! Tip
32
32
Be sure to read [Visual Studio Code Tips](../basics/vscode_tips.md){target=_blank} before getting started! It will make your life a lot easier.
33
33
34
-
### Creating the Motor Variables
34
+
### Creating the Talon Variables
35
35
36
36
!!! summary ""
37
-
**1)** At the top of the DriveTrainSubSystem class, create 4 global variables of data type **SparkMax** and name them: `leftLeader`, `rightLeader`, `leftFollower`, `rightFollower`
37
+
**1)**Create 4 global variables of data type **Talon** and name them: `leftFrontTalon`, `rightFrontTalon`, `leftBackTalon`, `rightBackTalon`
38
38
39
-
- To get started type private final SparkMax followed by the name i.e. `#!java private final SparkMax leftLeader;`
40
-
- These are declared at private and final because they will not be used outside of the drivetrain class, and will not be changing once assigned.
41
-
- These will eventually hold the object values for Neos and their port numbers.
39
+
- To get started type the word Talon followed by the name i.e. `#!java Talon leftFrontTalon;`
40
+
- These will eventually hold the object values for Talons and their port numbers.
42
41
43
42
!!! summary ""
44
-
<!--**2)** Next assign their values to `#!java null` ([more info on `null`](../basics/java_basics.md#overview){target=_blank}).-->
45
-
**2)** These will not be Assigned values here.
43
+
**2)** Next assign their values to `#!java null` ([more info on `null`](../basics/java_basics.md#overview){target=_blank}).
46
44
47
45
- We do this to make sure it is empty at this point.
48
46
- When we assign these variables a value, we will be getting the motor controller's port numbers out of Constants
@@ -53,10 +51,10 @@ In the Drivetrain class we will tell the subsystem what type of components it wi
53
51
The code you typed should be this:
54
52
55
53
```java
56
-
private final SparkMax leftLeader;
57
-
private final SparkMax leftFollower;
58
-
private final SparkMax rightLeader;
59
-
private final SparkMax rightFollower;
54
+
Talon leftFrontTalon = null;
55
+
Talon leftBackTalon = null;
56
+
Talon rightFrontTalon = null;
57
+
Talon rightBackTalon = null;
60
58
```
61
59
62
60
Your full **Drivetrain.java** should look like this:
@@ -70,17 +68,14 @@ In the Drivetrain class we will tell the subsystem what type of components it wi
70
68
/**
71
69
* Add your docs here.
72
70
*/
73
-
public class CANDriveSubsystem extends SubsystemBase {
74
-
private final SparkMax leftLeader;
75
-
private final SparkMax leftLeader;
76
-
private final SparkMax leftFollower;
77
-
private final SparkMax rightLeader;
78
-
private final SparkMax rightFollower;
79
-
71
+
public class Drivetrain extends Subsystem {
72
+
// Put methods for controlling this subsystem
73
+
// here. Call these from Commands.
80
74
81
-
public CANDriveSubsystem() {
82
-
83
-
}
75
+
Talon leftFrontTalon = null;
76
+
Talon leftBackTalon = null;
77
+
Talon rightFrontTalon = null;
78
+
Talon rightBackTalon = null;
84
79
85
80
@Override
86
81
public void periodic() {
@@ -91,27 +86,21 @@ In the Drivetrain class we will tell the subsystem what type of components it wi
**1)** Create the constructor for Drivetrain.java ([more info on constructors](../basics/java_basics.md#constructors){target=_blank})
106
-
107
-
- The constructor is where we will assign values to our talon variables.
108
-
109
-
!!! summary ""
110
-
Now that we have created the Talons we must initialize them and tell them what port on the roboRIO they are on.
100
+
Now that we have created the SparkMaxes and the Drive Constants we must initialize them and tell them what port on the roboRIO they are on.
111
101
112
-
**2)** Initialize (set value of) `leftFrontTalon` to `#!java new Talon(0)`.
113
-
114
-
- This initializes a new talon, `leftFrontTalon`, in a new piece of memory and states it is on port 0 of the roboRIO.
102
+
**1)** Initialize (set value of) `leftLeader` to `#!java new SparkMax(LEFT_LEADER_ID, MotorType.KBrushed)`.
103
+
- This initializes a new SparkMax, `leftLeader`, in a new piece of memory and states it is on the port defined by `LEFT_LEADER_ID`.
115
104
- This should be done within the constructor `#!java Drivetrain()`
116
105
- This calls the constructor `#!java Talon(int)` in the Talon class.
117
106
- The constructor `#!java Talon(int)` takes a variable of type `#!java int`. In this case the `#!java int` (integer) refers to the port number on the roboRIO.
@@ -126,7 +115,7 @@ In the Drivetrain class we will tell the subsystem what type of components it wi
126
115
```java
127
116
public Drivetrain() {
128
117
// Talons
129
-
leftFrontTalon = new Talon(0);
118
+
leftLeader = new SparkMax(DriveConstants.LEFT_LEADER_ID, MotorType.kBrushed);
130
119
}
131
120
```
132
121
@@ -145,14 +134,17 @@ In the Drivetrain class we will tell the subsystem what type of components it wi
145
134
// Put methods for controlling this subsystem
146
135
// here. Call these from Commands.
147
136
148
-
Talon leftFrontTalon = null;
149
-
Talon leftBackTalon = null;
150
-
Talon rightFrontTalon = null;
151
-
Talon rightBackTalon = null;
137
+
private final SparkMax leftLeader;
138
+
private final SparkMax leftFollower;
139
+
private final SparkMax rightLeader;
140
+
private final SparkMax rightFollower;
152
141
153
142
public Drivetrain() {
154
143
// Talons
155
-
leftFrontTalon = new Talon(0);
144
+
leftLeader = new SparkMax(0, MotorType.kBrushed);
145
+
leftFollower = new SparkMax(1 , MotorType.kBrushed);
146
+
rightLeader = new SparkMax(2, MotorType.kBrushed);
147
+
rightFollower = new SparkMax(3, MotorType.kBrushed);
156
148
}
157
149
158
150
@Override
@@ -167,36 +159,30 @@ In the Drivetrain class we will tell the subsystem what type of components it wi
167
159
168
160
Since each subsystem has its own components with their own ports, it is easy to lose track of which ports are being used and for what. To counter this you can use a class called **Constants** to hold all these values in a single location.
169
161
170
-
!!! summary ""
171
-
**1)** To use Constants, instead of putting `0` for the port on the Talon type:
172
-
```java
173
-
Constants.DRIVETRAIN_LEFT_FRONT_TALON
174
-
```
175
-
162
+
176
163
- Names should follow the pattern SUBSYSTEM_NAME_OF_COMPONENT
177
164
- The name is all caps since it is a **constant** ([more info on constants](../basics/java_basics.md#constants){target=_blank}).
0 commit comments