forked from FIRST-Tech-Challenge/FtcRobotController
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServoValueFinder.java
57 lines (50 loc) · 1.88 KB
/
ServoValueFinder.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 org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.Servo;
import java.util.Map;
/**
* An OpMode that finds servo values. Copied from last year's code.
*/
@TeleOp(name = "Servo Value Finder", group = "Teleop")
public class ServoValueFinder extends LinearOpMode {
private static String[] SERVO_LIST;
private static int num = 0;
private boolean dpad_right_prev = false;
private boolean dpad_left_prev = false;
/**
* Runs the OpMode.
*/
@Override
public void runOpMode() {
SERVO_LIST = hardwareMap.servo.entrySet().stream().map(Map.Entry::getKey).toArray(String[]::new);
while(!gamepad2.a && !isStopRequested()){
if(gamepad2.dpad_right && !dpad_right_prev){
num = (num + 1) % SERVO_LIST.length;
dpad_right_prev = true;
}else if(gamepad2.dpad_left && !dpad_left_prev){
num = (num + SERVO_LIST.length - 1) % SERVO_LIST.length;
dpad_left_prev = true;
}
if(!gamepad2.dpad_right){
dpad_right_prev = false;
}
if(!gamepad2.dpad_left){
dpad_left_prev = false;
}
telemetry.addData("selected servo: ", SERVO_LIST[num]);
telemetry.update();
}
Servo servo = hardwareMap.get(Servo.class, SERVO_LIST[num]);
waitForStart();
while(opModeIsActive()){
if(gamepad2.dpad_up){
servo.setPosition(servo.getPosition()+0.0001);
}else if(gamepad2.dpad_down){
servo.setPosition(servo.getPosition()-0.0001);
}
telemetry.addData("servo pos: ",servo.getPosition());
telemetry.update();
}
}
}