-
Notifications
You must be signed in to change notification settings - Fork 0
/
Elevator.java
84 lines (66 loc) · 2.76 KB
/
Elevator.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
73
74
75
76
77
78
79
80
81
82
83
84
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.Gamepad;
import org.firstinspires.ftc.teamcode.Config;
import org.firstinspires.ftc.teamcode.motion.SpeedPID;
public class Elevator {
Config config;
long encoderPosition;
double maxSpeed = 0;
double actualSpeed = 0;
int actualPosition = 0;
SpeedPID speedPID;
//double newSetpoint = config.position1;
public Elevator(Config config) {
this.config = config;
speedPID = new SpeedPID(config.elevatorkP,config.elevatorkI,config.elevatorkD,config.elevatorkF);
speedPID.setlastT();
}
public void controllWithJoystick(Gamepad gamepad) {
encoderPosition = -config.rightElevator.getCurrentPosition();
double yValue = gamepad.left_stick_y;
if(Math.abs(yValue) > 0.1){
config.leftElevator.setPower(yValue);
config.rightElevator.setPower(yValue);
}else {
config.leftElevator.setPower(0);
config.rightElevator.setPower(0);
}
actualSpeed = -config.rightElevator.getVelocity();
if(actualSpeed > maxSpeed) {
maxSpeed = actualSpeed;
}
}
public void controllWithButton(Gamepad gamepad) {
encoderPosition = -config.rightElevator.getCurrentPosition();
if(gamepad.a) {
config.leftElevator.setTargetPosition(-750);
config.rightElevator.setTargetPosition(-750);
/* config.leftElevator.setVelocity(300);
config.rightElevator.setVelocity(300);*/
}else if(gamepad.b) {
config.leftElevator.setTargetPosition(-10);
config.rightElevator.setTargetPosition(-10);
}
}
public void controllWithStick(Gamepad gamepad) {
if(Math.abs(gamepad.left_stick_y) > 0.1) {
actualPosition -= gamepad.left_stick_y * 10;
if(actualPosition < 0) {
actualPosition = 0;
}
if(actualPosition > 750) {
actualPosition = 750;
}
/*if(config.touch.isPressed()) {
config.leftElevator.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
config.ri`g`htElevator.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
config.leftElevator.setMode(DcMotor.RunMode.RUN_TO_POSITION);
config.rightElevator.setMode(DcMotor.RunMode.RUN_TO_POSITION);
}*/
config.leftElevator.setTargetPosition(-actualPosition);
config.rightElevator.setTargetPosition(-actualPosition);
}
}
}