-
Notifications
You must be signed in to change notification settings - Fork 1
/
TeleOp10415.java
178 lines (155 loc) · 6.63 KB
/
TeleOp10415.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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.util.ElapsedTime;
import com.qualcomm.robotcore.util.Range;
/**
* Created by Anthony on 9/14/2016.
*/
@TeleOp(name="TeleOp v1.3", group="Cool")
public class TeleOp10415 extends OpMode {
Hardware10415 robot = new Hardware10415();
double launcherPower = 1;
boolean launcherPadUp = false;
boolean launcherPadDown = false;
int speedPID = 4000;
@Override
public void init() {
robot.init(hardwareMap);
robot.motorLauncherLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
robot.motorLauncherRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
}
@Override
public void loop() {
double left = scaleInput(-gamepad1.left_stick_y);
double right = scaleInput(-gamepad1.right_stick_y);
robot.motorLauncherLeft.setMaxSpeed(speedPID);
robot.motorLauncherRight.setMaxSpeed(speedPID);
if(gamepad1.left_trigger > .5)
{
left /= 2;
right /= 2;
}
//Player 2 controls
if(gamepad2.a)
{
robot.motorLauncherRight.setPower(1/*launcherPower*/);
robot.motorLauncherLeft.setPower(1/*launcherPower*/);
}
else {
robot.motorLauncherRight.setPower(0);
robot.motorLauncherLeft.setPower(0);
}
if(gamepad2.dpad_up && !launcherPadUp) {
if(robot.motorLauncherLeft.getMaxSpeed() < 4000)
{
speedPID += 100;
}
/*if(launcherPower < 1.0) {
launcherPower += .1;
if(launcherPower > 1.0)
{
launcherPower = 1.0;
}
}
*/
//telemetry.addLine("Launcher Speed: " + launcherPower);
}
else if(gamepad2.dpad_down && !launcherPadDown)
{
if(robot.motorLauncherLeft.getMaxSpeed() > 0)
{
speedPID -= 100;
}
/*if(launcherPower < 0.1) {
launcherPower -= .1;
if(launcherPower < 0)
{
launcherPower = .1;
}
}*/
//telemetry.addLine("Launcher Speed: " + launcherPower);
}
telemetry.addLine("Launcher Speed: " + launcherPower);
telemetry.addLine("Launcher MaxSpeed:" + speedPID);
launcherPadUp = gamepad2.dpad_up;
launcherPadDown = gamepad2.dpad_down;
//if(gamepad2.y){
// runCatapult();
//}
/*
if(gamepad2.left_trigger > 0.0)
{
robot.motorLift.setPower(gamepad2.left_stick_y);
telemetry.addLine("Test");
}
else if(gamepad2.right_trigger > 0)
{
robot.motorLift.setDirection(DcMotorSimple.Direction.REVERSE);
robot.motorLift.setPower(gamepad2.left_stick_y);
}
else {
robot.motorLift.setPower(0);
}
*/
// write values to wheel motor
robot.motorLift.setPower(gamepad2.left_stick_y);
robot.motorFrontRight.setPower(right);
robot.motorFrontLeft.setPower(left);
robot.motorBackRight.setPower(right);
robot.motorBackLeft.setPower(left);
}
@Override
public void stop(){
}
/*
* This method scales the joystick input so for low joystick values, the
* scaled value is less than linear. This is to make it easier to drive
* the robot more precisely at slower speeds.
*/
double scaleInput(double dVal) {
double[] scaleArray = { 0.0, 0.05, 0.09, 0.10, 0.12, 0.15, 0.18, 0.24,
0.30, 0.36, 0.43, 0.50, 0.60, 0.72, 0.85, 1.00, 1.00 };
// get the corresponding index for the scaleInput array.
int index = (int) (dVal * 16.0);
if (index < 0) {
index = -index;
} else if (index > 16) {
index = 16;
}
double dScale = 0.0;
if (dVal < 0) {
dScale = -scaleArray[index];
} else {
dScale = scaleArray[index];
}
return dScale;
}
/*void runCatapult(){
if(catapultRunning == false *//*|| robot.motorCatapult.isBusy() == false*//*)
{
catapultRunning = true;
telemetry.addLine("True");
robot.motorCatapult.setPower(20);
robot.motorCatapult.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
robot.motorCatapult.setTargetPosition(350*4);
while(robot.motorCatapult.isBusy())
{
//Nothing
}
robot.motorCatapult.setTargetPosition(5*4); //Move to initl pos
while(robot.motorCatapult.isBusy())
{
//Nothing
}
robot.motorCatapult.setPower(0);
robot.motorCatapult.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
catapultRunning = false;
telemetry.addLine("false");
}
}*/
}