Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…Code2024 into sofie-arm
  • Loading branch information
stwiggy committed Mar 3, 2024
2 parents f4b812c + 21f8ba9 commit e779bdb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 52 deletions.
76 changes: 40 additions & 36 deletions src/main/java/org/carlmontrobotics/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,63 +25,69 @@ public static final class Drivetrain {
}

public static final class Arm {

//ports
//config for motors (inverted, encoder offset, etc)
//goal positions
//feedforward, pid, trapezoid constants
//Boundaries (arm cannot go beyond certain angles)
//Controller buttons should go in OI not Arm

//Motor port
public static final int ARM_MOTOR_PORT_1 = 7;
public final static int ARM_MOTOR_PORT_2 = 8;

//config
//Config for motors
public static final boolean MOTOR_INVERTED = true; //Todo: find all these (they are definetely wrong)
public static final double ROTATION_TO_RAD = 2 * Math.PI;
public static final boolean ENCODER_INVERTED = false;
public static final double ARM_TELEOP_MAX_GOAL_DIFF_FROM_CURRENT_RAD = 0;
public static final double POS_TOLERANCE_RAD = 0;
public static final double VEL_TOLERANCE_RAD_P_SEC = 0;
public static final int MAX_VOLTAGE = 12;

//TODO: finish understand why this is broken public static final Measure<Angle> INTAKE_ANGLE = Degrees.to(-1);

//goal pos
// USE RADIANS FOR THE ARM
public static final double INTAKE_ANGLE = Units.degreesToRadians(0);
public static final double AMP_ANGLE = Units.degreesToRadians(103);
public static final double SPEAKER_ANGLE_1 = Units.degreesToRadians(24); //placeholder
public static final double SPEAKER_ANGLE_2 = Units.degreesToRadians(24); //placeholder
public static final double SPEAKER_ANGLE_3 = Units.degreesToRadians(24); //placeholder
public static final double AMP_ANGLE = Units.degreesToRadians(105);
public static final double SUBWOFFER_ANGLE = Units.degreesToRadians(24);
public static final double SAFE_ZONE_ANGLE = Units.degreesToRadians(24);
public static final double PODIUM_ANGLE = Units.degreesToRadians(24);
public static final double CLIMBER_UP_ANGLE = Units.degreesToRadians(24);
public static final double CLIMBER_DOWN_ANGLE = Units.degreesToRadians(24);

// Feedforward

//PID, Feedforward, Trapezoid
public static final double kP = 0.1;
public static final double kI = 0.1;
public static final double kD = 0.1;
public static final double kS = 0.1;
public static final double kG = 0.1;
public static final double kV = 0.1;
public static final double kA = 0.1;
public static final double IZONE = 4;

// PID Constants
public static final double kP = 0.1;
public static final double kI = 0.1;
public static final double kD = 0.1;
//I assume to max vel and accel are in meters per second

//trapezoidal
public static final double MAX_FF_VEL = 1; // rot / s
public static final double MAX_FF_ACCEL = 1; // rot / s^2
public static TrapezoidProfile.Constraints TRAP_CONSTRAINTS = new TrapezoidProfile.Constraints(MAX_FF_VEL, MAX_FF_ACCEL);
public static final int MAX_VOLTAGE = 12;
public static final double ROTATION_TO_RAD = 2 * Math.PI;


//boundaries
//if needed
public static final double UPPER_ANGLE_LIMIT = Units.degreesToRadians(70);
public static final double LOWER_ANGLE_LIMIT = Units.degreesToRadians(0);
public static final double ARM_DISCONT_RAD = (LOWER_ANGLE_LIMIT + UPPER_ANGLE_LIMIT) /2 - Math.PI;
public static TrapezoidProfile.Constraints TRAP_CONSTRAINTS = new TrapezoidProfile.Constraints(MAX_FF_VEL, MAX_FF_ACCEL);
//other0;

public static final double MARGIN_OF_ERROR = Math.PI/18;
public static final double ARM_LOWER_LIMIT_RAD = -3.569 + MARGIN_OF_ERROR;
public static final double ARM_UPPER_LIMIT_RAD = .36 - MARGIN_OF_ERROR;
public static final double ARM_TELEOP_MAX_GOAL_DIFF_FROM_CURRENT_RAD = 0;
public static final double ARM_DISCONTINUITY_RAD = (ARM_LOWER_LIMIT_RAD + ARM_UPPER_LIMIT_RAD) / 2 - Math.PI;
public static final double POS_TOLERANCE_RAD = 0;
public static final double VEL_TOLERANCE_RAD_PER_SEC = 0;

//TODO: finish understand why this is broken public static final Measure<Angle> INTAKE_ANGLE = Degrees.to(-1);

//Arm measurements - ALL OF THEM ARE PLACEHOLDERS THE NUMBERS MEAN NOTHING
public static final double COM_ARM_LENGTH_METERS = 0.381 ;
public static final double ARM_MASS_KG = 9.59302503;

//Arm buttons
public static final int RAISE_TO_SPEAKER_POD_BUTTON = Button.kY.value;
public static final int RAISE_TO_AMP_BUTTON = Button.kB.value;
public static final int RAISE_TO_SPEAKER_SAFE_ZONE_BUTTON = Button.kA.value;
public static final int RAISE_TO_SPEAKER_NEXT_BUTTON = Button.kX.value;
public static final int RAISE_TO_GROUND_BUTTON = Button.kStart.value;
public static final int RAISE_TO_CLIMBER_BUTTON = Button.kLeftBumper.value;
public static final int LOWER_TO_CLIMBER_BUTTON = Button.kRightBumper.value;
}

