Skip to content

Commit 34f9063

Browse files
committed
Added new images and continued updating kitbot page.
1 parent 2acb971 commit 34f9063

4 files changed

Lines changed: 84 additions & 88 deletions

File tree

12 KB
Loading
6.69 KB
Loading
8.76 KB
Loading

docs/programming/driving_robot.md

Lines changed: 84 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,24 @@ Before we begin we must create the class file for the drivetrain subsystem. See
2323

2424
In the Drivetrain class we will tell the subsystem what type of components it will be using.
2525

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.
3030

3131
!!! Tip
3232
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.
3333

34-
### Creating the Motor Variables
34+
### Creating the Talon Variables
3535

3636
!!! 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`
3838

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.
4241

4342
!!! 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}).
4644

4745
- We do this to make sure it is empty at this point.
4846
- 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
5351
The code you typed should be this:
5452

5553
```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;
6058
```
6159

6260
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
7068
/**
7169
* Add your docs here.
7270
*/
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.
8074

81-
public CANDriveSubsystem() {
82-
83-
}
75+
Talon leftFrontTalon = null;
76+
Talon leftBackTalon = null;
77+
Talon rightFrontTalon = null;
78+
Talon rightBackTalon = null;
8479

8580
@Override
8681
public void periodic() {
@@ -91,27 +86,21 @@ In the Drivetrain class we will tell the subsystem what type of components it wi
9186
<!-- TODO: Generalize this more -->
9287

9388
??? fail "If an error occurs (red squiggles)"
94-
1. Click the word SparkMax
95-
![](../assets/images/driving_robot/e1.png)
96-
2. 💡 Click the light bulb
97-
![](../assets/images/driving_robot/e2.png)
98-
3. Select "Import 'SparkMax' (edu.wpi.first.wpilibj)"
99-
![](../assets/images/driving_robot/e3.png)
89+
1. Mouse Over the word SparkMax: The following menu should appear.
90+
![](../assets/images/driving_robot/fix_error_1.png)
91+
2. 💡 Click "quick fix"
92+
![](../assets/images/driving_robot/Quick_fix_click.png)
93+
3. Select "Import 'SparkMax' (com.revrobotics.spark)"
94+
![](../assets/images/driving_robot/quick_fix_import.PNG)
10095
4. Your error should be gone!
10196

10297
### Creating and filling the constructor
10398

10499
!!! summary ""
105-
**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.
111101

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`.
115104
- This should be done within the constructor `#!java Drivetrain()`
116105
- This calls the constructor `#!java Talon(int)` in the Talon class.
117106
- 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
126115
```java
127116
public Drivetrain() {
128117
// Talons
129-
leftFrontTalon = new Talon(0);
118+
leftLeader = new SparkMax(DriveConstants.LEFT_LEADER_ID, MotorType.kBrushed);
130119
}
131120
```
132121

@@ -145,14 +134,17 @@ In the Drivetrain class we will tell the subsystem what type of components it wi
145134
// Put methods for controlling this subsystem
146135
// here. Call these from Commands.
147136

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;
152141

153142
public Drivetrain() {
154143
// 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);
156148
}
157149

158150
@Override
@@ -167,36 +159,30 @@ In the Drivetrain class we will tell the subsystem what type of components it wi
167159

168160
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.
169161

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+
176163
- Names should follow the pattern SUBSYSTEM_NAME_OF_COMPONENT
177164
- The name is all caps since it is a **constant** ([more info on constants](../basics/java_basics.md#constants){target=_blank}).
178165

179166
!!! summary ""
180-
**2)** Click on the underlined text
181-
![](../assets/images/driving_robot/constants/step_1.png)
182-
183-
!!! summary ""
184-
**3)** Click on the 💡light bulb and select “create constant…”
185-
![](../assets/images/driving_robot/constants/step_2.png)
186-
187-
!!! summary ""
188-
**4)** Click on Constants.java tab that just popped up
189-
![](../assets/images/driving_robot/constants/step_3.png)
190-
167+
**1)**
168+
Before we initalize the SparkMax objects we are going to create constants to hold the CAN ID's of the motors. This will happen in constants.java
169+
- Inside the constants class, create a new class called `public static DriveConstants`.
170+
- Inside `DriveConstants` class, create for constants called `LEFT_LEADER_ID`, `LEFT_FOLLOWER_ID`, `RIGHT_LEADER_ID`, and `RIGHT_FOLLOWER_ID`.
171+
- Back in your `DriveTrain` class in `drivetrain.java`, import the `DriveConstants` class as follows: `Import frc.robot.Constants.DriveConstants;`.
172+
173+
!!! Tip
174+
Make sure to declare constants with `public static final` so they cannot be changed at runtime.
175+
176+
!!! Danger
177+
***If you set this to the wrong value, you could damage your robot when it tries to move!***
191178
!!! summary ""
192-
**5)** Change the `0` to the correct port for that motor controller on your robot/roboRIO
193-
![](../assets/images/driving_robot/constants/step_4.png)
194-
195-
!!! Danger
196-
***If you set this to the wrong value, you could damage your robot when it tries to move!***
179+
**1)** To use Constants, instead of putting `0` for the port in the SparkMax type:
180+
```java
181+
DriveConstants.LEFT_LEADER_ID
182+
```
197183

