Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions src/main/java/frc/robot/classes/Kinematics.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public Kinematics(Position2D startingPosition) {
m_previousRightEncoderPosition = 0;
}

// This function runs the kinematics caluclation,
// This function runs the kinematics calculation,
// given the delta Psi to use instead fo calculating from encoders
public void calculatePosition(double leftEncoderPostion, double rightEncoderPosition, double heading) {
public void calculatePosition(double leftEncoderPosition, double rightEncoderPosition, double heading) {
double currentHeading = 0.0d;

updateCurrentPose(leftEncoderPostion, rightEncoderPosition);
updateCurrentPose(leftEncoderPosition, rightEncoderPosition);

// Limit psi between Pi and -Pi
currentHeading = limitRadians(heading);
Expand All @@ -28,13 +28,13 @@ public void calculatePosition(double leftEncoderPostion, double rightEncoderPosi
m_currentPose.setHeadingRadians(currentHeading);
}

// This function runs the kinematics caluclation,
// This function runs the kinematics calculation,
// calculating delta Psi based off of encoder distance traveled
public void calculatePosition(double leftEncoderPostion, double rightEncoderPosition) {
updateCurrentPose(leftEncoderPostion, rightEncoderPosition);
public void calculatePosition(double leftEncoderPosition, double rightEncoderPosition) {
updateCurrentPose(leftEncoderPosition, rightEncoderPosition);
}

private void updateCurrentPose(double leftEncoderPostion, double rightEncoderPosition) {
private void updateCurrentPose(double leftEncoderPosition, double rightEncoderPosition) {
double deltaLeft = 0.0d;
double deltaRight = 0.0d;
double deltaX = 0.0d;
Expand All @@ -43,11 +43,11 @@ private void updateCurrentPose(double leftEncoderPostion, double rightEncoderPos
double newPsi = 0.0d;

// Calculate distance traveled
deltaLeft = (leftEncoderPostion - m_previousLeftEncoderPosition);
deltaLeft = (leftEncoderPosition - m_previousLeftEncoderPosition);
deltaRight = (rightEncoderPosition - m_previousRightEncoderPosition);

// Save distance traveled
m_previousLeftEncoderPosition = leftEncoderPostion;
m_previousLeftEncoderPosition = leftEncoderPosition;
m_previousRightEncoderPosition = rightEncoderPosition;

// Use encoders to calculate heading
Expand All @@ -58,7 +58,7 @@ private void updateCurrentPose(double leftEncoderPostion, double rightEncoderPos
deltaPsi = limitRadians(deltaPsi);
newPsi = limitRadians(m_currentPose.getHeadingRadians() + deltaPsi);

// Calcualte new X, Y
// Calculate new X, Y
deltaX = ((deltaLeft + deltaRight) / 2) * Math.cos(m_currentPose.getHeadingRadians()); // previous heading is in
// radians
deltaY = ((deltaLeft + deltaRight) / 2) * Math.sin(m_currentPose.getHeadingRadians()); // previous heading is in
Expand Down Expand Up @@ -98,17 +98,11 @@ public double distanceFromPose(Position2D checkpoint) {
double y1 = m_currentPose.getY();
double x2 = checkpoint.getX();
double y2 = checkpoint.getY();
double distance = Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));

return distance;
return Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));
Comment thread
PillageDev marked this conversation as resolved.
Outdated
}

public boolean atPose(Position2D checkpoint, double threshold) {
double distanceFromPose = distanceFromPose(checkpoint);
if (distanceFromPose <= threshold) {
return true;
} else {
return false;
}
return distanceFromPose <= threshold;
Comment thread
PillageDev marked this conversation as resolved.
Outdated
}
}
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/classes/SmoothControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public SmoothControl() {
}

// Modification of equation 13, Calculates the omegaDesired (in radians)
// modified by velocity aggressivness given required turn rate
// modified by velocity aggressiveness given required turn rate
public double computeTurnRate(Position2D currentPose, Position2D targetPose, double givenMaxVelocity, boolean inReverse) {
double omegaDesired = 0.0d;
double poseHeading = currentPose.getHeadingRadians(); // Convert heading to radians
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/frc/robot/commands/AutoBalance.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class AutoBalance extends CommandBase {
private static final double PITCH_OFFSET = -73.0d;
private static final int BALANCE_THRESHOLD = 4;
private static final int BALANCE_ITERATIONS = 20;
private static final double INTERGRAL_LIMIT = 5;
private static final double INTEGRAL_LIMIT = 5;

private double m_pitch;
private double m_error = 0.0d;
Expand All @@ -21,7 +21,7 @@ public class AutoBalance extends CommandBase {

// start (gives throttle) (may make it overshoot if too high)
private double m_P = 0.0031d;
// finicky (depends on situation) (within 5 to 3 degress of error)
// finicky (depends on situation) (within 5 to 3 degrees of error)
private double m_I = 0.00d;
// good rule of thumb for d: m_d = m_p * 10
private double m_D = 0.04;
Expand Down Expand Up @@ -92,7 +92,7 @@ public void execute() {

m_change = m_error - m_lastError;

if (Math.abs(m_errorIntegral) < INTERGRAL_LIMIT) {
if (Math.abs(m_errorIntegral) < INTEGRAL_LIMIT) {
// Accumulate the error into the integral
m_errorIntegral += m_error;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/frc/robot/commands/Rotate.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Rotate extends CommandBase {

private final Drivetrain m_drivetrain;
private double m_targetDegrees;
private double initalAngle;
private double initialAngle;
private double m_lastError = 0.0d;
private double m_errorIntegral = 0.0d;
private double m_error;
Expand All @@ -20,7 +20,7 @@ public class Rotate extends CommandBase {
public Rotate(Drivetrain drivetrain, double targetDegrees) {
m_drivetrain = drivetrain;
m_targetDegrees = targetDegrees;
initalAngle = m_drivetrain.getGyroYawDegrees();
initialAngle = m_drivetrain.getGyroYawDegrees();

addRequirements(m_drivetrain);
}
Expand All @@ -36,7 +36,7 @@ public void initialize() {
@Override
public void execute() {
double percentOutput = 0.0d;
m_error = Math.abs(m_drivetrain.getGyroYawDegrees() - Math.abs(initalAngle - m_targetDegrees));
m_error = Math.abs(m_drivetrain.getGyroYawDegrees() - Math.abs(initialAngle - m_targetDegrees));

m_change = m_error - m_lastError;

Expand Down
26 changes: 12 additions & 14 deletions src/main/java/frc/robot/subsystems/Arm.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public class Arm extends SubsystemBase {
public static final double EXTENDER_CALIBRATION_MOTOR_SPEED = 0.1d;

/* Conversion Factors */
public static final double ENCODER_UNITS_PER_REVOLUTION = 2048.0d / 1.0d;
public static final double PIVOT_GEARBOX_MOTOR_TO_GEARBOX_ARM_RATIO = 36.00d / 1.0d;
public static final double ENCODER_UNITS_PER_REVOLUTION = 2048.0d;
public static final double PIVOT_GEARBOX_MOTOR_TO_GEARBOX_ARM_RATIO = 36.00d;
public static final double PIVOT_PULLEY_MOTOR_TO_PULLEY_ARM_RATIO = 72.0d / 36.0d;
public static final double EXTENDER_GEARBOX_MOTOR_TO_GEARBOX_ARM_RATIO = 4.0d / 1.0d;
public static final double EXTENDER_GEARBOX_MOTOR_TO_GEARBOX_ARM_RATIO = 4.0d;
Comment thread
PillageDev marked this conversation as resolved.
Outdated
public static final double EXTENDER_PULLEY_ROTATION_TO_INCHES = 3.75d; // One rotation of the final extender pulley
// moves
public static final double RADIANS_PER_REVOLUTION = 2 * Math.PI;
Expand All @@ -61,7 +61,7 @@ public class Arm extends SubsystemBase {
public static final double MIN_INCHES = 35.112d;
public static final double MAX_INCHES = 50.0d;

public static final double ARM_THETA_DELTA_MODIFIER = 1.0d * ((2 * Math.PI) / 360.0d); // radians
Comment thread
PillageDev marked this conversation as resolved.
public static final double ARM_THETA_DELTA_MODIFIER = ((2 * Math.PI) / 360.0d); // radians
public static final double ARM_R_DELTA_MODIFIER = 0.75d; // inches

public static final double ZEROED_R_POSITION_RADIANS = 0.0d;
Expand Down Expand Up @@ -161,10 +161,10 @@ public void periodic() {
checkPivotCalibration();

/* Are we calibrated? */
if (false == isExtenderCalibrated) {
if (!isExtenderCalibrated) {
Comment thread
PillageDev marked this conversation as resolved.
Outdated
// The extender is not calibrated, start the extender calibration
extenderTalonFX.set(-EXTENDER_CALIBRATION_MOTOR_SPEED);
} else if (false == isPivotCalibrated) {
} else if (!isPivotCalibrated) {
Comment thread
PillageDev marked this conversation as resolved.
Outdated
// The extender is calibrated, but the pivot is not calibrated
// Double Check: Is extender is pulled in?
if (0 == extenderTalonFX.isRevLimitSwitchClosed()) {
Expand All @@ -174,7 +174,7 @@ public void periodic() {
pivotTalonFX.set(-PIVOT_CALIBRATION_MOTOR_SPEED);
}
} else {
// We are now calibrated and we know the position of the arm!
// We are now calibrated, and we know the position of the arm!
moveToPosition(theta, rInches);
}
}
Expand Down Expand Up @@ -209,13 +209,11 @@ public void rotateTo(double radians) {
* @return
*/
public double getPivotEncoderUnits() {
double encoderUnits = pivotTalonFX.getSelectedSensorPosition();
return encoderUnits;
return pivotTalonFX.getSelectedSensorPosition();
Comment thread
PillageDev marked this conversation as resolved.
Outdated
}

public double getExtenderEncoderUnits() {
double encoderUnits = extenderTalonFX.getSelectedSensorPosition();
return encoderUnits;
return extenderTalonFX.getSelectedSensorPosition();
Comment thread
PillageDev marked this conversation as resolved.
Outdated
}

/**
Expand Down Expand Up @@ -316,7 +314,7 @@ public void invalidateExtenderCalibration() {
*/
private void checkExtenderCalibration() {
// Do we need to check for calibration?
if (false == isExtenderCalibrated) {
if (!isExtenderCalibrated) {
Comment thread
PillageDev marked this conversation as resolved.
Outdated
// The extender is not calibrated! Check to see if it is now calibrated
// Is limit switch closed?
if (extenderTalonFX.isRevLimitSwitchClosed() == 1) {
Expand All @@ -341,7 +339,7 @@ private void checkExtenderCalibration() {
*/
private void checkPivotCalibration() {
// Do we need to check for calibration?
if (false == isPivotCalibrated) {
if (!isPivotCalibrated) {
Comment thread
PillageDev marked this conversation as resolved.
Outdated
// The pivot is not calibrated! Check to see if it is now calibrated
// Is limit switch closed?
if (pivotTalonFX.isRevLimitSwitchClosed() == 1) {
Expand All @@ -359,7 +357,7 @@ private void checkPivotCalibration() {
}

public boolean isCalibrated() {
return ((true == isPivotCalibrated) && (true == isExtenderCalibrated));
return ((isPivotCalibrated) && (isExtenderCalibrated));
Comment thread
PillageDev marked this conversation as resolved.
Outdated
}

public double getTheta() {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/frc/robot/subsystems/Drivetrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Drivetrain(Kinematics kinematics) {
leftTalonLead.clearStickyFaults();
rightTalonLead.clearStickyFaults();

// Set facotry defaults for onboard PID
// Set factory defaults for onboard PID
leftTalonLead.configFactoryDefault();
rightTalonLead.configFactoryDefault();

Expand Down Expand Up @@ -192,7 +192,7 @@ public void periodic() {
put("Kinematics Heading (degrees)", currentPose.getHeadingDegrees());
put("Left Encoder Velocity (Ft per S)", getLeftEncoderVelocity());
put("Left Encoder Position (Ft)", getLeftEncoderPosition());
put("Right Encoder Veloctiy (Ft per S)", getRightEncoderVelocity());
put("Right Encoder Velocity (Ft per S)", getRightEncoderVelocity());
put("Right Encoder Position (Ft)", getRightEncoderPosition());
put("Raw Left Encoder", leftTalonLead.getSelectedSensorPosition(0));
put("Raw Right Encoder", rightTalonLead.getSelectedSensorPosition(0));
Expand Down Expand Up @@ -320,7 +320,7 @@ public double getRightEncoderPosition() {
* @return left encoder Velocity in ft/s
*/
public double getLeftEncoderVelocity() {
// Returns the velocity of encoder by claculating the velocity from encoder
// Returns the velocity of encoder by calculating the velocity from encoder
// units of click/100ms to ft/s
return SPIKE293Utils.controllerVelocityToFeetPerSec(leftTalonLead.getSelectedSensorVelocity());
}
Expand All @@ -331,7 +331,7 @@ public double getLeftEncoderVelocity() {
* @return right encoder Velocity in ft/s
*/
public double getRightEncoderVelocity() {
// Returns the velocity of encoder by claculating the velocity from encoder
// Returns the velocity of encoder by calculating the velocity from encoder
// units of click/100ms to ft/s
return SPIKE293Utils.controllerVelocityToFeetPerSec(rightTalonLead.getSelectedSensorVelocity());
}
Expand All @@ -342,8 +342,8 @@ public double getRightEncoderVelocity() {
* @return robot Velocity in ft/s
*/
public double getRobotVelocity() {
// Returns the velocity of the robot by taking the averga of the velcity on both
// sides of the robor
// Returns the velocity of the robot by taking the average of the velocity on both
// sides of the robot
return (getLeftEncoderVelocity() + getRightEncoderVelocity()) / 2.0d;
}

Expand Down Expand Up @@ -398,7 +398,7 @@ public void resetGyro(double headingDegrees) {
setupGyro(navX, headingDegrees);
}

// rotates robot according to give degress using arc length formula
// rotates robot according to give degrees using arc length formula
public void rotateDegrees(double angle) {
double radians = Math.toRadians(angle);
double arcLength = (radians * (TRACK_WIDTH_FEET / 2.0));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/frc/robot/subsystems/Targeting.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Targeting() {
m_limeData.getEntry("ledMode").setNumber(LIMELIGHT_LED_ON);
m_limeData.getEntry("pipeline").setNumber(1.0d);

SmartDashboard.putBoolean("isTargetted", false);
SmartDashboard.putBoolean("isTargeted", false);

controlLight(true);
}
Expand All @@ -55,7 +55,7 @@ public Targeting() {
public void periodic() {
SmartDashboard.putNumber("Tx", m_targetX.getDouble(10000));
SmartDashboard.putNumber("Ty", m_targetY.getDouble(10000));
SmartDashboard.putBoolean("isTargetted", isTargeted());
SmartDashboard.putBoolean("isTargeted", isTargeted());
SmartDashboard.putNumber("Distance from Target", calcDistance());
}

Expand All @@ -76,7 +76,7 @@ public double calcShooterRPM() {
double retval = DEFAULT_TARGET_RPM;
double ty = m_targetY.getDouble(0.0);
if (m_tAcquired.getDouble(0.0) == TARGET_ACQUIRED) {
//retv al = (-30.07 * ty) + 1690.42;
//retval = (-30.07 * ty) + 1690.42;
Comment thread
PillageDev marked this conversation as resolved.
Outdated
retval = (230 * Math.pow(Math.E, ((-0.237 * ty) - 1.5))) + 1680.48;
if(retval > 2900.0){
retval = 2900.0;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/subsystems/WriteToCSV.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public WriteToCSV() {
//Check if file exists
File tempFile = new File(String.format("%s%s.csv", path, filename));

if(true == tempFile.exists())
if(tempFile.exists())
Comment thread
NathanEdg marked this conversation as resolved.
Outdated
{
filename = "match_data-b";
}
Expand Down