Skip to content

Commit

Permalink
Added ability to drive while finding ball. (Not Tested!)
Browse files Browse the repository at this point in the history
  • Loading branch information
keco185 committed Apr 9, 2014
1 parent c6e205b commit 6b4bc77
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 12 deletions.
9 changes: 6 additions & 3 deletions src/org/team484/fluffy/OI.java
Expand Up @@ -20,6 +20,7 @@
import org.team484.fluffy.commands.PickupWheelHalf;
import org.team484.fluffy.commands.PickupWheelOff;
import org.team484.fluffy.commands.PickupWheelOn;
import org.team484.fluffy.commands.SetShootBall;
import org.team484.fluffy.commands.ZeroGyro;

/**
Expand All @@ -41,7 +42,7 @@ public class OI {
Button magTest = new JoystickButton(shootStick, 8);
Button kickerOut = new JoystickButton(driveStick, 2);
Button pickupWheelBack = new JoystickButton(shootStick, RobotMap.pickupWheelBack);
Button followBall = new JoystickButton(driveStick, 7);
Button followBall = new JoystickButton(driveStick, 3);
Button safetyOverride = new JoystickButton(shootStick, 11);
public double getDriveX() {
return driveStick.getX();
Expand All @@ -60,8 +61,10 @@ public OI() {
//highShot.whenPressed(new PickupArmDown()); //added
//lobShot.whenPressed(new PickupArmDown()); //added
//pickupBall.whenPressed(new PickupArmDown()); //added
highShot.whenPressed(new HighShot());
lobShot.whenPressed(new LobShot());
highShot.whileHeld(new HighShot());
highShot.whenReleased(new PickupArmDown());
lobShot.whileHeld(new LobShot());
lobShot.whenReleased(new PickupArmDown());
lowerArm.whenPressed(new PickupArmDown());
raiseArm.whenPressed(new PickupArmUp());
pickupBall.whenPressed(new PickupArmDown());
Expand Down
11 changes: 10 additions & 1 deletion src/org/team484/fluffy/Robot.java
Expand Up @@ -16,11 +16,13 @@
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import org.team484.fluffy.commands.Autonomous;
import org.team484.fluffy.commands.Autonomous2;
import org.team484.fluffy.commands.CommandBase;

public class Robot extends IterativeRobot {

Command autonomousCommand;
Command autonomous2Command;
Compressor compressor;
protected DriverStation ds;
Relay LEDs;
Expand Down Expand Up @@ -49,13 +51,18 @@ public void robotInit() {
}
camLED.set(Relay.Value.kReverse);
autonomousCommand = new Autonomous();
autonomous2Command = new Autonomous2();
CommandBase.init();
compressor = new Compressor(RobotMap.pressureSwitch, RobotMap.compressorRelay);
compressor.start();
}

public void autonomousInit() {
autonomousCommand.start();
if (ds.getDigitalIn(1)) {
autonomousCommand.start();
} else {
autonomous2Command.start();
}
if (ds.getAlliance().value == 0) {
//Red Team
System.out.println("Go Red!");
Expand All @@ -78,6 +85,8 @@ public void autonomousPeriodic() {
}

public void teleopInit() {
autonomous2Command.cancel();
autonomousCommand.cancel();
if (ds.getAlliance().value == 0) {
//Red Team
System.out.println("Go Red!");
Expand Down
8 changes: 4 additions & 4 deletions src/org/team484/fluffy/commands/Autonomous2.java
Expand Up @@ -20,17 +20,17 @@ public Autonomous2() {
addSequential(new DriveForTime(), 1.6);
addSequential(new WaitCommand(0.5), 0.5);
addSequential(new ShooterUp(), 1);
addSequential(new SetStartAuto());
addParallel(new ShooterDown());
addSequential(new DriveForTimeBack(), 1.6);
addSequential(new FindAndPickupAuto(), 1.9);
addSequential(new SetStartAuto());
addParallel(new PickupWheelOn());
addSequential(new FollowBall(), 1.9);
addParallel(new PickupWheelOn());
addSequential(new KickerChecked(), 0.3);
addParallel (new KickerIn());
addParallel(new PickupWheelOff());
addSequential(new DriveForTime(), 1.6);
addSequential(new DriveForTime(), 1.7);
addSequential(new WaitCommand(0.5), 0.5);
addSequential(new SetShootBall(), 0.05);
addSequential(new ShooterUp(), 1);
addParallel(new ShooterDown());
}
Expand Down
4 changes: 2 additions & 2 deletions src/org/team484/fluffy/commands/FindAndPickup.java
Expand Up @@ -33,8 +33,8 @@ public FindAndPickup() {
addSequential(new ZeroGyro(), 0.1);
addParallel(new PickupArmDown());
addParallel(new PickupWheelOn());
addSequential(new WaitCommand(0.8), 0.8);
addSequential(new FollowBall());
//addSequential(new WaitCommand(0.8), 0.8);
addSequential(new FollowBallTele());
addParallel(new PickupWheelOn());
addSequential (new WaitCommand(0.5), 0.5);
addSequential(new KickerChecked(), 0.3);
Expand Down
41 changes: 41 additions & 0 deletions src/org/team484/fluffy/commands/FollowBallTele.java
@@ -0,0 +1,41 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.team484.fluffy.commands;

/**
*
* @author Team484
*/
public class FollowBallTele extends CommandBase {

public FollowBallTele() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(drivetrain);
}