public static final class IntakeShooter {
Expand All @@ -99,15 +105,13 @@ public static final class Driver {
}
public static final class Manipulator {
public static final int port = 1;

//Arm buttons
public static final int RAISE_TO_SPEAKER_POD_BUTTON = Button.kY.value;
public static final int RAISE_TO_AMP_BUTTON = Button.kB.value;
public static final int RAISE_TO_AMP_BUTTON= Button.kB.value;
public static final int RAISE_TO_SPEAKER_SAFE_BUTTON = Button.kA.value;
public static final int RAISE_TO_SPEAKER_NEXT_BUTTON = Button.kX.value;
public static final int RAISE_TO_GROUND_BUTTON = Button.kStart.value;
public static final int RAISE_TO_GROUND_BUTTON= Button.kStart.value;
public static final int RAISE_TO_CLIMBER_BUTTON = Button.kLeftBumper.value;
public static final int LOWER_TO_CLIMER_BUTTON = Button.kRightBumper.value;
public static final int LOWER_TO_CLIMBER_BUTTON = Button.kRightBumper.value;
}
}
}
15 changes: 8 additions & 7 deletions src/main/java/org/carlmontrobotics/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// import org.carlmontrobotics.subsystems.*;
import org.carlmontrobotics.commands.*;
import static org.carlmontrobotics.Constants.OI;
import static org.carlmontrobotics.Constants.Arm.*;

