-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTele.java
More file actions
98 lines (83 loc) · 2.61 KB
/
Tele.java
File metadata and controls
98 lines (83 loc) · 2.61 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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
/**
* Created by khadija on 1/5/2019.
*/
@TeleOp(name = "Tele",group = "A")
public class Tele extends OpMode {
TeleMap bot = new TeleMap();
double xpow;
double ypow;
double zpow;
int count = 0;
@Override
public void init() {
//initalizes hardware map
bot.init(hardwareMap);
}
public void readGamePad() {
//assigns joystick values to variables
zpow = gamepad1.right_stick_x;
ypow = gamepad1.left_stick_y;
xpow = gamepad1.left_stick_x;
//creates a deadzone for left stick y
if (Math.abs(ypow) < .1) {
ypow = 0;
}
//creates a deadzone for left stick x
if (Math.abs(xpow) < .1) {
xpow = 0;
}
}
@Override
public void loop() {
//takes the joystick values and converts to motor speeds through holonomic calculations
readGamePad();
double theta = Math.atan2(ypow, xpow); //angle of joystick
double power = Math.pow(Math.max(Math.abs(xpow),Math.abs(ypow)),2); //logarithmic drive
// offset of pi/4 makes wheels strafe correctly at cardinal and intermediate directions
double cos = Math.cos(theta - Math.PI / 4);
double sin = Math.sin(theta - Math.PI / 4);
//eliminates incorrect signs resulting from double precision
if(Math.abs(cos)<.0000001){
cos=0;
}
if(Math.abs(sin)<.0000001){
sin=0;
}
double x = Math.signum(cos);
double y = Math.signum(sin);
bot.motorLF.setPower(power * -x + zpow);
bot.motorRF.setPower(power * y + zpow);
bot.motorRB.setPower(power * x + zpow);
bot.motorLB.setPower(power * -y + zpow);
if(gamepad2.a)
{
bot.intakeMotor.setPower(1);
}
if(gamepad2.b)
{
bot.intakeMotor.setPower(0);
}
if(gamepad2.y) {
bot.intakeMotor.setPower(-1);
}
bot.bucketMotor.setPower(-gamepad2.right_stick_y);
bot.hangMotor.setPower(-gamepad2.left_stick_y);
if(gamepad2.dpad_up) {
bot.bucketServo.setPosition(1.0);
}
if(gamepad2.dpad_down)
{
bot.bucketServo.setPosition(0.0);
}
if(bot.limit1.getVoltage()>.2||bot.limit2.getVoltage()>.2) {
count++;
if (count>2){
bot.intakeMotor.setPower(-1);
count = 0;
}
}
}
}