-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTonyTelOp-FC
More file actions
204 lines (164 loc) · 6.93 KB
/
TonyTelOp-FC
File metadata and controls
204 lines (164 loc) · 6.93 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
195
196
197
198
199
200
201
202
203
204
package org.firstinspires.ftc.teamcode;
import com.qualcomm.hardware.bosch.BNO055IMU;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.ElapsedTime;
@TeleOp(name = "TonyComboOpMode2", group = "OldTony")
//@Disabled
public class TonyComboOpMode2 extends LinearOpMode {
TonyRobotHardware robot = new TonyRobotHardware();
private ElapsedTime runtime = new ElapsedTime();
/**
* Create IMU
*/
public BNO055IMU imu;
public void runOpMode() throws InterruptedException {
boolean isUp = true;
double negLiftPow = 0;
double speedBoost =0;
// Make sure your ID's match your configuration
robot.init(hardwareMap);
PodsUp();
// Initialize IMU here as the hardware Class uses DEGREES and RADIANS are used here.
//Hardware could be cleaned up, but currently Auto programs use DEGREES
BNO055IMU imu = hardwareMap.get(BNO055IMU.class, "imu");
BNO055IMU.Parameters parameters = new BNO055IMU.Parameters();
// Technically this is the default, however specifying it is clearer
parameters.angleUnit = BNO055IMU.AngleUnit.RADIANS;
// Without this, data retrieving from the IMU throws an exception
imu.initialize(parameters);
waitForStart();
if (isStopRequested()) return;
while (opModeIsActive()) {
speedBoost = gamepad1.right_trigger/2;
//establish joystick variables
double y;
double x;
double rx;
y = (-gamepad1.left_stick_y /2); // Remember, joystick is reversed therefore changed to neg!
x = (gamepad1.left_stick_x /2); // Counteract imperfect strafing
rx = (gamepad1.right_stick_x /2);
// Read inverse (neg in front) IMU heading, as the IMU heading is CW positive
double botHeading = -imu.getAngularOrientation().firstAngle;
double rotX = x * Math.cos(botHeading) - y * Math.sin(botHeading);
double rotY = x * Math.sin(botHeading) + y * Math.cos(botHeading);
// Denominator is the largest motor power (absolute value) or 1
// This ensures all the powers maintain the same ratio, but only when
// at least one is out of the range [-1, 1]
double denominator = Math.max(Math.abs(y) + Math.abs(x) + Math.abs(rx), 1);
//calculate motorPower for adjusted botHeading
double frontLeftPower = (rotY + rotX + rx) / denominator;
double backLeftPower = (rotY - rotX + rx) / denominator;
double frontRightPower = (rotY - rotX - rx) / denominator;
double backRightPower = (rotY + rotX - rx) / denominator;
//Set motor power using Boost method (calculatedPower +- speedBoost)
robot.frontLeft.setPower(Boost(frontLeftPower,speedBoost));
robot.backLeft.setPower(Boost(backLeftPower,speedBoost));
robot.frontRight.setPower(Boost(frontRightPower,speedBoost));
robot.backRight.setPower(Boost(backRightPower,speedBoost));
/**********************************************
END OF CHASSIS CONTROL
**********************************************/
//open palm (x)
if (gamepad2.b)
{
//open palm
robot.palmL.setPosition(0.5); // center
robot.palmR.setPosition(0.5); // center
}
//close palm (o)
if (gamepad2.a)
{
robot.palmL.setPosition(1); // right limit
robot.palmR.setPosition(0); // left limit
}
//region swing arm
if(gamepad2.right_stick_y > 0.1 || gamepad2.right_stick_y < -0.1) {
robot.armMotor.setPower(-gamepad2.right_stick_y / 0.5);
robot.armHoldpos = robot.armMotor.getCurrentPosition();
}
else
{
robot.armMotor.setPower((double)(robot.armHoldpos - robot.armMotor.getCurrentPosition()) / robot.slopeVal);
}
//endregion
//region spin wrist
if(gamepad2.right_stick_x > 0.5 && isUp)
{
robot.wrist.setPosition(0);
isUp = false;
}
if(gamepad2.right_stick_x < -0.5 && !isUp)
{
robot.wrist.setPosition(1);
isUp = true;
}
telemetry.addData("Is Up", isUp);
//endregion
//region Lift Motors
//Restrict downward linear slide movement if touch sensor is pressed
if(robot.liftTouch.isPressed())
{
negLiftPow = 0;
}
else if(!robot.liftTouch.isPressed())
{
negLiftPow = gamepad2.left_trigger;
}
if(gamepad2.right_trigger > 0.1 || gamepad2.left_trigger > 0.1)
{
robot.liftL.setPower((gamepad2.right_trigger) - (negLiftPow));
robot.liftR.setPower((gamepad2.right_trigger) - (negLiftPow));
robot.liftLHoldPos = robot.liftL.getCurrentPosition();
robot.liftRHoldPos = robot.liftR.getCurrentPosition();
}
else
{
robot.liftL.setPower((double)(robot.liftLHoldPos - robot.liftL.getCurrentPosition()) / robot.slopeVal);
robot.liftR.setPower((double)(robot.liftRHoldPos - robot.liftR.getCurrentPosition()) / robot.slopeVal);
}
//endregion
/**TESTING PODS positioning
* ********************************
*/
if(gamepad2.dpad_down) {
robot.podLeft.setPosition(0.7); // 0.7 is down
robot.podRight.setPosition(0.0); // 0 is down
robot.podBack.setPosition(0.0); // 0.4 is down
}
if(gamepad2.dpad_up) {
robot.podLeft.setPosition(0.0); //
robot.podRight.setPosition(0.9); //
robot.podBack.setPosition(0.9); //
}
//display debug telemetry
telemetry.addData("heading",(int)botHeading);
telemetry.update();
}
}
/**
*
* @METHODS USED IN CODE ABOVE
*/
//speedboost method
public double Boost(double iMotorPower, double boostVal)
{
//determine if calculated power is pos/neg
//to determine whether to add or subtract Boost value
//returns double
if(iMotorPower < 0){
return iMotorPower -boostVal;
}
else
{
return iMotorPower + boostVal;
}
}
public void PodsUp(){
robot.podLeft.setPosition(0.0); //
robot.podRight.setPosition(0.9); //
robot.podBack.setPosition(0.9); //
}
}