198184
!!! summary ""
199-
**6)** Repeat these steps for the remaining Talons.
185+
**2)** Replace the remaining numbers with constants.
200186

201187
!!! Tip
202188
Remember to save both **Drivetrain.java** and **Constants.java**
@@ -205,18 +191,24 @@ Since each subsystem has its own components with their own ports, it is easy to
205191

206192
The code you type should be this:
207193

208-
```java
209-
leftFrontTalon = new Talon(Constants.DRIVETRAIN_LEFT_FRONT_TALON);
210-
```
194+
```Java
195+
public static final class DriveConstants {
196+
public static final int LEFT_LEADER_ID = 1;
197+
public static final int LEFT_FOLLOWER_ID = 2;
198+
public static final int RIGHT_LEADER_ID = 3;
199+
public static final int RIGHT_FOLLOWER_ID = 4;
200+
}
201+
```
211202

212203
Your full **Drivetrain.java** should look like this:
213204

214205
```java
215206
package frc.robot.subsystems;
216207

217-
import edu.wpi.first.wpilibj.Talon;
208+
import com.revrobotics.spark.SparkLowLevel.MotorType;
209+
import com.revrobotics.spark.SparkMax;
218210
import edu.wpi.first.wpilibj.command.Subsystem;
219-
import frc.robot.Constants;
211+
import frc.robot.Constants.DriveConstants;
220212

221213
/**
222214
* Add your docs here.
@@ -225,18 +217,17 @@ Since each subsystem has its own components with their own ports, it is easy to
225217
// Put methods for controlling this subsystem
226218
// here. Call these from Commands.
227219

228-
Talon leftFrontTalon = null;
229-
Talon leftBackTalon = null;
230-
Talon rightFrontTalon = null;
231-
Talon rightBackTalon = null;
220+
private final SparkMax leftLeader;
221+
private final SparkMax leftFollower;
222+
private final SparkMax rightLeader;
223+
private final SparkMax rightFollower;
232224

233225
public Drivetrain() {
234226
// Talons
235-
leftFrontTalon = new Talon(Constants.DRIVETRAIN_LEFT_FRONT_TALON);
236-
leftBackTalon = new Talon(Constants.DRIVETRAIN_LEFT_BACK_TALON);
237-
rightFrontTalon = new Talon(Constants.DRIVETRAIN_RIGHT_FRONT_TALON);
238-
rightBackTalon = new Talon(Constants.DRIVETRAIN_RIGHT_BACK_TALON);
239-
}
227+
leftLeader = new SparkMax(DriveConstants.LEFT_LEADER_ID, MotorType.kBrushed);
228+
leftFollower = new SparkMax(DriveConstants.LEFT_FOLLOWER_ID, MotorType.kBrushed);
229+
rightLeader = new SparkMax(DriveConstants.RIGHT_LEADER_ID, MotorType.kBrushed);
230+
rightFollower = new SparkMax(DriveConstants.RIGHT_FOLLOWER_ID, MotorType.kBrushed);
240231

241232
@Override
242233
public void periodic() {
@@ -251,17 +242,22 @@ Since each subsystem has its own components with their own ports, it is easy to
251242
package frc.robot;
252243

253244
public class Constants {
254-
// Talons
255-
public static final int DRIVETRAIN_LEFT_FRONT_TALON = 0;
256-
public static final int DRIVETRAIN_LEFT_BACK_TALON = 1;
257-
public static final int DRIVETRAIN_RIGHT_FRONT_TALON = 2;
258-
public static final int DRIVETRAIN_RIGHT_BACK_TALON = 3;
245+
public static final class DriveConstants {
246+
public static final int LEFT_LEADER_ID = 1;
247+
public static final int LEFT_FOLLOWER_ID = 2;
248+
public static final int RIGHT_LEADER_ID = 3;
249+
public static final int RIGHT_FOLLOWER_ID = 4;
250+
}
259251
}
260252
```
261253

262254
!!! Warning
263255
Remember to use the values for **YOUR** specific robot or you could risk damaging it!
264256

257+
### Cofiguring the SparkMaxes
258+
259+
260+
265261
### Creating the arcade drive
266262

267263
#### What is the Drive Class

0 commit comments

Comments
 (0)