Skip to content

Commit

Permalink
Chezy Day 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
cttdev committed Oct 30, 2021
1 parent eca2b95 commit 0f50d65
Show file tree
Hide file tree
Showing 15 changed files with 4,262 additions and 22 deletions.
636 changes: 636 additions & 0 deletions src/com/_604robotics/deploy/05_ball_b.csv

Large diffs are not rendered by default.

516 changes: 516 additions & 0 deletions src/com/_604robotics/deploy/06_ball_b.csv

Large diffs are not rendered by default.

790 changes: 790 additions & 0 deletions src/com/_604robotics/deploy/08_ball_b.csv

Large diffs are not rendered by default.

577 changes: 577 additions & 0 deletions src/com/_604robotics/deploy/10_ball_b.csv

Large diffs are not rendered by default.

844 changes: 844 additions & 0 deletions src/com/_604robotics/deploy/11_ball_b.csv

Large diffs are not rendered by default.

753 changes: 753 additions & 0 deletions src/com/_604robotics/deploy/13_ball_b.csv

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/com/_604robotics/robot2020/Robot2020.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ private Robot2020() {

public final Shooter shooter = addModule(new Shooter());

public final Climber climber = addModule(new Climber());

public final Swerve drive = addModule(new Swerve());

public final Limelight limelight = addModule(new Limelight(
Expand Down
5 changes: 2 additions & 3 deletions src/com/_604robotics/robot2020/constants/Calibration.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public class Calibration {

/* Climber Calibration */
public static final class Climber {
public static final double CLIMB_SPEED = -0.25;
public static final double RETRACT_SPEED = 0.25;
public static final double CLIMB_SPEED = 0.5;
}

/* Tower Calibration */
Expand All @@ -32,7 +31,7 @@ public static final class Tower {
/* Revolver Calibration */
public static final class Revolver {
// public static final double EMPTY_SPEED = 0.75;
public static final double EMPTY_SPEED = 0.4;
public static final double EMPTY_SPEED = 0.6;
public static final double INTAKE_SPEED = 0.5;
public static final double REVERSE_SPEED = -0.5;
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/_604robotics/robot2020/constants/Ports.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Ports {
public static final int MODULE_3_ABS_ENCODER = 3;

/* Climber */
public static final int CLIMBER_MOTOR = 4;
public static final int CLIMBER_MOTOR = 16;

/* Shifter */
public static final int SHIFTER_A = 4;
Expand Down
4 changes: 4 additions & 0 deletions src/com/_604robotics/robot2020/modes/AutonomousMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public AutonomousMode(Robot2020 robot) {
public void begin() {
System.out.println(autonMode.get());

reader.loadChosenFile();

robot.drive.zeroGyroOffset();

switch (autonMode.get()) {
case MANUAL:
selectedModeMacro = robot.teleopMode;
Expand Down
30 changes: 24 additions & 6 deletions src/com/_604robotics/robot2020/modes/TeleopMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class TeleopMode extends Coordinator {
private boolean autoCentering = false;
private boolean aligned = false;

private boolean climbMode = false;

private final Logger test = new Logger("Teleop");

public TeleopMode(com._604robotics.robot2020.Robot2020 robot) {
Expand Down Expand Up @@ -272,17 +274,35 @@ public void run() {
}

if (driverStart) {
robot.drive.zeroGyro();
climbMode = true;

if (driverBack) {
robot.climber.extend.activate();
} else if (driverRightBumper) {
robot.climber.climb.activate();
} else if (driverLeftBumper) {
robot.climber.retract.activate();
} else {
robot.climber.idle.activate();
}

} else {
climbMode = false;
robot.climber.idle.activate();
}

if (driverY || driverA || driverB || driverX) {
if (driverY || driverA || driverB) {
currentDrive = CurrentDrive.SNAPPING;
}

if (Math.abs(rightX) > 0.1) {
currentDrive = CurrentDrive.OPENLOOP;
}

if (driverX) {
robot.drive.zeroGyroOffset();
}

// // Get Dashboard option for drive
// switch (robot.drive.driveMode.get()) {
// case OFF:
Expand Down Expand Up @@ -337,8 +357,6 @@ public void run() {
snapTo(CardinalDirections.SOUTH);
} else if (driverB) {
snapTo(CardinalDirections.EAST);
} else if (driverX) {
snapTo(CardinalDirections.WEST);
}

autoAngle.activate();
Expand Down Expand Up @@ -422,7 +440,7 @@ public void run() {
revolve.activate();
roller.activate();
antiJam.activate();
} else if (driverLeftBumper) {
} else if (driverLeftBumper && !climbMode) {
reverseIntake.activate();
reverseRevolver.activate();
reverseRoller.activate();
Expand Down Expand Up @@ -481,7 +499,7 @@ public void run() {
stop.activate();
}

if (driverRightBumper) {
if (driverRightBumper && !climbMode) {
emptyTower.activate();
emptyRevolver.activate();
roller.activate();
Expand Down
93 changes: 93 additions & 0 deletions src/com/_604robotics/robot2020/modules/Climber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com._604robotics.robot2020.modules;

import com._604robotics.robot2020.constants.Calibration;
import com._604robotics.robot2020.constants.Ports;
import com._604robotics.robotnik.Action;
import com._604robotics.robotnik.Module;
import com._604robotics.robotnik.Output;
import com._604robotics.robotnik.prefabs.devices.NEOEncoder;
import com._604robotics.robotnik.prefabs.motorcontrol.Motor;
import com._604robotics.robotnik.prefabs.motorcontrol.QuixSparkMAX;
import com._604robotics.robotnik.prefabs.motorcontrol.controllers.MotorControllerPIDConfig;
import com._604robotics.robotnik.prefabs.motorcontrol.controllers.SparkPID;
import com.revrobotics.CANSparkMax.IdleMode;
import com.revrobotics.CANSparkMax.SoftLimitDirection;
import com.revrobotics.CANSparkMaxLowLevel.PeriodicFrame;

public class Climber extends Module {
private QuixSparkMAX climbMotor = new QuixSparkMAX(Ports.CLIMBER_MOTOR, "Climber Motor", Motor.kNEO, this);

private NEOEncoder climbEncoder = new NEOEncoder(climbMotor);
private SparkPID climbPID = new SparkPID(climbMotor, climbEncoder, new MotorControllerPIDConfig(0.03, 0, 0));

public final Output<Double> climbPosition = addOutput("Climb Position", () -> climbEncoder.getPosition());

public Climber() {
super(Climber.class);
climbMotor.controller.getEncoder().setPosition(0.0);

climbMotor.controller.setIdleMode(IdleMode.kBrake);
climbMotor.controller.setSoftLimit(SoftLimitDirection.kForward, 365);

climbMotor.controller.setPeriodicFramePeriod(PeriodicFrame.kStatus1, 100);
climbMotor.controller.setPeriodicFramePeriod(PeriodicFrame.kStatus2, 100);

climbMotor.setCurrentLimit(60);

setDefaultAction(idle);
}

public class Idle extends Action {

public Idle() {
super(Climber.this, Idle.class);
}

@Override
public void run() {
climbMotor.set(0.0);
}
}

public class Extend extends Action {

public Extend() {
super(Climber.this, Extend.class);
}

@Override
public void begin() {
climbPID.setSetpointPosition(climbEncoder.getPosition() + 160);
}
}

public class Retract extends Action {

public Retract() {
super(Climber.this, Retract.class);
}

@Override
public void run() {
climbMotor.set(-0.25);
}
}

public class Climb extends Action {

public Climb() {
super(Climber.this, Climb.class);
}

@Override
public void run() {

climbMotor.set(Calibration.Climber.CLIMB_SPEED);
}
}

public Action idle = new Idle();
public Action extend = new Extend();
public Action retract = new Retract();
public Action climb = new Climb();
}
24 changes: 14 additions & 10 deletions src/com/_604robotics/robot2020/modules/Swerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,25 @@ public class Swerve extends Module {

public final Output<Double> gyroAngle = addOutput("gyroAngle", imu::getAngle);

// public final Output<Double> frontLeftAngle = addOutput("Front Left Angle", frontLeft::getAngle);
// public final Output<Double> frontRightAngle = addOutput("Front Right Angle", frontRight::getAngle);
// public final Output<Double> rearLeftAngle = addOutput("Rear Left Angle", rearLeft::getAngle);
// public final Output<Double> rearRightAngle = addOutput("Rear Right Angle", rearRight::getAngle);
public final Output<Double> frontLeftAngle = addOutput("Front Left Angle", frontLeft::getAngle);
public final Output<Double> frontRightAngle = addOutput("Front Right Angle", frontRight::getAngle);
public final Output<Double> rearLeftAngle = addOutput("Rear Left Angle", rearLeft::getAngle);
public final Output<Double> rearRightAngle = addOutput("Rear Right Angle", rearRight::getAngle);

// public final Output<Double> absfrontLeftAngle = addOutput("Abs Front Left Angle", frontLeft::getAbsEncoderAngle);
// public final Output<Double> absfrontRightAngle = addOutput("Abs Front Right Angle", frontRight::getAbsEncoderAngle);
// public final Output<Double> absrearLeftAngle = addOutput("Abs Rear Left Angle", rearLeft::getAbsEncoderAngle);
// public final Output<Double> absrearRightAngle = addOutput("Abs Rear Right Angle", rearRight::getAbsEncoderAngle);
public final Output<Double> absfrontLeftAngle = addOutput("Abs Front Left Angle", frontLeft::getAbsEncoderAngle);
public final Output<Double> absfrontRightAngle = addOutput("Abs Front Right Angle", frontRight::getAbsEncoderAngle);
public final Output<Double> absrearLeftAngle = addOutput("Abs Rear Left Angle", rearLeft::getAbsEncoderAngle);
public final Output<Double> absrearRightAngle = addOutput("Abs Rear Right Angle", rearRight::getAbsEncoderAngle);

public final Output<Double> robotHeading = addOutput("Robot Heading", this::getHeadingDegrees);
public final Output<Double> robotX = addOutput("Robot X Position", this::getX);
public final Output<Double> robotY = addOutput("Robot Y Position", this::getY);


private double gyroOffset = 0.0;

/* Auton Methods */
public Rotation2d getHeading() {
return (Calibration.Drive.GYRO_REVERSED) ? Rotation2d.fromDegrees(360 - imu.getAngle()) : Rotation2d.fromDegrees(imu.getAngle());
return (Calibration.Drive.GYRO_REVERSED) ? Rotation2d.fromDegrees(360 - (imu.getAngle() - gyroOffset)) : Rotation2d.fromDegrees((imu.getAngle() - gyroOffset));
// var angle = -imu.getAngle() * (Calibration.Drive.GYRO_REVERSED ? -1.0 : 1.0);
// return Rotation2d.fromDegrees(Math.IEEEremainder(angle, 360));
}
Expand Down Expand Up @@ -233,6 +233,10 @@ public void zeroGyro() {
imu.reset();
}

public void zeroGyroOffset() {
gyroOffset = imu.getAngle();
}

public void setModuleStates(boolean openLoop, QuixSwerveModuleState... desiredStates) {
QuixSwerveDriveKinematics.normalizeWheelSpeeds(desiredStates, Calibration.Drive.MAX_DRIVE_VELOCITY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.ctre.phoenix.sensors.AbsoluteSensorRange;
import com.ctre.phoenix.sensors.CANCoder;
import com.ctre.phoenix.sensors.CANCoderStatusFrame;
import com.ctre.phoenix.sensors.SensorInitializationStrategy;

public class QuixCANCoder implements BetterAbsoluteEncoder {
Expand All @@ -18,6 +19,9 @@ public QuixCANCoder(int port, String name) {
this.encoder.configFactoryDefault();
this.encoder.configAbsoluteSensorRange(AbsoluteSensorRange.Unsigned_0_to_360);
this.encoder.configSensorInitializationStrategy(SensorInitializationStrategy.BootToAbsolutePosition);

this.encoder.setStatusFramePeriod(CANCoderStatusFrame.SensorData, 50);
this.encoder.setStatusFramePeriod(CANCoderStatusFrame.VbatAndFaults, 100);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public QuixSwerveModule(
this.driveEncoder.setdistancePerRotation(this.driveRatio.calculate(Math.PI * wheelDiameter));
this.steeringEncoder.setdistancePerRotation(this.steeringRatio.calculate(360.0));

lastAngle = getState().angle.getDegrees();

zeroToAbsPosition();

lastAngle = getState().angle.getDegrees();
}

// public void setDesiredStateClosedLoop(QuixSwerveModuleState desiredState) {
Expand Down

0 comments on commit 0f50d65

Please sign in to comment.