This repository has been archived by the owner on Oct 25, 2021. It is now read-only.
-
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 drive distance command * added pid control to drive distance auto * finished driveDistance command * created TurnToAngle auto command. * added groups to auto call. * changed angle kP value. Co-authored-by: PJ Reiniger <[email protected]>
- Loading branch information
1 parent
db03517
commit d46cf97
Showing
5 changed files
with
135 additions
and
3 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
59 changes: 59 additions & 0 deletions
59
2020InfiniteRecharge/src/main/java/frc/robot/commands/autonomous/DriveDistance.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,59 @@ | ||
package frc.robot.commands.autonomous; | ||
|
||
import edu.wpi.first.wpilibj2.command.CommandBase; | ||
import frc.robot.subsystems.Chassis; | ||
|
||
public class DriveDistance extends CommandBase { | ||
|
||
Chassis chassis; | ||
|
||
private double m_distance; | ||
private double m_allowableError; | ||
private double m_error; | ||
|
||
private double AUTO_KP = 0.1; | ||
|
||
public DriveDistance(Chassis chassis, double distance, double allowableError) { | ||
// Use requires() here to declare subsystem dependencies | ||
//super.addRequirements(Shooter); When a subsystem is written, add the requires line back in. | ||
this.chassis = chassis; | ||
|
||
m_distance = distance + chassis.getAverageEncoderDistance(); | ||
m_allowableError = allowableError; | ||
} | ||
|
||
public void initialize(){ | ||
} | ||
|
||
// Called repeatedly when this Command is scheduled to run | ||
public void execute() { | ||
double currentDistance; | ||
|
||
currentDistance = chassis.getAverageEncoderDistance(); | ||
|
||
m_error = m_distance - currentDistance; | ||
|
||
double speed = m_error * AUTO_KP; | ||
|
||
chassis.setSpeed(speed); | ||
|
||
//System.out.println("error:" + m_error + "speed:" + speed); | ||
} | ||
|
||
// Make this return true when this Command no longer needs to run execute() | ||
public boolean isFinished() { | ||
if(Math.abs(m_error) < m_allowableError){ | ||
System.out.println("Done!"); | ||
return true; | ||
} | ||
else { | ||
System.out.println("drive to distance" + "error:" + m_error + "allowableError" + m_allowableError); | ||
return false; | ||
} | ||
} | ||
|
||
// Called once after isFinished returns true | ||
public void end(boolean interrupted) { | ||
chassis.setSpeed(0); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
2020InfiniteRecharge/src/main/java/frc/robot/commands/autonomous/TurnToAngle.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,59 @@ | ||
package frc.robot.commands.autonomous; | ||
|
||
import edu.wpi.first.wpilibj2.command.CommandBase; | ||
import frc.robot.subsystems.Chassis; | ||
|
||
public class TurnToAngle extends CommandBase { | ||
|
||
Chassis chassis; | ||
|
||
private double m_angle; | ||
private double m_allowableError; | ||
private double m_error; | ||
|
||
private double AUTO_KP = 0.05; | ||
|
||
public TurnToAngle(Chassis chassis, double angle, double allowableError) { | ||
// Use requires() here to declare subsystem dependencies | ||
//super.addRequirements(Shooter); When a subsystem is written, add the requires line back in. | ||
this.chassis = chassis; | ||
|
||
m_angle = angle + chassis.getHeading(); | ||
m_allowableError = allowableError; | ||
} | ||
|
||
public void initialize(){ | ||
} | ||
|
||
// Called repeatedly when this Command is scheduled to run | ||
public void execute() { | ||
double currentAngle; | ||
|
||
currentAngle = chassis.getHeading(); | ||
|
||
m_error = m_angle - currentAngle; | ||
|
||
double turnSpeed = m_error * AUTO_KP; | ||
|
||
chassis.setSpeedAndSteer(0, turnSpeed); | ||
|
||
//System.out.println("error:" + m_error + "speed:" + speed); | ||
} | ||
|
||
// Make this return true when this Command no longer needs to run execute() | ||
public boolean isFinished() { | ||
if(Math.abs(m_error) < m_allowableError){ | ||
System.out.println("Done!"); | ||
return true; | ||
} | ||
else { | ||
System.out.println("Turn to angle" + "error:" + m_error + "allowableError" + m_allowableError); | ||
return false; | ||
} | ||
} | ||
|
||
// Called once after isFinished returns true | ||
public void end(boolean interrupted) { | ||
chassis.setSpeed(0); | ||
} | ||
} |