-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathZ_Only.java
More file actions
194 lines (156 loc) · 7.14 KB
/
Z_Only.java
File metadata and controls
194 lines (156 loc) · 7.14 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
package org.firstinspires.ftc.teamcode;
//imports
//eventloop components
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.CRServo;
import com.qualcomm.robotcore.hardware.Servo;
//utilities
import com.qualcomm.robotcore.util.ElapsedTime;
import com.qualcomm.robotcore.util.Range;
import java.util.*;
import java.lang.Math;
@TeleOp
public class Z_Only extends LinearOpMode {
// Servo-related variables
Servo specimen_claw;
boolean specimen_claw_open_status = true;
// Servo position constants
private static final double CLAW_OPEN_POSITION = 1.0; // Adjust these values
private static final double CLAW_CLOSED_POSITION = 0.0; // to match your servo's range
// Clamping power for continuous servo (if using CRServo)
private static final double CLAW_CLAMPING_POWER = 0.5; // Adjust as needed
private static final double PASSIVE_CLAMP_POWER = 0.1; // Low power to maintain grip
// Button state tracking to prevent multiple toggles
boolean lastBButtonState = false;
@Override
public void runOpMode(){
// Motor initializations (unchanged)
DcMotor frontLeftMotor = hardwareMap.dcMotor.get("frontLeftMotor");
DcMotor backLeftMotor = hardwareMap.dcMotor.get("backLeftMotor");
DcMotor frontRightMotor = hardwareMap.dcMotor.get("frontRightMotor");
DcMotor backRightMotor = hardwareMap.dcMotor.get("backRightMotor");
// Initialize the servo
specimen_claw = hardwareMap.servo.get("specimen claw"); // Make sure this matches your config
DcMotor armMotor = hardwareMap.dcMotor.get("armMotor");
// Motor direction and zero power behavior (unchanged)
frontRightMotor.setDirection(DcMotorSimple.Direction.REVERSE);
backRightMotor.setDirection(DcMotorSimple.Direction.REVERSE);
frontLeftMotor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
frontRightMotor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
backLeftMotor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
backRightMotor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
armMotor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
// Ensure initial servo position is open
specimen_claw.setPosition(CLAW_OPEN_POSITION);
waitForStart();
while (opModeIsActive()) {
// Existing drive code (unchanged)
double y = gamepad1.left_stick_y;
double x = -gamepad1.left_stick_x;
double rx = -gamepad1.right_stick_x;
// Rest of your existing drive code... (keep the motor power calculations)
boolean up2 = gamepad2.dpad_up; // Remember, Y stick value is reversed
boolean down2 = gamepad2.dpad_down; // Counteract imperfect strafing
boolean left2 = gamepad2.dpad_left;
boolean right2 = gamepad2.dpad_right;
double frontLeftPower;
double backLeftPower;
double frontRightPower;
double backRightPower;
double penis = -0.07;
if (up2) {
frontLeftPower = -0.2;
backLeftPower = -0.2;
frontRightPower = -0.2;
backRightPower = -0.2;
} else if (down2) {
frontLeftPower = 0.2;
backLeftPower = 0.2;
frontRightPower = 0.2;
backRightPower = 0.2;
} else if (left2) {
frontLeftPower = 0.3;
backLeftPower = -0.3 - 0.05;
frontRightPower = -0.3;
backRightPower = 0.3;
} else if (right2) {
frontLeftPower = -0.3;
backLeftPower = (0.3 + 0.05);
frontRightPower = 0.3;
backRightPower = -0.3;
} else {
if (y * y > x * x) {
if (y>0) {
frontLeftPower = y + rx;
backLeftPower = y + rx + 0;
frontRightPower = y - rx;
backRightPower = y - rx;
} else {
frontLeftPower = y + rx;
backLeftPower = y + rx - 0;
frontRightPower = y - rx;
backRightPower = y - rx;
}
} else {
if (x>0) {
frontLeftPower = x + rx;
backLeftPower = -x + rx + penis;
frontRightPower = -x - rx;
backRightPower = x - rx;
} else if (x<0) {
frontLeftPower = x + rx;
backLeftPower = -x + rx - penis;
frontRightPower = -x - rx;
backRightPower = x - rx;
} else {
frontLeftPower = x + rx;
backLeftPower = -x + rx;
frontRightPower = -x - rx;
backRightPower = x - rx;
}
}
}
// Servo control logic
if (gamepad2.b && !lastBButtonState) {
// Toggle claw state
if (specimen_claw_open_status) {
// Close the claw
specimen_claw.setPosition(CLAW_CLOSED_POSITION);
specimen_claw_open_status = false;
} else {
// Open the claw
specimen_claw.setPosition(CLAW_OPEN_POSITION);
specimen_claw_open_status = true;
}
}
// Store current B button state for next iteration
lastBButtonState = gamepad2.b;
// Existing motor power setting code
frontLeftMotor.setPower(frontLeftPower);
backLeftMotor.setPower(backLeftPower);
frontRightMotor.setPower(frontRightPower);
backRightMotor.setPower(backRightPower);
// Existing arm motor code
if (gamepad2.right_bumper) {
armMotor.setPower(0.5);
sleep(10);
armMotor.setPower(0);
} else if (gamepad2.left_bumper) {
armMotor.setPower(-0.5);
sleep(10);
armMotor.setPower(0);
}
if (!specimen_claw_open_status) {
specimen_claw.setPosition(CLAW_CLOSED_POSITION-0.02);
}
if (gamepad2.y) {
specimen_claw.setPosition(0);
}
telemetry.update();
}
}
}