import org.carlmontrobotics.Constants.OI;
import org.carlmontrobotics.subsystems.Arm;
Expand Down Expand Up @@ -71,15 +72,15 @@ private void setBindingsManipulator() {
//right joystick used for manual arm control

// Speaker Buttons
new JoystickButton(manipulatorController, Constants.OI.Manipulator.RAISE_TO_SPEAKER_POD_BUTTON).onTrue(new InstantCommand(() -> {arm.driveArm(Constants.Arm.SPEAKER_ANGLE_1);}));
new JoystickButton(manipulatorController, Constants.OI.Manipulator.RAISE_TO_SPEAKER_NEXT_BUTTON).onTrue(new InstantCommand(() -> {arm.driveArm(Constants.Arm.SPEAKER_ANGLE_2);}));
new JoystickButton(manipulatorController, Constants.OI.Manipulator.RAISE_TO_SPEAKER_SAFE_BUTTON).onTrue(new InstantCommand(() -> {arm.driveArm(Constants.Arm.SPEAKER_ANGLE_3);}));
new JoystickButton(manipulatorController, Constants.Arm.RAISE_TO_SPEAKER_POD_BUTTON).onTrue(new InstantCommand(() -> {arm.driveArm(Constants.Arm.PODIUM_ANGLE);}));
new JoystickButton(manipulatorController, Constants.Arm.RAISE_TO_SPEAKER_NEXT_BUTTON).onTrue(new InstantCommand(() -> {arm.driveArm(Constants.Arm.SUBWOFFER_ANGLE);}));
new JoystickButton(manipulatorController, Constants.Arm.RAISE_TO_SPEAKER_SAFE_ZONE_BUTTON).onTrue(new InstantCommand(() -> {arm.driveArm(Constants.Arm.SAFE_ZONE_ANGLE);}));
// Amp and Intake Buttons
new JoystickButton(manipulatorController, Constants.OI.Manipulator.RAISE_TO_AMP_BUTTON).onTrue(new InstantCommand(() -> {arm.driveArm(Constants.Arm.AMP_ANGLE);}));
new JoystickButton(manipulatorController, Constants.OI.Manipulator.RAISE_TO_GROUND_BUTTON).onTrue(new InstantCommand(() -> {arm.driveArm(Constants.Arm.INTAKE_ANGLE);}));
new JoystickButton(manipulatorController, Constants.Arm.RAISE_TO_AMP_BUTTON).onTrue(new InstantCommand(() -> {arm.driveArm(Constants.Arm.AMP_ANGLE);}));
new JoystickButton(manipulatorController, Constants.Arm.RAISE_TO_GROUND_BUTTON).onTrue(new InstantCommand(() -> {arm.driveArm(Constants.Arm.INTAKE_ANGLE);}));
// Cimber Buttons
new JoystickButton(manipulatorController, Constants.OI.Manipulator.RAISE_TO_CLIMBER_BUTTON).onTrue(new InstantCommand(() -> {arm.driveArm(Constants.Arm.CLIMBER_UP_ANGLE);}));
new JoystickButton(manipulatorController, Constants.OI.Manipulator.LOWER_TO_CLIMER_BUTTON).onTrue(new InstantCommand(() -> {arm.driveArm(Constants.Arm.CLIMBER_DOWN_ANGLE);}));
new JoystickButton(manipulatorController, Constants.Arm.RAISE_TO_CLIMBER_BUTTON).onTrue(new InstantCommand(() -> {arm.driveArm(Constants.Arm.CLIMBER_UP_ANGLE);}));
new JoystickButton(manipulatorController, Constants.Arm.LOWER_TO_CLIMBER_BUTTON).onTrue(new InstantCommand(() -> {arm.driveArm(Constants.Arm.CLIMBER_DOWN_ANGLE);}));
}

public Command getAutonomousCommand() {
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/org/carlmontrobotics/subsystems/Arm.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public Arm() {
// SmartDashboard.putNumber("Arm Max Vel", MAX_FF_VEL );
SmartDashboard.putNumber("ARM_TELEOP_MAX_GOAL_DIFF_FROM_CURRENT_RAD", ARM_TELEOP_MAX_GOAL_DIFF_FROM_CURRENT_RAD);
SmartDashboard.putNumber("Arm Tolerance Pos", POS_TOLERANCE_RAD);
SmartDashboard.putNumber("Arm Tolerance Vel", VEL_TOLERANCE_RAD_PER_SEC);
SmartDashboard.putNumber("Arm Tolerance Vel", VEL_TOLERANCE_RAD_P_SEC);
}

@Override
Expand All @@ -108,7 +108,7 @@ public void periodic() {

// SmartDashboard.putNumber("MaxHoldingTorque", maxHoldingTorqueNM());
//SmartDashboard.putNumber("V_PER_NM", getV_PER_NM());
SmartDashboard.putNumber("COMDistance", getCoM().getNorm());
// SmartDashboard.putNumber("COMDistance", getCoM().getNorm());
SmartDashboard.putNumber("InternalArmVelocity", armEncoder.getVelocity());
//SmartDashboard.putNumber("Arm Current", armMotor.getOutputCurrent());

Expand Down Expand Up @@ -202,13 +202,8 @@ public double getArmClampedGoal(double goal) {



public Translation2d getCoM() {
Translation2d comOfArm = new Translation2d(COM_ARM_LENGTH_METERS, Rotation2d.fromRadians(getArmPos()))
.times(ARM_MASS_KG);

return comOfArm.plus(comOfArm);
//this math is prob wront
}




}

0 comments on commit e779bdb

Please sign in to comment.