// Called just before this Command runs the first time
protected void initialize() {
}

// Called repeatedly when this Command is scheduled to run
protected void execute() {
drivetrain.followBallTele();
}

// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return false;
}

// Called once after isFinished returns true
protected void end() {
}

// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
}
}
2 changes: 1 addition & 1 deletion src/org/team484/fluffy/commands/LobShot.java
Expand Up @@ -32,7 +32,7 @@ public LobShot() {
}
addSequential(new SetShootBall(), 0.1);
addSequential(new ShooterUp(), 0.29);
addSequential(new ShooterDown(), 0.1);
addParallel(new ShooterDown());
//addSequential(new WaitCommand(1), 1);
//addSequential(new PickupArmUp(), 0.1);
}
Expand Down
36 changes: 35 additions & 1 deletion src/org/team484/fluffy/subsystems/DriveTrain.java
Expand Up @@ -133,7 +133,7 @@ public void followBall() {
double leftIn = (MathUtils.pow(currentLeft, -1.22)*6627);
double rightIn = (MathUtils.pow(currentRight, -1.22)*6627);
System.out.println("Left: " + leftIn + " Right: " + rightIn);
if ((leftIn < 40 || rightIn < 40) && SmartDashboard.getBoolean("No Ball", true)) {
if ((leftIn < 32 || rightIn < 32) && SmartDashboard.getBoolean("No Ball", true)) {
double mech = MathUtils.log(Math.abs(leftIn - rightIn)) / 20;
if (leftIn - rightIn < 0) {
mech = 0 - mech;
Expand All @@ -157,6 +157,40 @@ public void followBall() {
robotDrive.mecanumDrive_Cartesian(mech, speed, rotation, 0);
}
}
public void followBallTele() {
double rotation = -(gyro.getAngle() / 160);
double speed = 0;
int currentLeft = leftIR.getValue();
int currentRight = rightIR.getValue();
double leftIn = (MathUtils.pow(currentLeft, -1.22)*6627);
double rightIn = (MathUtils.pow(currentRight, -1.22)*6627);
System.out.println("Left: " + leftIn + " Right: " + rightIn);
if ((leftIn < 38 || rightIn < 38) && SmartDashboard.getBoolean("No Ball", true)) {
double mech = MathUtils.log(Math.abs(leftIn - rightIn)) / 20;
if (leftIn - rightIn < 0) {
mech = 0 - mech;
}
if (mech > 0.5) {
mech = 0.5;
} else if (mech < -0.5) {
mech = -0.5;
} else if (mech > -0.1 && mech < 0) {
mech = 0;
} else if (mech > 0 && mech < 0.1) {
mech = 0;
}
if (leftIn < rightIn && leftIn > 12) {
speed = (leftIn - 12) / 20;
} else if (leftIn > rightIn && rightIn > 12) {
speed = (rightIn - 12) / 20;
} else {
speed = 0;
}
robotDrive.mecanumDrive_Cartesian(mech, speed, rotation, 0);
} else {
robotDrive.mecanumDrive_Cartesian(0, driveStick.getY(), driveStick.getX(), 0);
}
}
public void mechanumDrive(double x, double y, double rotation, boolean autonomous, boolean mechanum) {
if (mechanum && !this.wasMech) {
this.wasMech = true;
Expand Down

0 comments on commit 6b4bc77

Please sign in to comment.