forked from FIRST-Tech-Challenge/FtcRobotController
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBaseAuto.java
More file actions
75 lines (73 loc) · 2.27 KB
/
BaseAuto.java
File metadata and controls
75 lines (73 loc) · 2.27 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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.hardware.CRServo;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.Servo;
public class BaseAuto {
MecanumDrive drive;
EasyIMU easy;
DcMotor leftFront;
public BaseAuto(MecanumDrive d, EasyIMU e, DcMotor lf){
drive=d;
easy=e;
leftFront=lf;
}
public boolean strafe(double goalPos, double power){
if(goalPos<0){
if(leftFront.getCurrentPosition()>goalPos){
drive.moveLeft(power);
return true;
}
} if(goalPos>0){
if(leftFront.getCurrentPosition()<goalPos){
drive.moveRight(power);
return true;
}
}
drive.stop();
leftFront.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
leftFront.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
return false;
}
public boolean forwardBackward(double goalPos, double power){
if(goalPos<0){
if(leftFront.getCurrentPosition()>goalPos){
drive.moveForward(power);
return true;
}
} if(goalPos>0){
if(leftFront.getCurrentPosition()<goalPos){
drive.moveBackward(power);
return true;
}
}
drive.stop();
leftFront.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
leftFront.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
return false;
}
double startTime=0;
public boolean timedGoal(double goalTime){
double currentTime = System.currentTimeMillis();
if(startTime==0){
startTime=currentTime;
}
if(currentTime-startTime<goalTime){
return true;
}
startTime=0;
return false;
}
public boolean turn(double goalPos, double power){
if(easy.getYaw()>goalPos+1){
drive.turnRightTank(power);
return true;
}if (easy.getYaw()<goalPos-1){
drive.turnLeftTank(power);
return true;
}
drive.stop();
leftFront.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
leftFront.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
return false;
}
}