forked from FIRST-Tech-Challenge/FtcRobotController
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRobotChassisDrive.java
More file actions
63 lines (53 loc) · 2.35 KB
/
Copy pathRobotChassisDrive.java
File metadata and controls
63 lines (53 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import org.firstinspires.ftc.robotcore.external.Telemetry;
import java.util.ArrayList;
public class RobotChassisDrive {
DcMotorEx FLMotor; // front left
DcMotorEx FRMotor; // front right
DcMotorEx BLMotor; // back left
DcMotorEx BRMotor; // back right
ArrayList<DcMotorEx> ChassisMotors;
ArrayList<DcMotorEx> ChassisLeftMotors;
ArrayList<DcMotorEx> ChassisRightMotors;
public void init(HardwareMap HM, Telemetry telemetry){
try {
FLMotor = HM.get(DcMotorEx.class, "fl"); // front left
FRMotor = HM.get(DcMotorEx.class, "fr"); // front right
BLMotor = HM.get(DcMotorEx.class, "bl"); // back left
BRMotor = HM.get(DcMotorEx.class, "br"); // back right
// all motors
ChassisMotors = new ArrayList<>();
ChassisMotors.add(FLMotor);
ChassisMotors.add(FRMotor);
ChassisMotors.add(BRMotor);
ChassisMotors.add(BLMotor);
// left motors
ChassisLeftMotors.add(FLMotor);
ChassisLeftMotors.add(BLMotor);
// right motors
ChassisRightMotors.add(FRMotor);
ChassisRightMotors.add(BRMotor);
// initialized?
for (int i = 0; i < ChassisMotors.size(); i++){
if (ChassisMotors.get(i) == null){
telemetry.addData("Motor Error", ChassisMotors.get(i).getDeviceName() + " not initialized");
throw new RuntimeException("Motor initialization failed");
}
}
// left motors forward (CCW is front)
FLMotor.setDirection(DcMotor.Direction.FORWARD);
FRMotor.setDirection(DcMotor.Direction.FORWARD);
BLMotor.setDirection(DcMotor.Direction.REVERSE);
BRMotor.setDirection(DcMotor.Direction.REVERSE);
for (int i = 0; i < ChassisMotors.size(); i++) {
ChassisMotors.get(i).setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
}
} catch (Exception exception) {
telemetry.addData("Error", "Initialization failed: " + exception.getMessage());
telemetry.update();
}
}
}