-
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.
Added acceleration ramp to auto drive
- Loading branch information
1 parent
302f293
commit 8ebb57e
Showing
4 changed files
with
136 additions
and
35 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
69 changes: 69 additions & 0 deletions
69
src/org/usfirst/frc/team4737/robot/commands/drivetrain/AutoBlindAccelerate.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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.usfirst.frc.team4737.robot.commands.drivetrain; | ||
|
||
import org.usfirst.frc.team4737.robot.Robot; | ||
|
||
import edu.wpi.first.wpilibj.command.Command; | ||
|
||
/** | ||
* | ||
*/ | ||
public class AutoBlindAccelerate extends Command { | ||
|
||
private double percentPerSecond; | ||
private double startPercent; | ||
private double targetPercent; | ||
|
||
private boolean startLow; | ||
|
||
private double lastTime; | ||
private double percent; | ||
|
||
public AutoBlindAccelerate(double percentPerSecond, double startPercent, double targetPercent) { | ||
requires(Robot.DRIVETRAIN); | ||
this.percentPerSecond = percentPerSecond; | ||
this.startPercent = startPercent; | ||
this.targetPercent = targetPercent; | ||
} | ||
|
||
// Called just before this Command runs the first time | ||
protected void initialize() { | ||
lastTime = 0; | ||
percent = startPercent; | ||
startLow = startPercent < targetPercent; | ||
} | ||
|
||
// Called repeatedly when this Command is scheduled to run | ||
protected void execute() { | ||
double time = this.timeSinceInitialized(); | ||
double delta = time - lastTime; | ||
lastTime = time; | ||
|
||
// Adjust speed | ||
if (startLow) percent += percentPerSecond * delta; | ||
else percent -= percentPerSecond * delta; | ||
|
||
// Check bounds | ||
if (startLow && percent > targetPercent) percent = targetPercent; | ||
if (!startLow && percent < targetPercent) percent = targetPercent; | ||
if (percent < -1) percent = -1; | ||
if (percent > 1) percent = 1; | ||
|
||
// Apply speed | ||
Robot.DRIVETRAIN.arcadeDrive(percent, 0); | ||
} | ||
|
||
// Make this return true when this Command no longer needs to run execute() | ||
protected boolean isFinished() { | ||
return percent == targetPercent; | ||
} | ||
|
||
// 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() { | ||
} | ||
|
||
} |
60 changes: 26 additions & 34 deletions
60
src/org/usfirst/frc/team4737/robot/commands/drivetrain/AutoBlindBaseline.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,43 +1,35 @@ | ||
package org.usfirst.frc.team4737.robot.commands.drivetrain; | ||
|
||
import org.usfirst.frc.team4737.robot.Robot; | ||
import org.usfirst.frc.team4737.robot.RobotMap; | ||
|
||
import edu.wpi.first.wpilibj.command.Command; | ||
import edu.wpi.first.wpilibj.command.CommandGroup; | ||
|
||
/** | ||
* | ||
*/ | ||
public class AutoBlindBaseline extends Command { | ||
|
||
public AutoBlindBaseline() { | ||
requires(Robot.DRIVETRAIN); | ||
} | ||
|
||
// Called just before this Command runs the first time | ||
protected void initialize() { | ||
Robot.DRIVETRAIN.setBrakeMode(); | ||
} | ||
|
||
// Called repeatedly when this Command is scheduled to run | ||
protected void execute() { | ||
Robot.DRIVETRAIN.arcadeDrive(RobotMap.AUTO_BLIND_SPEED, 0); | ||
} | ||
|
||
// Make this return true when this Command no longer needs to run execute() | ||
protected boolean isFinished() { | ||
return this.timeSinceInitialized() > RobotMap.AUTO_BLIND_TIME; | ||
} | ||
|
||
// Called once after isFinished returns true | ||
protected void end() { | ||
Robot.DRIVETRAIN.arcadeDrive(0, 0); | ||
} | ||
|
||
// Called when another command which requires one or more of the same | ||
// subsystems is scheduled to run | ||
protected void interrupted() { | ||
this.end(); | ||
} | ||
|
||
public class AutoBlindBaseline extends CommandGroup { | ||
|
||
public AutoBlindBaseline() { | ||
// Add Commands here: | ||
// e.g. addSequential(new Command1()); | ||
// addSequential(new Command2()); | ||
// these will run in order. | ||
|
||
// To run multiple commands at the same time, | ||
// use addParallel() | ||
// e.g. addParallel(new Command1()); | ||
// addSequential(new Command2()); | ||
// Command1 and Command2 will run in parallel. | ||
|
||
// A command group will require all of the subsystems that each member | ||
// would require. | ||
// e.g. if Command1 requires chassis, and Command2 requires arm, | ||
// a CommandGroup containing them would require both the chassis and the | ||
// arm. | ||
|
||
addSequential(new AutoBlindAccelerate(0.1, 0, RobotMap.AUTO_BLIND_SPEED)); | ||
addSequential(new AutoBlindDrive(RobotMap.AUTO_BLIND_TIME, RobotMap.AUTO_BLIND_SPEED)); | ||
addSequential(new AutoBlindAccelerate(0.1, RobotMap.AUTO_BLIND_SPEED, 0)); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/org/usfirst/frc/team4737/robot/commands/drivetrain/AutoBlindDrive.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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.usfirst.frc.team4737.robot.commands.drivetrain; | ||
|
||
import org.usfirst.frc.team4737.robot.Robot; | ||
|
||
import edu.wpi.first.wpilibj.command.TimedCommand; | ||
|
||
/** | ||
* | ||
*/ | ||
public class AutoBlindDrive extends TimedCommand { | ||
|
||
private double percent; | ||
|
||
public AutoBlindDrive(double time, double percent) { | ||
super(time); | ||
requires(Robot.DRIVETRAIN); | ||
|
||
this.percent = percent; | ||
} | ||
|
||
// Called just before this Command runs the first time | ||
protected void initialize() { | ||
} | ||
|
||
// Called repeatedly when this Command is scheduled to run | ||
protected void execute() { | ||
Robot.DRIVETRAIN.arcadeDrive(percent, 0); | ||
} | ||
|
||
// 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() { | ||
} | ||
|
||
} |