-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHardwareBase
106 lines (85 loc) · 3.91 KB
/
HardwareBase
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package org.firstinspires.ftc.teamcode;
import com.qualcomm.hardware.bosch.BNO055IMU;
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
import org.firstinspires.ftc.robotcore.external.navigation.AxesOrder;
import org.firstinspires.ftc.robotcore.external.navigation.AxesReference;
import org.firstinspires.ftc.robotcore.external.navigation.Orientation;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DistanceSensor;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.util.ElapsedTime;
public class HardwareBase
{
/* Public OpMode members. */
// Wheel objects
public DcMotor left_drive = null; // left drive front
public DcMotor right_drive = null; // left drive front
public DcMotor right_drive1 = null; // right drive back
public DcMotor left_drive1 = null; // right drive back
// Foundation objects
public Servo hook1 = null; // Hook left
public Servo hook2 = null; // Hook right
// Aquisition objects
public DcMotor acq1 = null; // Torret
public DcMotor acq2 = null; // Torret
public Servo arm = null; // Capture and Release
public DistanceSensor sensorRange;
public DistanceSensor sensorRange2;
/* local OpMode members. */
HardwareMap hwMap = null;
private ElapsedTime period = new ElapsedTime();
/* Constructor */
public HardwareBase(){
}
public initIMU(
BNO055IMU.Parameters parameters = new BNO055IMU.Parameters();
parameters.angleUnit = BNO055IMU.AngleUnit.DEGREES;
parameters.accelUnit = BNO055IMU.AccelUnit.METERS_PERSEC_PERSEC;
parameters.calibrationDataFile = "BNO055IMUCalibration.json";
parameters.loggingEnabled = true;
parameters.loggingTag = "IMU";
parameters.accelerationIntegrationAlgorithm = new JustLoggingAccelerationIntegrator();
imu = hwMap.get(BNO055IMU.class, IMU);
imu.initialize(parameters);
}
/* Initialize standard Hardware interfaces */
public void init(HardwareMap ahwMap) {
// Save reference to Hardware map
hwMap = ahwMap;
// Define and Initialize Motors
left_drive = hwMap.get(DcMotor.class, "l1");
right_drive = hwMap.get(DcMotor.class, "r1");
left_drive1 = hwMap.get(DcMotor.class, "l2");
right_drive1 = hwMap.get(DcMotor.class, "r2");
acq1 = hwMap.get(DcMotor.class, "a1");
acq2 = hwMap.get(DcMotor.class, "a2");
right_drive.setDirection(DcMotor.Direction.REVERSE);
left_drive.setDirection(DcMotor.Direction.FORWARD);
right_drive1.setDirection(DcMotor.Direction.FORWARD);
left_drive1.setDirection(DcMotor.Direction.REVERSE);
acq1.setDirection(DcMotor.Direction.FORWARD);
acq2.setDirection(DcMotor.Direction.FORWARD);
sensorRange = hwMap.get(DistanceSensor.class, "sensor_range");
sensorRange2 = hwMap.get(DistanceSensor.class, "range2");
// Set all motors to zero power
left_drive.setPower(0);
right_drive.setPower(0);
left_drive1.setPower(0);
right_drive1.setPower(0);
acq1.setPower(0);
acq2.setPower(0);
// Set all motors to run without encoders.
// May want to use RUN_USING_ENCODERS if encoders are installed.
left_drive.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
right_drive.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
left_drive1.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
right_drive1.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
acq1.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
acq2.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
// Define and initialize ALL installed servos.
hook1 = hwMap.get(Servo.class, "h1");
hook2 = hwMap.get(Servo.class, "h2");
arm = hwMap.get(Servo.class, "arm");
}
}