-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwoWheelDemoLinear.java
69 lines (63 loc) · 3.06 KB
/
TwoWheelDemoLinear.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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.hardware.*;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit;
/**
* Example OpMode. Demonstrates use of gyro, color sensor, encoders, and telemetry.
*
*/
@TeleOp(name = "two wheel demo linear", group = "TwoWheel")
public class TwoWheelDemoLinear extends LinearOpMode {
public void runOpMode() {
DcMotor left = hardwareMap.dcMotor.get("left_motor");
DcMotor right = hardwareMap.dcMotor.get("right_motor");
left.setDirection(DcMotor.Direction.REVERSE);
GyroSensor gyro = hardwareMap.gyroSensor.get("gyro_sensor");
Servo backServo = hardwareMap.servo.get("back_servo");
gyro.init();
ColorSensor colorSensor = hardwareMap.colorSensor.get("color_sensor");
DistanceSensor frontDistance = hardwareMap.get(DistanceSensor.class, "front_distance");
DistanceSensor leftDistance = hardwareMap.get(DistanceSensor.class, "left_distance");
DistanceSensor backDistance = hardwareMap.get(DistanceSensor.class, "back_distance");
DistanceSensor rightDistance = hardwareMap.get(DistanceSensor.class, "right_distance");
telemetry.addData("Press Start to Continue","");
telemetry.update();
waitForStart();
while (opModeIsActive()){
if (gamepad1.a){
telemetry.addData("a pressed","");
left.setPower(-.5);
right.setPower(-.5);
} else if (gamepad1.y) {
telemetry.addData("y pressed", "");
left.setPower(0.5);
right.setPower(0.5);
} else if (gamepad1.b){
telemetry.addData("b pressed", "");
left.setPower(0.5);
right.setPower(-0.5);
} else if (gamepad1.x){
telemetry.addData("x pressed", "");
left.setPower(-0.5);
right.setPower(0.5);
} else {
left.setPower(0);
right.setPower(0);
}
backServo.setPosition(0.5 - 0.5* gamepad1.left_stick_y);
telemetry.addData("Press", "Y-fwd, A-rev, B-Rt, X-Lt");
telemetry.addData("Left Gamepad stick controls back servo","");
telemetry.addData("Color","R %d G %d B %d", colorSensor.red(), colorSensor.green(), colorSensor.blue());
telemetry.addData("Heading"," %.1f", gyro.getHeading());
telemetry.addData("Encoders","Left %d Right %d", left.getCurrentPosition(), right.getCurrentPosition());
telemetry.addData("Distance", " Fr %.1f Lt %.1f Rt %.1f Bk %.1f ",
frontDistance.getDistance(DistanceUnit.CM), leftDistance.getDistance(DistanceUnit.CM),
rightDistance.getDistance(DistanceUnit.CM), backDistance.getDistance(DistanceUnit.CM)
);
telemetry.update();
}
left.setPower(0);
right.setPower(0);
}
}