-
Notifications
You must be signed in to change notification settings - Fork 0
/
MecaWheels
104 lines (84 loc) · 3.73 KB
/
MecaWheels
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
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.util.Range;
@TeleOp(name="Meca", group="Linear Opmode")
public class MecaWheels extends LinearOpMode{
// Declare OpMode members
HardwareBase robot = new HardwareBase();
@Override
public void runOpMode() {
telemetry.addData("Status", "Initialized");
telemetry.update();
/* Initialize the hardware variables.
* The init() method of the hardware class does all the work here
*/
robot.init(hardwareMap);
// Most robots need the motor on one side to be reversed to drive forward
// Reverse the motor that runs backwards when connected directly to the battery
// Wait for the game to start (driver presses PLAY)
waitForStart();
// run until the end of the match (driver presses STOP)
while (opModeIsActive()) {
double y = gamepad1.left_stick_y;
double x = gamepad1.left_stick_x;
double z = 0;
if(gamepad1.left_stick_x != 0)
z = (y/ x);
// Regular forward, backward, and sideways motions
if( z != 0)
{
robot.right_drive.setPower(scale((y-x)));
robot.right_drive1.setPower(scale((y+x)));
robot.left_drive.setPower(scale((y+x)));
robot.left_drive1.setPower(scale((y-x)));
}
robot.right_drive.setPower(scale((y-x-z)));
robot.right_drive1.setPower(scale((y+x-z)));
robot.left_drive.setPower(scale((y+x+z)));
robot.left_drive1.setPower(scale((y-x+z)));
//More Complex motions and manuvers
if(gamepad1.right_stick_y != 0 )
{
if(gamepad1.right_stick_y < 0)
{
robot.right_drive.setPower(scale((-y)));
robot.right_drive1.setPower(0);
robot.left_drive.setPower(scale((y)));
robot.left_drive1.setPower(0);
}
if(gamepad1.right_stick_y > 0)
{
robot.right_drive.setPower(0);
robot.right_drive1.setPower(scale((-y)));
robot.left_drive.setPower(0);
robot.left_drive1.setPower(scale((y)));
}
}
if(gamepad1.right_stick_x != 0 && gamepad1.right_stick_x == 0)
{
robot.right_drive.setDirection(DcMotor.Direction.REVERSE);
robot.left_drive.setDirection(DcMotor.Direction.REVERSE);
robot.right_drive1.setDirection(DcMotor.Direction.FORWARD);
robot.left_drive1.setDirection(DcMotor.Direction.FORWARD);
robot.right_drive.setPower(scale((y-x-z)));
robot.right_drive1.setPower(scale((y+x-z)));
robot.left_drive.setPower(scale((y+x+z)));
robot.left_drive1.setPower(scale((y-x+z)));
}
// Acqusition system controls
double extendArm = gamepad2.left_stick_y;
double rotate = gamepad2.right_stick_y;
robot.acq1.setPower(extendArm);
robot.acq2.setPower(rotate);
telemetry.addData("Current Position of Rotation", + robot.acq2.getCurrentPosition());
telemetry.addData("Current Position of Extension", + robot.acq1.getCurrentPosition() );
telemetry.update();
}
}
public double scale(double n)
{
return n;
}
}