Skip to content

Commit

Permalink
3.13.2020 autoing
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesdnguyen03 committed Mar 13, 2020
1 parent 0180cb6 commit 55266d2
Show file tree
Hide file tree
Showing 16 changed files with 329 additions and 72 deletions.
3 changes: 1 addition & 2 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
public final class Constants {
public static final double hoodFromTrench = 930;
public static final double hoodTriangle = 550;
public static final double hoodAutoLine = 1117
;
public static final double hoodAutoLine = 1075;
public static final double turretFromTrench = -6;
public static final double turretLine = -7;
public static final double turretTriangle = 0;
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import frc.robot.commands.PIDHood;
import frc.robot.commands.PIDTurret;
import frc.robot.commands.TurretCommand;
import frc.robot.commands.auto.AutoIntaking;
import frc.robot.commands.auto.BasicAuto;
import frc.robot.commands.auto.ThisIsDumb;
import frc.robot.commands.auto.paths.BasicTurn;
import frc.robot.commands.auto.paths.Chain;
import frc.robot.commands.auto.paths.Example;
Expand Down Expand Up @@ -45,12 +47,15 @@ public void robotInit() {
configRobot();

m_chooser = new SendableChooser<>();
m_chooser.addOption("forward", new Move(1, false));
m_chooser.addOption("forward", new Move(4, false));
m_chooser.addOption("reverse", new Move(1, true));
m_chooser.addOption("reverse turn", new TurnReverse());
m_chooser.addOption("basic turning", new BasicTurn());
try {
m_chooser.addOption("basic auto", new BasicAuto());
m_chooser.addOption("Intake intakes", new AutoIntaking());
m_chooser.addOption("Just Testing Fwd", new ThisIsDumb());

m_chooser.addOption("example", new Example());
m_chooser.addOption("chain", new Chain());
m_chooser.addOption("smiles", new Smiles());
Expand All @@ -62,7 +67,7 @@ public void robotInit() {
} catch (final IOException e1) {
e1.printStackTrace();
}
SmartDashboard.putData("Auto choochooer", m_chooser);
SmartDashboard.putData("Auto chooBchooser", m_chooser);

}

Expand Down
53 changes: 53 additions & 0 deletions src/main/java/frc/robot/commands/AutoIntakeIntake.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

package frc.robot.commands;

import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.RobotContainer;
import frc.robot.subsystems.IntakeSub;

public class AutoIntakeIntake extends CommandBase {

public AutoIntakeIntake() {
addRequirements(RobotContainer.intakeSub);
// Use addRequirements() here to declare subsystem dependencies.
}

// Called when the command is initially scheduled.
@Override
public void initialize() {
System.out.println("Intake intake Command init");
SmartDashboard.putBoolean("Exist", true);
SmartDashboard.putBoolean("Not Exist", false);
SmartDashboard.putBoolean("Exist Execute", false);
}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
SmartDashboard.putBoolean("Exist Execute", true);
System.out.println("Intake intake Command exe");
RobotContainer.intakeSub.intakeOut();
RobotContainer.intakeSub.runIntake(IntakeSub.intakeSpeed);
}

// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
RobotContainer.intakeSub.runIntake(0);
SmartDashboard.putBoolean("Not Exist", true);
}

// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}
65 changes: 41 additions & 24 deletions src/main/java/frc/robot/commands/AutoShootIntake.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase;
Expand All @@ -15,62 +16,78 @@ public class AutoShootIntake extends CommandBase {
int numBall = 0;
boolean shoot;
boolean intaking;
boolean startTimer = false;
double tim = 0;
Timer t = new Timer();
public static boolean finished = false;

public AutoShootIntake(boolean intaking) {
addRequirements(RobotContainer.flywheelSub);
addRequirements(RobotContainer.intakeSub, RobotContainer.flywheelSub);
this.intaking = intaking;
}

@Override
public void initialize() {
t.reset();
shoot = false;
countBalls = 0;
finished = false;
RobotContainer.intakeSub.intakeIn();
}

@Override
public void execute() {
System.out.println("0");
System.out.println("Intaking: " + intaking);
if(!intaking){
System.out.println("1");
RobotContainer.intakeSub.intakeIn();
RobotContainer.flywheelSub.spinFlywheels(1);
System.out.println("1.5");
if(RobotContainer.flywheelSub.getFlywheelSpeed() > 16000) {shoot = true;}

if(RobotContainer.touchOne.get() && RobotContainer.touchTwo.get() && RobotContainer.touchThree.get()) numBall = 3;
else if(!RobotContainer.touchOne.get() && RobotContainer.touchTwo.get() && RobotContainer.touchThree.get() ||
RobotContainer.touchOne.get() && !RobotContainer.touchTwo.get() && RobotContainer.touchThree.get() ||
RobotContainer.touchOne.get() && RobotContainer.touchTwo.get() && !RobotContainer.touchThree.get()
) numBall = 2;
else if(!RobotContainer.touchOne.get() && !RobotContainer.touchTwo.get() && RobotContainer.touchThree.get() ||
!RobotContainer.touchOne.get() && RobotContainer.touchTwo.get() && !RobotContainer.touchThree.get() ||
RobotContainer.touchOne.get() && !RobotContainer.touchTwo.get() && !RobotContainer.touchThree.get()
) numBall = 1;
else numBall = 0;

if(numBall == 0){
t.reset();
if(RobotContainer.flywheelSub.getFlywheelSpeed() > 16000) {//16000
shoot = true;
if(!startTimer){
t.start();
startTimer = true;
tim = DriverStation.getInstance().getMatchTime();
}
}

if(shoot && numBall != 0){
if(shoot){
RobotContainer.intakeSub.runConveyorAndCPM(IntakeSub.starWheelAndCPMSpeed);
RobotContainer.intakeSub.runTurretFeeder(IntakeSub.conveyorMotorSpeed);
}
}else{
System.out.println("1");
RobotContainer.intakeSub.intakeOut();
RobotContainer.intakeSub.runIntake(IntakeSub.intakeSpeed);
}
if(t.get() != 0){
System.out.println("Timer is: " + t.get());
}

}

@Override
public void end(boolean interrupted) {
RobotContainer.intakeSub.runConveyorAndCPM(0);
RobotContainer.intakeSub.runTurretFeeder(0);
RobotContainer.intakeSub.intakeOut();
finished = true;
}

@Override
public boolean isFinished() {
if(!intaking)return numBall == 0 && t.get()>5;
return false;
return countBalls()>=3 || t.get()>5 || DriverStation.getInstance().getMatchTime()-tim > 5;
}

int countBalls = 0;
boolean prevTrue = false;
public int countBalls(){
if(!prevTrue && RobotContainer.touchThree.get()){
countBalls++;
}

if(!RobotContainer.touchThree.get()) prevTrue = false;
else prevTrue = true;

System.out.println("counting: " + countBalls);
System.out.println("prevTrue: " + prevTrue);
return countBalls;
}
}
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/commands/IntakeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void initialize() {

@Override
public void execute() {
if(RobotContainer.flywheelSub.getFlywheelSpeed() > 16000) shoot = true;
if(RobotContainer.flywheelSub.getFlywheelSpeed() > 16000) shoot = true;//16000
else shoot = false;
double axis2 = RobotContainer.manipulator.getRawAxis(2);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/commands/PIDTurret.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class PIDTurret extends CommandBase {

static PIDController pidController;
private static final double kP = 0.03;
private static final double kP = 0.025;
private static final double kI = 0.0001;
private static final double kD = 0;
private static final double tolerance = 2;
Expand Down
25 changes: 18 additions & 7 deletions src/main/java/frc/robot/commands/PositionControlCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.RobotContainer;
import frc.robot.subsystems.CPMSub;
Expand Down Expand Up @@ -35,13 +36,23 @@ public void initialize() {

@Override
public void execute() {
if (numOfColorsAway != 100000000){
if (numOfColorsAway <= 0) {
RobotContainer.cpmSub.runCPMAndIntake(CPMSub.CPMSpeed);
} else if (numOfColorsAway >= 0) {
RobotContainer.cpmSub.runCPMAndIntake(-CPMSub.CPMSpeed);
}
}

RobotContainer.cpmSub.printGetting();

SmartDashboard.putString("Get Color L", CPMSub.getColorL().toString());
SmartDashboard.putString("Get Color R", CPMSub.getColorR().toString());

// SmartDashboard.putString("Get Target Color", CPMSub.getTargetColor());

RobotContainer.intake2.set(-0.3);
//spin cpm motor
// if (numOfColorsAway != 100000000){
// if (numOfColorsAway <= 0) {
// RobotContainer.cpmSub.runCPMAndIntake(CPMSub.CPMSpeed);
// } else if (numOfColorsAway >= 0) {
// RobotContainer.cpmSub.runCPMAndIntake(-CPMSub.CPMSpeed);
// }
// }
}

@Override
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/frc/robot/commands/RotationControlCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.RobotContainer;
import frc.robot.subsystems.CPMSub;
Expand Down Expand Up @@ -29,7 +30,17 @@ public void initialize() {
@Override
public void execute() {

RobotContainer.cpmSub.printGetting();

SmartDashboard.putString("Get Color L", CPMSub.getColorL().toString());
SmartDashboard.putString("Get Color R", CPMSub.getColorR().toString());

// SmartDashboard.putString("Get Target Color", CPMSub.getTargetColor());

SmartDashboard.putNumber("Nymber of revs", numberOfRevs);

if(numberOfRevs < 3){
RobotContainer.intake2.set(0.3);
//spin cpm motor
}
if (t.hasElapsed(timeout) && CPMSub.getColorL() == startingColor) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

package frc.robot.commands.auto;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.RobotContainer;

public class AutoDistanceDriveCommand extends CommandBase {
private double distance;

public AutoDistanceDriveCommand() {
addRequirements(RobotContainer.driveSub);
}

@Override
public void initialize() {
}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
SmartDashboard.putNumber("this is the encoder of r1", RobotContainer.r1.getEncoder().getPosition());
RobotContainer.driveSub.drive(0.5, 0);
}

// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
}

// Returns true when the command should end.
@Override
public boolean isFinished() {
if(RobotContainer.r1.getEncoder().getPosition() > 35){
return true;
}
return false;
}
}
38 changes: 38 additions & 0 deletions src/main/java/frc/robot/commands/auto/AutoIntaking.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/

package frc.robot.commands.auto;

import edu.wpi.first.wpilibj2.command.ParallelCommandGroup;
import edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import frc.robot.commands.AutoIntakeIntake;
import frc.robot.commands.AutoShootIntake;
import frc.robot.commands.auto.paths.Move;

// NOTE: Consider using this command inline, rather than writing a subclass. For more
// information, see:
// https://docs.wpilib.org/en/latest/docs/software/commandbased/convenience-features.html
public class AutoIntaking extends SequentialCommandGroup {
/**
* Creates a new AutoIntaking.
*/
public AutoIntaking() {

addCommands(
// new AutoDistanceDriveCommand(),
new BasicAuto(),
// new Move(1, false).withTimeout(Move.commandTime),
new ParallelCommandGroup(
new AutoIntakeIntake(),
new Move(1, false).withTimeout(Move.commandTime)
)
);
// Add your commands in the super() call, e.g.
// super(new FooCommand(), new BarCommand());
}
}
6 changes: 3 additions & 3 deletions src/main/java/frc/robot/commands/auto/BasicAuto.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import frc.robot.Constants;
import frc.robot.RobotContainer;
import frc.robot.commands.AutoIntakeIntake;
import frc.robot.commands.AutoShootIntake;
import frc.robot.commands.PIDHood;
import frc.robot.commands.PIDTurret;
Expand All @@ -17,11 +18,10 @@ public class BasicAuto extends SequentialCommandGroup {
public BasicAuto() {
addCommands(
new ParallelDeadlineGroup(
new AutoShootIntake(false),
new AutoShootIntake(false).withInterrupt(() -> AutoShootIntake.finished),
new PIDTurret(Constants.turretLine),
new PIDHood(Constants.hoodAutoLine)
),
new Move(1, true)
)
);
}
}
Loading

0 comments on commit 55266d2

Please sign in to comment.