-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSept12Code.java
More file actions
165 lines (153 loc) · 5.24 KB
/
Sept12Code.java
File metadata and controls
165 lines (153 loc) · 5.24 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package RobotCode;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.ElapsedTime;
@Autonomous(name="Basic: Omni Linear OpMode", group="Linear Opmode")
//starting the file and creates the variables
public class Sept12Code extends LinearOpMode {
private DcMotorEx leftFrontDrive = null;
private DcMotorEx leftBackDrive = null;
private DcMotorEx rightFrontDrive = null;
private DcMotorEx rightBackDrive = null;
//defining variables
@Override
public void runOpMode() {
leftFrontDrive = hardwareMap.get(DcMotorEx.class, "fLeft");
leftBackDrive = hardwareMap.get(DcMotorEx.class, "bLeft");
rightFrontDrive = hardwareMap.get(DcMotorEx.class, "fRight");
rightBackDrive = hardwareMap.get(DcMotorEx.class, "bRight");
//setting left wheels to reverse since they are put on backwards or something
leftFrontDrive.setDirection(DcMotorEx.Direction.REVERSE);
leftBackDrive.setDirection(DcMotorEx.Direction.REVERSE);
//driving function made by sam (numbers are in milimeters)
//moves left 200, drives fwrd 150, turns left (90 degrees), drives fwrd 150, moves left 200
leftEncoders(200);
driveEncoders(150);
turnLeft(90);
driveEncoders(150);
leftEncoders(200);
}
}
//everything oustide of the brackets above are sams functions
public void input(double leftFront, double rightFront, double leftBack, double rightBack)
{
leftFrontDrive.setPower(leftFront);
rightFrontDrive.setPower(rightFront);
leftBackDrive.setPower(leftBack);
rightBackDrive.setPower(rightBack);
sleep(500);
}
public void turnLeft(int angle)
{
int convert=revPerMM*angle*(38/10)+(angle*12/10);
encoders(-convert, convert, -convert, convert);
}
public void turnRight(int angle)
{
int convert=revPerMM*angle*(38/10)+(angle*12/10);
encoders(convert, -convert, convert, -convert);
}
public void driveEncoders(int target)
{
encoders(target, target, target, target);
}
public void backEncoders(int target)
{
encoders(-target, -target, -target, -target);
}
public void rightEncoders(int target)
{
encoders(target, -target, -target, target);
}
public void leftEncoders(int target)
{
encoders(-target, target, target, -target);
}
public void leftTopDiagonal(int target)
{
encoders(0, target, target, 0);
}
public void rightTopDiagonal(int target)
{
encoders(target, 0, 0, target);
}
public void leftBottomDiagonal(int target)
{
encoders(-target, 0, 0, -target);
}
public void rightBottomDiagonal(int target)
{
encoders(0, -target, -target, 0);
}
public void encoders(int leftFront, int rightFront, int leftBack, int rightBack)
{
leftFrontDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
rightFrontDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
leftBackDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
rightBackDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
leftFrontDrive.setTargetPosition(leftFront*revPerMM);
rightFrontDrive.setTargetPosition(rightFront*revPerMM);
leftBackDrive.setTargetPosition(leftBack*revPerMM);
rightBackDrive.setTargetPosition(rightBack*revPerMM);
leftFrontDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
rightFrontDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
leftBackDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
rightBackDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
double power=0.2;
leftFrontDrive.setVelocity(1500);
rightFrontDrive.setVelocity(1500);
leftBackDrive.setVelocity(1500);
rightBackDrive.setVelocity(1500);
while (opModeIsActive()&&leftFrontDrive.isBusy()||rightFrontDrive.isBusy()||leftBackDrive.isBusy()||rightBackDrive.isBusy())
{
}
leftFrontDrive.setPower(0);
rightFrontDrive.setPower(0);
leftBackDrive.setPower(0);
rightBackDrive.setPower(0);
}
public void drive()
{
leftFrontDrive.setPower(1.0);
rightFrontDrive.setPower(1.0);
leftBackDrive.setPower(1.0);
rightBackDrive.setPower(1.0);
//input(0.4, 0.4, 0.4, 0.4);
}
public void topRight()
{
input(0.4, 0, 0, 0.4);
}
public void right()
{
input(0.4, -0.4, -0.4, 0.4);
}
public void bottomRight()
{
input(0, -0.4, -0.4, 0);
}
public void back()
{
input(-0.4, -0.4, -0.4, -0.4);
}
public void bottomLeft()
{
input(-0.4, 0, 0, -0.4);
}
public void left()
{
input(-0.4, 0.4, 0.4, -0.4);
}
public void topLeft()
{
input(0, 0.4, 0.4, 0);
}
public void stop(double time)
{
input(0, 0, 0, 0);
}
}