-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBasicLineTracking.java
57 lines (41 loc) · 1.44 KB
/
BasicLineTracking.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
package com.qualcomm.ftcrobotcontroller.opmodes;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.OpticalDistanceSensor;
/**
* Created by Knut on 10/15/2015.
*/
public class BasicLineTracking extends OpMode {
DcMotor LeftDrive1;
DcMotor LeftDrive2;
DcMotor RightDrive1;
DcMotor RightDrive2;
OpticalDistanceSensor opticalDistanceSensor;
public BasicLineTracking() {
}
public void init() {
LeftDrive1 = hardwareMap.dcMotor.get("Motor1");
LeftDrive2 = hardwareMap.dcMotor.get("Motor2");
RightDrive1 = hardwareMap.dcMotor.get("Motor3");
RightDrive2 = hardwareMap.dcMotor.get("Motor4");
RightDrive1.setDirection(DcMotor.Direction.REVERSE);
RightDrive2.setDirection(DcMotor.Direction.REVERSE);
opticalDistanceSensor = hardwareMap.opticalDistanceSensor.get("OpticalDistanceSensor");
}
public void loop() {
double reflectance = opticalDistanceSensor.getLightDetected();
if (reflectance <= 0.60) {
RightDrive1.setPower(0.2);
RightDrive2.setPower(0.2);
LeftDrive1.setPower(0);
LeftDrive2.setPower(0);
} else {
LeftDrive1.setPower(0.2);
LeftDrive2.setPower(0.2);
RightDrive1.setPower(0);
RightDrive2.setPower(0);
}
}
public void stop() {
}
}