forked from NicholsSchool/2023-RoboKart-Side-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBowserMecanum
153 lines (107 loc) · 4.88 KB
/
BowserMecanum
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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.hardware.ColorSensor;
import com.qualcomm.hardware.rev.RevBlinkinLedDriver;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.ElapsedTime;
@TeleOp(name="BowserMecanum", group="Iterative Opmode")
public class BowserMecanum extends OpMode{
private ElapsedTime runtime = new ElapsedTime();
private DcMotor leftMotorF = null;
private DcMotor leftMotorB = null;
private DcMotor rightMotorF = null;
private DcMotor rightMotorB = null;
public RevBlinkinLedDriver blinkin = null;
RevBlinkinLedDriver.BlinkinPattern pattern;
ColorSensor colorSensor;
Servo servo;
double leftPowerF;
double leftPowerB;
double rightPowerF;
double rightPowerB;
double topSpeed;
double crawl;
boolean isTank = false;
@Override
public void init() {
telemetry.addData("Status", "Initialized");
leftMotorF = hardwareMap.get(DcMotor.class, "leftMotorF");
leftMotorB = hardwareMap.get(DcMotor.class, "leftMotorB");
rightMotorF = hardwareMap.get(DcMotor.class, "rightMotorF");
rightMotorB = hardwareMap.get(DcMotor.class, "rightMotorB");
blinkin = hardwareMap.get(RevBlinkinLedDriver.class,"blinkin");
colorSensor = hardwareMap.get(ColorSensor.class,"colorSensor");
servo = hardwareMap.get(Servo.class,"servo");
leftMotorF.setDirection(DcMotor.Direction.REVERSE);
leftMotorB.setDirection(DcMotor.Direction.REVERSE);
rightMotorF.setDirection(DcMotor.Direction.FORWARD);
rightMotorB.setDirection(DcMotor.Direction.FORWARD);
leftMotorF.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
leftMotorB.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
rightMotorF.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
rightMotorB.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
telemetry.addData("Status", "Initialized");
}
@Override
public void init_loop() {
}
@Override
public void start() {
runtime.reset();
}
@Override
public void loop() {
if (gamepad1.dpad_up) {
isTank = true;
}
if (gamepad1.dpad_down) {
isTank = false;
}
if (!isTank) {
double drive = -gamepad1.left_stick_y;
double turn = gamepad1.right_stick_x;
leftPowerF = ((drive + turn) * topSpeed) + gamepad1.left_trigger - gamepad1.right_trigger;
leftPowerB = ((drive + turn) * topSpeed) - gamepad1.left_trigger + gamepad1.right_trigger;
rightPowerF = ((drive - turn) * topSpeed) - gamepad1.left_trigger + gamepad1.right_trigger;
rightPowerB = ((drive - turn) * topSpeed) + gamepad1.left_trigger - gamepad1.right_trigger;
}
if (isTank) {
leftPowerF = -gamepad1.left_stick_y ;
leftPowerB = -gamepad1.left_stick_y ;
rightPowerF = -gamepad1.right_stick_y ;
rightPowerB = -gamepad1.right_stick_y ;
}
if (leftPowerF > 0 && leftPowerB > 0 && rightPowerF > 0 && rightPowerB > 0) {
blinkin.setPattern(RevBlinkinLedDriver.BlinkinPattern.GREEN);
}
if (leftPowerF == 0 && leftPowerB == 0 && rightPowerF == 0 && rightPowerB == 0) {
blinkin.setPattern(RevBlinkinLedDriver.BlinkinPattern.WHITE);
}
if (leftPowerF < 0 && leftPowerB < 0 && rightPowerF < 0 && rightPowerB < 0) {
blinkin.setPattern(RevBlinkinLedDriver.BlinkinPattern.RED);
}
if (colorSensor.red() <= 400 && colorSensor.red() >= 260 && colorSensor.green() <= 250 && colorSensor.blue() <= 150) {
topSpeed = 0.2;
}else if (colorSensor.green() <= 350 && colorSensor.green() >= 210 && colorSensor.blue() <= 250 && colorSensor.red() <= 110) {
topSpeed = 0.8;
}else {
topSpeed = 1;
}
leftMotorF.setPower(leftPowerF);
leftMotorB.setPower(leftPowerB);
rightMotorF.setPower(rightPowerF);
rightMotorB.setPower(rightPowerB);
telemetry.addData("Status", "Run Time: " + runtime.toString());
telemetry.addData("isTank", isTank);
telemetry.addData("topSpeed", topSpeed);
telemetry.addData("red", colorSensor.red());
telemetry.addData("green", colorSensor.green());
telemetry.addData("blue", colorSensor.blue());
}
@Override
public void stop() {
}
}