-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFieldCentricTwoPlayer.java
More file actions
198 lines (151 loc) · 7.68 KB
/
Copy pathFieldCentricTwoPlayer.java
File metadata and controls
198 lines (151 loc) · 7.68 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
186
187
188
189
190
191
192
193
194
195
196
197
198
package org.firstinspires.ftc.teamcode;
import com.acmerobotics.roadrunner.geometry.Pose2d;
import com.acmerobotics.roadrunner.geometry.Vector2d;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.ServoImplEx;
import org.firstinspires.ftc.teamcode.drive.SampleMecanumDrive;
/**
* This is a simple teleop routine for testing localization. Drive the robot around like a normal
* teleop routine and make sure the robot's estimated pose matches the robot's actual pose (slight
* errors are not out of the ordinary, especially with sudden drive motions). The goal of this
* exercise is to ascertain whether the localizer has been configured properly (note: the pure
* encoder localizer heading may be significantly off if the track width has not been tuned).
*/
@TeleOp(name = "Field Centric Tele Op 9103", group = "Competition")
public class FieldCentricTwoPlayer extends LinearOpMode {
// Custom for lift
//private DcMotorEx lift;
// Custom for claw
public ServoImplEx servoLeft, servoRight;
public DcMotorEx lift;
@Override
public void runOpMode() throws InterruptedException {
SampleMecanumDrive drive = new SampleMecanumDrive(hardwareMap);
drive.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
lift = hardwareMap.get(DcMotorEx.class, "lift");
// Needed for internal run to position PIDs
lift.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
// Lift will suspend in midair rather than coasting when at 0 power
lift.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
servoLeft = hardwareMap.get(ServoImplEx.class, "servoLeft");
servoRight = hardwareMap.get(ServoImplEx.class, "servoRight");
servoLeft.setPwmEnable();
servoRight.setPwmEnable();
waitForStart();
boolean clawInvertRight = true, clawInvertLeft = true;
// Create a vector from the gamepad x/y inputs
// Then, rotate that vector by the inverse of that heading
// Pass in the rotated input + right stick value for rotation
// Rotation is not part of the rotated input thus must be passed in separately
while (!isStopRequested() && opModeIsActive()) {
Pose2d poseEstimate = drive.getPoseEstimate();
Vector2d input = new Vector2d(
-gamepad1.left_stick_y,
-gamepad1.left_stick_x
).rotated(-poseEstimate.getHeading());
drive.setWeightedDrivePower(
new Pose2d(
input.getX(),
input.getY(),
-gamepad1.right_stick_x
)
);
drive.update();
// telemetry.addData("x", poseEstimate.getX());
// telemetry.addData("y", poseEstimate.getY());
// telemetry.addData("heading", poseEstimate.getHeading());
telemetry.addData(" Vaule of: servoLeft.getPwmRange(): ", servoLeft.getPwmRange());
telemetry.addData("Value of: servoLeft.isPwmEnabled(): ", servoLeft.isPwmEnabled());
telemetry.addData("Value of servoLeft.getPosition();", servoLeft.getPosition());
telemetry.addData(" Vaule of: servoRight.getPwmRange(): ", servoRight.getPwmRange());
telemetry.addData("Value of: servoRight.isPwmEnabled(): ", servoRight.isPwmEnabled());
telemetry.addData("Value of servoRight.getPosition();", servoRight.getPosition());
telemetry.addData("lift.getCurrentPosition(): ", lift.getCurrentPosition());
telemetry.update();
//
// telemetry.addData(" Vaule of: servoLeft.getPwmRange(): ", servoLeft.getPwmRange());
// telemetry.addData("Value of: servoLeft.isPwmEnabled(): ", servoLeft.isPwmEnabled());
// telemetry.addData("Value of servoLeft.getPosition();", servoLeft.getPosition());
//
// telemetry.addData(" Vaule of: servoRight.getPwmRange(): ", servoRight.getPwmRange());
// telemetry.addData("Value of: servoRight.isPwmEnabled(): ", servoRight.isPwmEnabled());
// telemetry.addData("Value of servoRight.getPosition();", servoRight.getPosition());
//
// telemetry.addData("lift.getCurrentPosition(): ", lift.getCurrentPosition());
//
//
// telemetry.update();
if (gamepad2.left_trigger > 0.05 && gamepad2.right_trigger < 0.05) { // Raise up on right trigger
// lift.setTargetPosition(lift.get CurrentPosition()+100);
lift.setPower(1);
telemetry.addData("Lift position - ", lift.getCurrentPosition());
}
if (gamepad2.right_trigger > 0.05 && gamepad2.left_trigger < 0.05) {
// lift.setTargetPosition(lift.getCurrentPosition()-100);
lift.setPower(-1);
telemetry.addData("Lift position - ", lift.getCurrentPosition());
}
if (gamepad2.left_trigger < 0.05 && gamepad2.right_trigger < 0.05) { // neither pressed
// lift.setTargetPosition(lift.getCurrentPosition());
telemetry.addData("Lift position - ", lift.getCurrentPosition());
lift.setPower(0);
}
telemetry.update();
float closeDistance = 1.0f;
float openDistance = 0.6f;
// Right trigger controller 2
// Starts closed with cone and clawInvertRight = true
if (gamepad2.right_bumper && !clawInvertRight && !gamepad2.left_bumper) {
// Servo only go 0 to 1
servoRight.setPosition(closeDistance); // Close
servoLeft.setPosition(1.0f - closeDistance); // Close
clawInvertRight = !clawInvertRight;
}
if (gamepad2.left_bumper && clawInvertRight && !gamepad2.right_bumper) {
servoRight.setPosition(openDistance); // Open
servoLeft.setPosition(1.0f - openDistance); // Open
clawInvertRight = !clawInvertRight;
}
// if (gamepad1.right) {
// servoRight.setPosition(servoRight.getPosition());
// servoLeft.setPosition(servoLeft.getPosition());
// }
// float closeDistance = 1.0f;
// float openDistance = 0.6f;
//
// // Right trigger controller 2
// // Starts closed with cone and clawInvertRight = true
// if (gamepad1.right_trigger > 0.05 && !clawInvertRight) {
// // Servo only go 0 to 1
//
// servoRight.setPosition(closeDistance); // Close
// clawInvertRight = !clawInvertRight;
// }
//
// if (gamepad2.right_trigger > 0.05 && clawInvertRight) {
// servoRight.setPosition(openDistance); // Open
// clawInvertRight = !clawInvertRight;
// }
// else {
// servoRight.setPosition(servoRight.getPosition());
// }
//
// // Left trigger controller 2
// // Starts closed with cone and clawInvertLeft = true at start
// if (gamepad1.left_trigger > 0.05 && !clawInvertLeft) {
// servoLeft.setPosition(1.0f - closeDistance); // Close
// clawInvertLeft = !clawInvertLeft;
// }
// if (gamepad1.left_trigger > 0.05 && clawInvertLeft) {
// servoLeft.setPosition(1.0f - openDistance); // Open
// clawInvertLeft = !clawInvertLeft;
// }
// else {
// servoLeft.setPosition(servoLeft.getPosition());
// }
}
}
}