This repository has been archived by the owner on Oct 15, 2024. 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
1 parent
5865b10
commit 61a7428
Showing
8 changed files
with
184 additions
and
13 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
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 |
---|---|---|
@@ -0,0 +1,164 @@ | ||
package frc.robot.autonomous; | ||
|
||
import edu.wpi.first.math.controller.PIDController; | ||
import edu.wpi.first.networktables.NetworkTable; | ||
import edu.wpi.first.networktables.NetworkTableEntry; | ||
import edu.wpi.first.networktables.NetworkTableInstance; | ||
import frc.robot.generic.GenericRobot; | ||
|
||
//Simple autonomous code for ball C, closest ball to the hangar, and driving to the ball at terminal | ||
//Setup: Line the robot straight between ball C and the center point of the hub | ||
public class ShortRun extends GenericAutonomous { | ||
double startingYaw; | ||
double startDistance; | ||
double startTime; | ||
|
||
double leftpower; | ||
double rightpower; | ||
double defaultPower = .6; | ||
double correction; | ||
boolean time = false; | ||
|
||
double distanceC = 47.9; | ||
double distanceTerminal = 225; | ||
double angleC = 82.74; | ||
double rampDownDist = 10; | ||
|
||
PIDController PIDDriveStraight; | ||
PIDController PIDTurret; | ||
PIDController PIDPivot; | ||
|
||
int averageTurretXSize = 2; | ||
double[] averageTurretX = new double [averageTurretXSize]; | ||
int counter = 0; | ||
|
||
double shooterTargetRPM; | ||
boolean readyToShoot; | ||
|
||
double indexerPct; | ||
double collectorPct; | ||
|
||
|
||
|
||
@Override | ||
public void autonomousInit(GenericRobot robot) { | ||
autonomousStep = 0; | ||
startingYaw = robot.getYaw(); | ||
startTime = System.currentTimeMillis(); | ||
shooterTargetRPM = 0; | ||
indexerPct = 0; | ||
collectorPct = 0; | ||
readyToShoot = false; | ||
PIDDriveStraight = new PIDController(robot.getPIDmaneuverP(), robot.getPIDmaneuverI(), robot.getPIDmaneuverD()); | ||
PIDPivot = new PIDController(robot.getPIDpivotP(), robot.getPIDpivotI(), robot.getPIDpivotD()); | ||
PIDTurret = new PIDController(robot.turretPIDgetP(), robot.turretPIDgetI(), robot.turretPIDgetD()); | ||
robot.setPipeline(0); | ||
} | ||
|
||
@Override | ||
public void autonomousPeriodic(GenericRobot robot) { | ||
|
||
if(robot.isTargetFound()) { | ||
averageTurretX[counter % averageTurretXSize] = robot.getTargetX(); | ||
counter++; | ||
} | ||
|
||
double average = 0; | ||
for(double i: averageTurretX){ | ||
average += i; | ||
} | ||
average /= averageTurretXSize; | ||
|
||
double currentTurretPower = 0; | ||
|
||
if(robot.isTargetFound()){ | ||
currentTurretPower = PIDTurret.calculate(average); | ||
}else{ | ||
PIDTurret.reset(); | ||
} | ||
|
||
if (autonomousStep < 4){ | ||
if((!robot.isTargetFound()) && (System.currentTimeMillis() - startTime < 5000)) { | ||
currentTurretPower = .3; | ||
} | ||
} | ||
if ((autonomousStep>=4) && (autonomousStep < 8)){ | ||
if((!robot.isTargetFound()) && (System.currentTimeMillis() - startTime < 5000)) { | ||
currentTurretPower = -.2; | ||
} | ||
} | ||
robot.setTurretPowerPct(currentTurretPower); | ||
|
||
if (autonomousStep >= 1){ | ||
robot.getCargo(); | ||
robot.shoot(); | ||
} | ||
if (autonomousStep >= 1 && autonomousStep <=10){ | ||
robot.setTurretPitchPosition(.38); | ||
} | ||
else{ | ||
robot.setCollectorIntakePercentage(0); | ||
robot.setTurretPowerPct(0); | ||
} | ||
switch(autonomousStep){ | ||
case 0: //reset | ||
robot.lowerCollector(); | ||
PIDPivot.reset(); | ||
PIDPivot.enableContinuousInput(-180,180); | ||
PIDDriveStraight.reset(); | ||
PIDDriveStraight.enableContinuousInput(-180,180); | ||
robot.resetEncoders(); | ||
robot.resetAttitude(); | ||
if (System.currentTimeMillis() - startTime > 500){ | ||
autonomousStep += 1; | ||
startingYaw = robot.getYaw(); | ||
startDistance = robot.getDriveDistanceInchesLeft(); | ||
} | ||
break; | ||
case 1: //drive to ball C | ||
collectorPct = 1; | ||
correction = PIDDriveStraight.calculate(robot.getYaw() - startingYaw); | ||
|
||
leftpower = defaultPower + correction; | ||
rightpower = defaultPower - correction; | ||
|
||
if(robot.getDriveDistanceInchesLeft() - startDistance >= distanceC - rampDownDist){ | ||
double ramp = rampDown(defaultPower, .1, startDistance, rampDownDist, | ||
robot.getDriveDistanceInchesLeft(), distanceC); | ||
leftpower = ramp; | ||
rightpower = ramp; | ||
} | ||
if(robot.getDriveDistanceInchesLeft() - startDistance >= distanceC){ | ||
autonomousStep += 1; | ||
startTime = System.currentTimeMillis(); | ||
} | ||
break; | ||
case 2: //stop | ||
leftpower = 0; | ||
rightpower = 0; | ||
startDistance = robot.getDriveDistanceInchesLeft(); | ||
autonomousStep += 1; | ||
time = false; | ||
break; | ||
case 3: //create a target shooter value and see if shooter reaches it. | ||
if (robot.isTargetFound() && robot.canShoot() && (-5 < average) && (average< 5)){ | ||
robot.setActivelyShooting(true); | ||
startTime = System.currentTimeMillis(); | ||
autonomousStep += 1; | ||
} | ||
break; | ||
case 4: //turn the shooter off | ||
if (System.currentTimeMillis() - startTime >= 2000){ | ||
robot.setActivelyShooting(false); | ||
autonomousStep += 1; | ||
} | ||
break; | ||
|
||
case 5: //End of autonomous, wait for Teleop | ||
leftpower = 0; | ||
rightpower = 0; | ||
break; | ||
} | ||
robot.drivePercent(leftpower, rightpower); | ||
} | ||
} |
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