This repository has been archived by the owner on Jun 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoddlerNuke.java
72 lines (55 loc) · 1.93 KB
/
toddlerNuke.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
package com.qualcomm.ftcrobotcontroller.opmodes;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.util.Range;
public class toddlerNuke extends OpMode {
DcMotor motor_driveLeft;
DcMotor motor_driveRight;
DcMotor motor_lift;
public toddlerNuke () {
}
@Override
public void init () {
motor_driveLeft = hardwareMap.dcMotor.get("motor_1");
motor_driveRight = hardwareMap.dcMotor.get("motor_2");
motor_lift = hardwareMap.dcMotor.get("motor_lift");
motor_driveLeft.setDirection(DcMotor.Direction.REVERSE);
}
@Override
public void loop () {
float leftPower = -gamepad1.left_stick_y;
float rightPower = -gamepad1.right_stick_y;
float liftPower = -gamepad2.left_stick_y;
rightPower = Range.clip(rightPower, -1, 1);
leftPower = Range.clip(leftPower, -1, 1);
liftPower = Range.clip(liftPower, -1, 1);
leftPower = (float)scaleInput(leftPower);
rightPower = (float)scaleInput(rightPower);
liftPower = (float)scaleInput(liftPower);
motor_driveLeft.setPower(leftPower);
motor_driveRight.setPower(rightPower);
motor_lift.setPower(liftPower);
}
@Override
public void stop () {
}
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 };
int index = (int) (dVal * 16.0);
if (index < 0) {
index = -index;
} else if (index > 16) {
index = 16;
}
//used to be double dScale = 0.0
double dScale;
if (dVal < 0) {
dScale = -scaleArray[index];
} else {
dScale = scaleArray[index];
}
return dScale;
}
}