Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
Autobalance work + making A1C better--> centerline protection and get…
Browse files Browse the repository at this point in the history
… last cube fully in.
  • Loading branch information
MOE 365 Programming Laptop authored and MOE 365 Programming Laptop committed Mar 5, 2023
1 parent 4d211c4 commit b43c1c0
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Robot extends TimedRobot {
ExitAndEngage = new ExitAndEngageSideways(),
A1B2C = new A1B2C();

genericAutonomous autonomous = new A1CDock();
genericAutonomous autonomous = A1C;
GenericTeleop teleop = new DriveCode();
DriverStation.Alliance OurAllianceColor;
GenericRobot robot = new TherMOEDynamic();
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/frc/robot/autonomous/A1C.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class A1C extends genericAutonomous {
double thirdDist = AutoCodeLines.getDistance(thirdPosition, fourthPosition);
double fourthDist = AutoCodeLines.getDistance(fourthPosition, endPosition);

double centerLineBlue = 300;
double centerLineBlue = 295;
double centerLine = centerLineBlue;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double kP = 1.0e-1; //.5e-1
Expand Down Expand Up @@ -254,10 +254,22 @@ public void autonomousPeriodic(GenericRobot robot) {
collectorRPM = 0;
armPos = -4;
xspd = yspd = 0;
if (robot.getArmPosition() < 0){
m_timer.reset();
m_timer.start();
autonomousStep ++;
}
break;
case 7:
xspd = -12;
if (robot.getRed()) xspd = -xspd;
if (m_timer.get() >= .8){
xspd = yspd = 0;
}
break;

}
if (autonomousStep > 0 && autonomousStep < 6) turnspd = PID.calculate(-robot.getYaw());
if (autonomousStep > 0) turnspd = PID.calculate(-robot.getYaw());
robot.raiseTopRoller(collectorUp);
robot.setDrive(xspd, yspd, turnspd, true);
robot.collect(collectorRPM, autoMode);
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/frc/robot/autonomous/ExitAndEngageSideways.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@
public class ExitAndEngageSideways extends genericAutonomous{
double basePower = 35.0;
double high = 13.5;
double climbPower = 20.0;
double climbPower = 30.0;
double correctionPower = 13.0;
double desiredPitch = 9.0;
double firstBreak = 5;
double dropping = 9;
double xspd;
double timerDelta;
Timer m_timer = new Timer();

double xPos;
@Override
public void autonomousInit(GenericRobot robot) {
autonomousStep = 0;
timerDelta = 0;
climbPower = 20;
climbPower = 30;
robot.setPigeonYaw(-90);
robot.resetStartDists();
robot.resetAttitude();
robot.resetStartPivots();
robot.resetStartHeading();
robot.setPose();
}

@Override
Expand All @@ -34,17 +39,22 @@ public void autonomousPeriodic(GenericRobot robot) {
case 0:
xspd = basePower;
if (Math.abs(currPitch) > firstBreak) {

//Add length of the robot from front encoder to end of back wheel.
autonomousStep++;
}
break;
case 1:
xspd = basePower;
if (Math.abs(currPitch) > high) {
xPos = robot.getPose().getX();
autonomousStep++;
}
break;
case 2:
if(robot.getPose().getX() - xPos >= 32){
climbPower = 13;
}
xspd = climbPower;
if (Math.abs(currPitch) < dropping) {
autonomousStep++;
Expand Down
129 changes: 129 additions & 0 deletions src/main/java/frc/robot/autonomous/mobilityEngage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package frc.robot.autonomous;

import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import frc.robot.generic.GenericRobot;


public class mobilityEngage extends genericAutonomous{
double basePower = 35.0;
double high = 13.5;
double climbPower = 30.0;
double correctionPower = 13.0;
double desiredPitch = 9.0;
double firstBreak = 5;
double dropping = 9;
double xspd;
double timerDelta;
Timer m_timer = new Timer();
double xPos;
@Override
public void autonomousInit(GenericRobot robot) {
autonomousStep = 0;
timerDelta = 0;
climbPower = 30;
basePower = 35.0;
correctionPower = 13.0;
robot.setPigeonYaw(-90);
robot.resetStartDists();
robot.resetAttitude();
robot.resetStartPivots();
robot.resetStartHeading();
robot.setPose();
}

@Override
public void autonomousPeriodic(GenericRobot robot) {
SmartDashboard.putNumber("autonomousStep", autonomousStep);

double currPitch = -robot.getRoll();
switch (autonomousStep) {
case 0:
xspd = basePower;
if (Math.abs(currPitch) > firstBreak) {

//Add length of the robot from front encoder to end of back wheel.
autonomousStep++;
}
break;
case 1:
xspd = basePower;
if (currPitch > high) {
xPos = robot.getPose().getX();
autonomousStep++;
}
break;
case 2:
xspd = climbPower;
if (Math.abs(currPitch) < dropping) {
autonomousStep++;
}
break;
case 3:
xspd = climbPower;
if (Math.abs(currPitch) > high){
autonomousStep ++;
}
break;
case 4:
xspd = climbPower;
if (Math.abs(currPitch) < desiredPitch){
xPos = robot.getPose().getX();
autonomousStep ++;
}
break;
case 5:
xspd = climbPower;
if (Math.abs(robot.getPose().getX() - xPos) > 36){
xspd = 0;
autonomousStep ++;
}
break;
case 6:
climbPower = -30;
basePower = -35.0;
correctionPower = -13.0;
autonomousStep ++;
break;
case 7:
xspd = basePower;
if (Math.abs(currPitch) > high) {
xPos = robot.getPose().getX();
autonomousStep++;
}
break;
case 8:
if(Math.abs(robot.getPose().getX() - xPos) >= 32){
climbPower = -13;
}
xspd = climbPower;
if (Math.abs(currPitch) < dropping) {
autonomousStep++;
}
break;
case 9:
xspd = -correctionPower;
m_timer.reset();
m_timer.start();
//This is a future feature to stop and let others get on before autobalancing.
autonomousStep++;
break;
case 10:
if ((currPitch < -desiredPitch) && (m_timer.get() <1)) { //correcting begins
timerDelta = m_timer.get();
xspd = -correctionPower; //backward
} else if ((currPitch > desiredPitch) && (m_timer.get() <1)) {
timerDelta = m_timer.get();
xspd = correctionPower;//forward
} else {
xspd = 0;
if (m_timer.get()-timerDelta > .25) {
m_timer.reset();
m_timer.start();
}
}
break;
}
robot.setDrive(xspd, 0, 0, true);
}
}

0 comments on commit b43c1c0

Please sign in to comment.