This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xavier
committed
Nov 23, 2024
1 parent
17050e3
commit 1d02372
Showing
5 changed files
with
62 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 36 additions & 31 deletions
67
src/main/java/com/team766/robot/rookie_bot/procedures/PIDElevator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,42 @@ | ||
package com.team766.robot.rookie_bot.procedures; | ||
import com.team766.framework.Procedure; | ||
|
||
import com.team766.controllers.PIDController; | ||
import com.team766.framework.Context; | ||
import com.team766.framework.Procedure; | ||
import com.team766.robot.rookie_bot.Robot; | ||
|
||
public class PIDElevator extends Procedure { | ||
double setpoint; | ||
PIDController controller; | ||
|
||
public PIDElevator(boolean top) { | ||
if (top) { | ||
setpoint = 400; | ||
|
||
} else { | ||
setpoint = 0; | ||
} | ||
|
||
} | ||
|
||
public void run(Context context) { | ||
context.takeOwnership(Robot.elevator); | ||
Robot.elevator.resetEncoder(); //clear encoder | ||
|
||
controller = new PIDController(0, 0, 0, 0, 1, 0.01); // values a P I D, min. max. and threshold | ||
controller.setSetpoint(setpoint); //tell our PID contoller our setpoint | ||
|
||
while (!controller.isDone()) { //stop loop when we get to setpoint | ||
controller.calculate(Robot.elevator.getElevatorDistance()); //pass the feedback into the PID | ||
double motor_effort = controller.getOutput(); //get the PID controller output for this cycle | ||
Robot.elevator.move(motor_effort); //MOVE THE ELEVATOR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1 (that 1 was a typo) | ||
} | ||
|
||
Robot.elevator.move(0); //Make sure that the dang elevator stopped moving!!!!!! | ||
context.yield(); | ||
public class PIDElevator extends Procedure { | ||
double setpoint; | ||
PIDController controller; | ||
|
||
public PIDElevator(boolean top) { | ||
if (top) { | ||
setpoint = 400; | ||
|
||
} else { | ||
setpoint = 0; | ||
} | ||
} | ||
} | ||
|
||
public void run(Context context) { | ||
context.takeOwnership(Robot.elevator); | ||
Robot.elevator.resetEncoder(); // clear encoder | ||
|
||
controller = | ||
new PIDController(0, 0, 0, 0, 1, 0.01); // values a P I D, min. max. and threshold | ||
controller.setSetpoint(setpoint); // tell our PID contoller our setpoint | ||
|
||
while (!controller.isDone()) { // stop loop when we get to setpoint | ||
controller.calculate( | ||
Robot.elevator.getElevatorDistance()); // pass the feedback into the PID | ||
double motor_effort = | ||
controller.getOutput(); // get the PID controller output for this cycle | ||
Robot.elevator.move(motor_effort); // MOVE THE | ||
// ELEVATOR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1 | ||
// (that 1 was a typo) | ||
} | ||
|
||
Robot.elevator.move(0); // Make sure that the dang elevator stopped moving!!!!!! | ||
context.yield(); | ||
} | ||
} |