-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotorTest.java
More file actions
81 lines (54 loc) · 2.31 KB
/
Copy pathMotorTest.java
File metadata and controls
81 lines (54 loc) · 2.31 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
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
package org.firstinspires.ftc.teamcode.nerds9064;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
//
@TeleOp(name="Motor Test", group="Iterative Opmode")
public class MotorTest extends OpMode {
private DcMotor leftFront, rightFront, leftBack, rightBack;
final boolean test = false;
public void init(){
leftFront=hardwareMap.dcMotor.get("leftFront");
rightFront=hardwareMap.dcMotor.get("rightFront");
leftBack=hardwareMap.dcMotor.get("leftBack");
rightBack=hardwareMap.dcMotor.get("rightBack");
}
public void loop (){
try {
if (gamepad1.a) {
forward(0.5, 500);
clockwise(0.5, 500);
}
}catch(InterruptedException e){}
}
private void clockwise(double power, int time) throws InterruptedException{
setMotorPower("Left Front",leftFront,-power,true);
setMotorPower("Right Front",rightFront,-power,true);
setMotorPower("Left Back",leftBack,-power,true);
setMotorPower("Right Back",rightBack,-power,true);
Thread.sleep(time);
setMotorPower("Left Front",leftFront,0,true);
setMotorPower("Right Front",rightFront,0,true);
setMotorPower("Left Back",leftBack,0,true);
setMotorPower("Right Back",rightBack,0,true);
}
private void forward(double power, int time) throws InterruptedException{
setMotorPower("Left Front",leftFront,-power,true);
setMotorPower("Right Front",rightFront,power,true);
setMotorPower("Left Back",leftBack,-power,true);
setMotorPower("Right Back",rightBack,power,true);
Thread.sleep(time);
setMotorPower("Left Front",leftFront,0,true);
setMotorPower("Right Front",rightFront,0,true);
setMotorPower("Left Back",leftBack,0,true);
setMotorPower("Right Back",rightBack,0,true);
}
public void setMotorPower(String motorName, DcMotor motor, double power, boolean tel) {
if(test){
if (tel) telemetry.addData(motorName + " power", "" + power);
}else{
if (tel) telemetry.addData(motorName + " power", power + ", " + motor.getCurrentPosition());
motor.setPower(power);
}
}
}