This repository was archived by the owner on Sep 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpreludio.java
More file actions
185 lines (167 loc) · 6.16 KB
/
preludio.java
File metadata and controls
185 lines (167 loc) · 6.16 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
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")
public class MechanumAutonomous extends LinearOpMode {
private final double wheelCircumference = 75*3.14;
private final double gearReduction = 3.61*5.23;
private final double counts = 28.0;
private final double rev = counts*gearReduction;
private final int revPerMM = (int)rev/(int)wheelCircumference;
private final double inches = revPerMM*25.4;
// Declare OpMode members for each of the 4 motors.
private ElapsedTime runtime = new ElapsedTime();
private DcMotorEx leftFrontDrive = null;
private DcMotorEx leftBackDrive = null;
private DcMotorEx rightFrontDrive = null;
private DcMotorEx rightBackDrive = null;
private DcMotor armOne;
private DcMotor armTwo;
private int armOneState;
private double armOneCooldown = 0.0;
private int armTwoState;
private double armTwoCooldown = 0.0;
@Override
public void runOpMode() {
// Initialize the hardware variables. Note that the strings used here must correspond
// to the names assigned during the robot configuration step on the DS or RC devices.
leftFrontDrive = hardwareMap.get(DcMotorEx.class, "fLeft");
leftBackDrive = hardwareMap.get(DcMotorEx.class, "bLeft");
rightFrontDrive = hardwareMap.get(DcMotorEx.class, "fRight");
rightBackDrive = hardwareMap.get(DcMotorEx.class, "bRight");
leftFrontDrive.setDirection(DcMotorEx.Direction.REVERSE);
leftBackDrive.setDirection(DcMotorEx.Direction.REVERSE);
rightFrontDrive.setDirection(DcMotorEx.Direction.REVERSE);
rightBackDrive.setDirection(DcMotorEx.Direction.FORWARD);
armOne.hardwareMap.get(DcMotor.class , "arm")
armTwo.hardwareMap.get(DcMotor.class , "arm")
waitForStart();
runtime.reset();
// run until the end of the match (driver presses STOP)
while (opModeIsActive()&&count==0) {
/*
driveEncoders(800); -- forward
leftEncoders(600); -- left (no turn)
driveEncoders(800);
rightEncoders(600); -- right (no turn)
driveEncoders(800);
turnLeft(90) -- degrees to turn left
turnRight(90) -- degress to turn but right
*/
backEncoders(250);
leftEncoders(100);
backEncoders(250);
armOne.setPower(1.0);
rightEncoders(100);
backEncoders(50);
// Show the elapsed game time and wheel power.
count++;
}
}
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 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);
}
}