forked from FIRST-Tech-Challenge/FtcRobotController
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTouchpadTeleop.java
191 lines (140 loc) · 6.26 KB
/
TouchpadTeleop.java
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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.CRServo;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.Servo;
@TeleOp
public class TouchpadTeleop extends LinearOpMode {
@Override
public void runOpMode() throws InterruptedException {
// Declare our motors
// Make sure your ID's match your configuration
float armSetting = 0;
double speedModifier = 1;
DcMotor frontLeftMotor = hardwareMap.dcMotor.get("frontleftmotor");
DcMotor backLeftMotor = hardwareMap.dcMotor.get("backleftmotor");
DcMotor frontRightMotor = hardwareMap.dcMotor.get("frontrightmotor");
DcMotor backRightMotor = hardwareMap.dcMotor.get("backrightmotor");
Servo IntakeLift = hardwareMap.servo.get("intakelift");
Servo OutputLift = hardwareMap.servo.get("outputlift");
Servo OutputRotation = hardwareMap.servo.get("outputrotate");
CRServo Intake = hardwareMap.crservo.get("intake");
DcMotor elevator = hardwareMap.dcMotor.get("elevator");
DcMotor armextender = hardwareMap.dcMotor.get("armextender");
frontLeftMotor.setDirection(DcMotorSimple.Direction.REVERSE);
backLeftMotor.setDirection(DcMotorSimple.Direction.REVERSE);
elevator.setDirection(DcMotorSimple.Direction.REVERSE);
waitForStart();
if (isStopRequested()) return;
while (opModeIsActive()) {
//movement
double y = gamepad1.touchpad_finger_1_y; // Remember, Y stick value is reversed
double x = gamepad1.touchpad_finger_1_x; // Counteract imperfect strafing
double rx = gamepad1.touchpad_finger_2_x;
//elevator
float ry = gamepad2.right_stick_y;
//arm extender
float dx = gamepad2.left_stick_x;
//intake
double intakepower = 0.25 * (gamepad2.right_trigger - gamepad2.left_trigger);
// Denominator is the largest motor power (absolute value) or 1
// This ensures all the powers maintain the same ratio,
// but only if at least one is out of the range [-1, 1]
double denominator = Math.max(Math.abs(y) + Math.abs(x) + Math.abs(rx), 1);
double frontLeftPower = ((y + x + rx) / denominator) * speedModifier;
double backLeftPower = ((y - x + rx) / denominator) * speedModifier;
double frontRightPower = ((y - x - rx) / denominator) * speedModifier;
double backRightPower = ((y + x - rx) / denominator) * speedModifier;
frontLeftMotor.setPower(frontLeftPower);
backLeftMotor.setPower(backLeftPower);
frontRightMotor.setPower(frontRightPower);
backRightMotor.setPower(backRightPower);
Intake.setPower(intakepower);
elevator.setPower(ry);
armextender.setPower(dx);
//setting position to dump the intake
if (gamepad2.a) {
IntakeLift.setPosition(0.9);
//setting the passive positon for the intake thing - so that it doesn't drag
} else if (gamepad2.b) {
IntakeLift.setPosition(0.55);
}
//this is going up
if (gamepad2.x) {
OutputRotation.setPosition(0.9);
telemetry.addData("Arm Down", 0);
}
if(gamepad2.y)
{
OutputLift.setPosition(0.35);
//eurvbleyivgbaelyrigfayeifduiahelfukhalerv
}
if(gamepad1.a)
{
speedModifier = 0.5;
}
else if (!gamepad1.a)
{
speedModifier = 1;
}
// is is so that the block doesn't fall off while going up - click dpad left while going up on outputlift
/*
if (gamepad2.dpad_left) {
OutputRotation.setPosition(0.5);
//this is so that it doesn't destroy the robot when it goes down. make sure to press dpad right
} else if (gamepad2.dpad_right) {
OutputRotation.setPosition(0.9);
}
*/
//for dumping
if (gamepad2.dpad_right) {
OutputRotation.setPosition(0.5);
} else if (gamepad2.dpad_left)
{
OutputRotation.setPosition(0.2);
}
if (gamepad2.dpad_up) {
OutputRotation.setPosition(0);
OutputLift.setPosition(0.3259);
}else if (gamepad2.dpad_down) {
OutputLift.setPosition(0.2957);
OutputRotation.setPosition(0.5);
}
if(gamepad2.options)
{
OutputLift.setPosition(0.3247);
}
telemetry.addData("Speed Modifier", speedModifier);
// set to drop bucket contents 0
//
/////////////////////////////////////////////////////////////////
///
/// Jim's Servo testing code for finding values of the servos.
/// comment out which servo you want to find the value of
/// The trigger buttons move the servo
// The servo value is displayed on the driver station
///
///
/// Comment this code block out for game time
///
/////////////////////////////////////////////////////////////////
/*if(gamepad2.right_bumper)
{
armSetting += 0.00008;
OutputLift.setPosition(armSetting);
// OutputRotation.setPosition(armSetting);
telemetry.addData("servo value",armSetting);
}
if(gamepad2.left_bumper)
{
armSetting -= 0.00008;
OutputLift.setPosition(armSetting);
// OutputRotation.setPosition(armSetting);
telemetry.addData("servo value",armSetting);
}*/
telemetry.update();
}
}
}