Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 0ab63e0

Browse files
committed
finished elevator
1 parent 818f508 commit 0ab63e0

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

src/main/java/com/team766/robot/rookie_bot/OI.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.team766.hal.RobotProvider;
77
import com.team766.logging.Category;
88
import com.team766.robot.example.procedures.*;
9+
import com.team766.robot.rookie_bot.procedures.PIDElevator;
910

1011
/**
1112
* This class is the glue that binds the controls on the physical operator
@@ -36,6 +37,13 @@ public void run(final Context context) {
3637

3738
Robot.drive.setArcadeDrivePower(-1 * joystick0.getAxis(1), joystick0.getAxis(3));
3839
context.waitFor(() -> RobotProvider.instance.hasNewDriverStationData());
40+
if (joystick0.getButtonPressed(1)) {
41+
context.startAsync(new PIDElevator(true));
42+
43+
}
44+
if (joystick0.getButtonPressed(2)) {
45+
context.startAsync(new PIDElevator(false));
46+
}
3947
}
4048
}
4149
}

src/main/java/com/team766/robot/rookie_bot/procedures/PIDElevator.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,34 @@
44
import com.team766.framework.Context;
55
import com.team766.robot.rookie_bot.Robot;
66

7-
public class PIDElevator extends Procedure{
7+
public class PIDElevator extends Procedure {
88
double setpoint;
99
PIDController controller;
1010

11-
public PIDElevator(){
12-
this.setpoint = 1;
13-
}
11+
public PIDElevator(boolean top) {
12+
if (top) {
13+
setpoint = 400;
14+
15+
} else {
16+
setpoint = 0;
17+
}
1418

15-
Public void run (Context context){
16-
context.
19+
}
1720

21+
public void run(Context context) {
22+
context.takeOwnership(Robot.elevator);
23+
Robot.elevator.resetEncoder(); //clear encoder
24+
25+
controller = new PIDController(0, 0, 0, 0, 1, 0.01); // values a P I D, min. max. and threshold
26+
controller.setSetpoint(setpoint); //tell our PID contoller our setpoint
27+
28+
while (!controller.isDone()) { //stop loop when we get to setpoint
29+
controller.calculate(Robot.elevator.getElevatorDistance()); //pass the feedback into the PID
30+
double motor_effort = controller.getOutput(); //get the PID controller output for this cycle
31+
Robot.elevator.move(motor_effort); //MOVE THE ELEVATOR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1 (that 1 was a typo)
32+
}
33+
34+
Robot.elevator.move(0); //Make sure that the dang elevator stopped moving!!!!!!
35+
context.yield();
36+
}
37+
}

0 commit comments

Comments
 (0)