forked from FIRST-Tech-Challenge/FtcRobotController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistanceDetectionTest.java
More file actions
56 lines (45 loc) · 2.52 KB
/
distanceDetectionTest.java
File metadata and controls
56 lines (45 loc) · 2.52 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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.hardware.rev.RevHubOrientationOnRobot;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DistanceSensor;
import com.qualcomm.robotcore.hardware.IMU;
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
import org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit;
import org.firstinspires.ftc.robotcore.external.navigation.YawPitchRollAngles;
@Autonomous(name = "distanceDetectionTest")
public class distanceDetectionTest extends LinearOpMode {
private DistanceSensor horizontalDistanceSensor, verticalDistanceSensor;
private IMU imu;
public void displaySensors() {
double horizontalDistance = horizontalDistanceSensor.getDistance(DistanceUnit.CM);
double verticalDistance = verticalDistanceSensor.getDistance(DistanceUnit.CM);
YawPitchRollAngles orientation = imu.getRobotYawPitchRollAngles();
telemetry.addData("horiz:", horizontalDistance);
telemetry.addData("vert:", verticalDistance);
telemetry.addData("orientation", orientation.getYaw(AngleUnit.DEGREES));
telemetry.update();
}
@Override
public void runOpMode() throws InterruptedException {
horizontalDistanceSensor = hardwareMap.get(DistanceSensor.class, "horizontalDistanceSensor");
verticalDistanceSensor = hardwareMap.get(DistanceSensor.class, "verticalDistanceSensor");
/* The next two lines define Hub orientation.
* The Default Orientation (shown) is when a hub is mounted horizontally with the printed logo pointing UP and the USB port pointing FORWARD.
*
* To Do: EDIT these two lines to match YOUR mounting configuration.
*/
RevHubOrientationOnRobot.LogoFacingDirection logoDirection = RevHubOrientationOnRobot.LogoFacingDirection.UP;
RevHubOrientationOnRobot.UsbFacingDirection usbDirection = RevHubOrientationOnRobot.UsbFacingDirection.FORWARD;
RevHubOrientationOnRobot orientationOnRobot = new RevHubOrientationOnRobot(logoDirection, usbDirection);
// Now initialize the IMU with this mounting orientation
// This sample expects the IMU to be in a REV Hub and named "imu".
imu = hardwareMap.get(IMU.class, "imu");
imu.initialize(new IMU.Parameters(orientationOnRobot));
imu.resetYaw();
waitForStart();
while (opModeIsActive()) {
displaySensors();
}
}
}