-
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 comments. Added tunable steer compensation to autonomous
- Loading branch information
1 parent
51d4ccf
commit c52fe34
Showing
14 changed files
with
222 additions
and
151 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,5 @@ protected void end() { | |
// subsystems is scheduled to run | ||
protected void interrupted() { | ||
} | ||
|
||
} |
123 changes: 71 additions & 52 deletions
123
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 |
---|---|---|
@@ -1,69 +1,88 @@ | ||
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; | ||
|
||
/** | ||
* | ||
* Autonomously accelerates/decelerates the robot to a target speed from a | ||
* starting speed. | ||
*/ | ||
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() { | ||
} | ||
|
||
|
||
/** | ||
* | ||
* @param percentPerSecond | ||
* The % speed to accelerate by per second. A value of 1 will | ||
* accelerate the robot from a standstill to full speed in one | ||
* second. | ||
* @param startPercent | ||
* The initial speed (between -1.0 and 1.0) of the robot. | ||
* @param targetPercent | ||
* The speed (between -1.0 and 1.0) to accelerate to. | ||
*/ | ||
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 based on time passed | ||
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; | ||
|
||
// Set drive speed | ||
Robot.DRIVETRAIN.arcadeDrive(percent, RobotMap.AUTO_BLIND_STEER); | ||
} | ||
|
||
// 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() { | ||
} | ||
|
||
} |
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
66 changes: 39 additions & 27 deletions
66
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 |
---|---|---|
@@ -1,39 +1,51 @@ | ||
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.TimedCommand; | ||
|
||
/** | ||
* | ||
* Drives the robot forward autonomously without sensor input. Drives at a | ||
* certain speed for a certain time. | ||
* | ||
* This should be used only in conjunction with AutoBlindAccelerate to get up to | ||
* speed. If the robot does not accelerate first, it may jerk and tip over. | ||
*/ | ||
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() { | ||
} | ||
|
||
|
||
/** | ||
* | ||
* @param time | ||
* The number of seconds to drive forward for. | ||
* @param percent | ||
* The percent output, or speed (between -1.0 and 1.0) to drive at. | ||
*/ | ||
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, RobotMap.AUTO_BLIND_STEER); | ||
} | ||
|
||
// 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() { | ||
} | ||
|
||
} |
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
Oops, something went wrong.