This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calibration.java
114 lines (94 loc) · 4.96 KB
/
Calibration.java
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
107
108
109
110
111
112
113
114
package org.firstinspires.ftc.teamcode;
import org.firstinspires.ftc.teamcode.libs.*;
import com.qualcomm.robotcore.robot.Robot;
import com.qualcomm.hardware.rev.RevColorSensorV3;
import com.qualcomm.hardware.adafruit.AdafruitBNO055IMU;
import com.qualcomm.hardware.bosch.BNO055IMU;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.util.ReadWriteFile;
import org.firstinspires.ftc.robotcore.external.Func;
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 org.firstinspires.ftc.robotcore.internal.system.AppUtil;
import java.io.File;
@TeleOp(name = "Calibration")
public class Calibration extends LinearOpMode {
BNO055IMU imu;
Orientation angles;
RevColorSensorV3 firstRingSensor;
RevColorSensorV3 secondRingSensor;
RevColorSensorV3 thirdRingSensor;
ColorSensorCalibration colorSensor1Calibration;
ColorSensorCalibration colorSensor2Calibration;
ColorSensorCalibration colorSensor3Calibration;
boolean pushingA = false;
boolean pushingB = false;
@Override
public void runOpMode() {
BNO055IMU.Parameters parameters = new BNO055IMU.Parameters();
parameters.loggingEnabled = true;
parameters.loggingTag = "IMU";
parameters.mode = BNO055IMU.SensorMode.NDOF;
imu = hardwareMap.get(BNO055IMU.class, "imu");
imu.initialize(parameters);
firstRingSensor = hardwareMap.get(RevColorSensorV3.class, "firstRingSensor");
secondRingSensor = hardwareMap.get(RevColorSensorV3.class, "secondRingSensor");
thirdRingSensor = hardwareMap.get(RevColorSensorV3.class, "thirdRingSensor");
colorSensor1Calibration = new ColorSensorCalibration();
colorSensor2Calibration = new ColorSensorCalibration();
colorSensor3Calibration = new ColorSensorCalibration();
writeTelemetry();
while (opModeIsActive()) {
if (gamepad1.a) {
if (!pushingA) {
BNO055IMU.CalibrationData calibrationData = imu.readCalibrationData();
writeFile(RobotConfig.imuConfigFileName, calibrationData.serialize());
}
pushingA = true;
} else pushingA = false;
if (gamepad1.b) {
if (!pushingB) {
writeFile(RobotConfig.colorSensor1ConfigFileName, colorSensor1Calibration.serialize());
writeFile(RobotConfig.colorSensor2ConfigFileName, colorSensor2Calibration.serialize());
writeFile(RobotConfig.colorSensor3ConfigFileName, colorSensor3Calibration.serialize());
}
pushingB = true;
} else pushingB = false;
if (gamepad1.x) {
colorSensor1Calibration.setAbsentRGB(firstRingSensor.red(), firstRingSensor.green(), firstRingSensor.blue());
colorSensor2Calibration.setAbsentRGB(secondRingSensor.red(), secondRingSensor.green(), secondRingSensor.blue());
colorSensor3Calibration.setAbsentRGB(thirdRingSensor.red(), thirdRingSensor.green(), thirdRingSensor.blue());
}
if (gamepad1.y) {
colorSensor1Calibration.setPresentRGB(firstRingSensor.red(), firstRingSensor.green(), firstRingSensor.blue());
colorSensor2Calibration.setPresentRGB(secondRingSensor.red(), secondRingSensor.green(), secondRingSensor.blue());
colorSensor3Calibration.setPresentRGB(thirdRingSensor.red(), thirdRingSensor.green(), thirdRingSensor.blue());
}
writeTelemetry();
}
}
void writeFile(String filename, String data) {
File file = AppUtil.getInstance().getSettingsFile(filename);
ReadWriteFile.writeFile(file, data);
telemetry.log().add("saved: " + filename);
}
void writeTelemetry() {
angles = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.XYZ, AngleUnit.DEGREES);
telemetry.addData("status", imu.getSystemStatus().toShortString());
telemetry.addData("calib", imu.getCalibrationStatus().toString());
telemetry.addData("pitch", formatAngle(angles.angleUnit, angles.firstAngle));
telemetry.addData("roll", formatAngle(angles.angleUnit, angles.secondAngle));
telemetry.addData("heading", formatAngle(angles.angleUnit, angles.thirdAngle));
telemetry.update();
}
String formatAngle(AngleUnit angleUnit, double angle) {
return formatDegrees(AngleUnit.DEGREES.fromUnit(angleUnit, angle));
}
String formatDegrees(double degrees){
return String.format("%.1f", AngleUnit.DEGREES.normalize(degrees));
}
}