Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maya arm #13

Open
wants to merge 27 commits into
base: on-robot
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7ea49a3
maya-add-subsystem
maya1414 Jul 31, 2024
fe1cc4c
maya-add-final-to-motor
maya1414 Aug 4, 2024
7471280
maya and danna - added pid and move to angle
maya1414 Aug 4, 2024
d2b078c
merge on-robot
maya1414 Aug 7, 2024
eb16230
finish isAtAngle
maya1414 Aug 7, 2024
4338039
maya add roller elbow and wrist subsystems
maya1414 Aug 7, 2024
e4f4f9b
maya add to MoveToAngleWrist, MoveToSpeedRoller, MoveElbowToAngle com…
maya1414 Aug 11, 2024
78f4089
maya-change
maya1414 Aug 18, 2024
e19e438
maya-fix-after-CR
maya1414 Aug 18, 2024
6dfc768
add ElbowSimulation, work on Elbow, IElbow, add to SimulationElbowCon…
maya1414 Aug 18, 2024
5b1dd6a
maya- fixed according to CR
maya1414 Aug 20, 2024
3eeddbe
maya- fixed according to CR.. tolerance...
maya1414 Aug 20, 2024
0c12770
maya- fixed according to CR
maya1414 Aug 21, 2024
9fc7b1a
maya- fixed according to CR
maya1414 Aug 21, 2024
83bfcac
maya- add to ElbowFactory, ElbowNEO, ElbowSimulation, TrainingRobotMa…
maya1414 Aug 21, 2024
1ec631e
work on CR
maya1414 Aug 21, 2024
3b7a013
work on CR
maya1414 Aug 21, 2024
7763e14
maya- add PID...
maya1414 Aug 21, 2024
96fe322
maya- fixed according to CR
maya1414 Aug 21, 2024
8fd0df9
maya- work on CR
maya1414 Aug 21, 2024
0bf1b22
maya- work on CR
maya1414 Aug 23, 2024
1c4801c
maya- work on CR
maya1414 Aug 23, 2024
9d8ceac
maya- work on joystick
maya1414 Aug 23, 2024
a608f3a
maya- work on joystick
maya1414 Aug 23, 2024
ed50ad2
maya- work on CR
maya1414 Aug 23, 2024
c8560e2
maya- work on inputs
maya1414 Aug 23, 2024
fb80cc5
maya- work on CR
maya1414 Aug 23, 2024
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
32 changes: 32 additions & 0 deletions src/main/java/training/commands/elbow/MoveElbowToAngle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package training.commands.elbow;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj2.command.Command;
import training.subsystems.elbow.Elbow;

public class MoveElbowToAngle extends Command {

private Rotation2d targetAngle;

public Elbow getInstance() {
return Elbow.getInstance();
}
maya1414 marked this conversation as resolved.
Show resolved Hide resolved

public MoveElbowToAngle(Rotation2d targetAngle) {
this.targetAngle = targetAngle;
}

@Override
public void initialize() {
maya1414 marked this conversation as resolved.
Show resolved Hide resolved
getInstance().goToAngle(targetAngle);
}

public boolean isFinished() {
return getInstance().isAtAngle(targetAngle);
}

public void end(boolean interrupted) {
getInstance().stayAtPosition();
}

}
26 changes: 26 additions & 0 deletions src/main/java/training/commands/roller/MoveToSpeedRoller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package training.commands.roller;

import edu.wpi.first.wpilibj2.command.Command;
import training.subsystems.roller.Roller;

public class MoveToSpeedRoller extends Command {
maya1414 marked this conversation as resolved.
Show resolved Hide resolved

private double targetSpeed;

public Roller getInstance() {
return Roller.getInstance();
}
maya1414 marked this conversation as resolved.
Show resolved Hide resolved

public void MoveToSpeedSpeed(double targetSpeed) {
maya1414 marked this conversation as resolved.
Show resolved Hide resolved
this.targetSpeed = targetSpeed;
}

public boolean isFinished() {
return getInstance().isAtVelocity(targetSpeed);
}

public void end(boolean interrupted) {
getInstance().stop();
}

}
32 changes: 32 additions & 0 deletions src/main/java/training/commands/wrist/MoveWristToAngle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package training.commands.wrist;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj2.command.Command;
import training.subsystems.wrist.Wrist;

public class MoveWristToAngle extends Command {

private Rotation2d targetAngle;

public Wrist getInstance() {
return Wrist.getInstance();
}
maya1414 marked this conversation as resolved.
Show resolved Hide resolved

public MoveWristToAngle(Rotation2d targetAngle) {
this.targetAngle = targetAngle;
}

@Override
public void initialize() {
getInstance().goToAngle(targetAngle);
}

public boolean isFinished() {
return getInstance().isAtAngle(targetAngle);
}

public void end(boolean interrupted) {
getInstance().stop();
}

}
70 changes: 70 additions & 0 deletions src/main/java/training/subsystems/elbow/Elbow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package training.subsystems.elbow;

import com.revrobotics.CANSparkBase;
import com.revrobotics.CANSparkLowLevel;
import com.revrobotics.CANSparkMax;
import edu.wpi.first.math.controller.ArmFeedforward;
import edu.wpi.first.math.geometry.Rotation2d;
import utils.GBSubsystem;

public class Elbow extends GBSubsystem {

private static Elbow instance;
maya1414 marked this conversation as resolved.
Show resolved Hide resolved
private final CANSparkMax motor;
private final ArmFeedforward armFeedforward;
maya1414 marked this conversation as resolved.
Show resolved Hide resolved

private Elbow() {
this.armFeedforward = ElbowConstants.ARM_FEEDFORWARD;
this.motor = new CANSparkMax(ElbowConstants.MOTOR_ID, CANSparkLowLevel.MotorType.kBrushless);
motor.getPIDController().setP(ElbowConstants.P);
motor.getPIDController().setI(ElbowConstants.I);
motor.getPIDController().setD(ElbowConstants.D);
}

public static void init() {
if (instance == null) {
instance = new Elbow();
}
}

public static Elbow getInstance() {
init();
return instance;
}

public Rotation2d getPosition() {
return Rotation2d.fromRotations(motor.getEncoder().getPosition());
}

public Rotation2d getVelocity() {
return Rotation2d.fromRotations(motor.getEncoder().getVelocity());
}

public void goToAngle(Rotation2d targetAngle) {
motor.getPIDController()
.setReference(
targetAngle.getDegrees(),
CANSparkBase.ControlType.kPosition,
ElbowConstants.PID_SLOT,
ElbowConstants.ARM_FEEDFORWARD.calculate(getPosition().getRadians(), getVelocity().getRotations())
);
}

public boolean isAtAngle(Rotation2d targetAngle) {
return Math.abs(targetAngle.getDegrees() - motor.getEncoder().getPosition()) <= ElbowConstants.TOLERANCE.getRadians();
maya1414 marked this conversation as resolved.
Show resolved Hide resolved
}

public void stayAtPosition() {
goToAngle(getPosition());
}

@Override
protected String getLogPath() {
return "Elbow/";
}

@Override
protected void subsystemPeriodic() {
}

}
44 changes: 44 additions & 0 deletions src/main/java/training/subsystems/elbow/ElbowConstants.java
maya1414 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package training.subsystems.elbow;


import edu.wpi.first.math.controller.ArmFeedforward;
import edu.wpi.first.math.geometry.Rotation2d;

public class ElbowConstants {

public enum PresetPositions {

SAFE(Rotation2d.fromDegrees(0)),
INTAKE(Rotation2d.fromDegrees(0)),
SCORE(Rotation2d.fromDegrees(0)),
STARTING(Rotation2d.fromDegrees(0)),
TRANSFER(Rotation2d.fromDegrees(0));

public final Rotation2d ANGLE;

PresetPositions(Rotation2d angle) {
this.ANGLE = angle;
}

}


public static final int MOTOR_ID = 5;
public static final int P = 1;
public static final int I = 0;
public static final int D = 0;

public static final int PID_SLOT = 0;

public static final int KS = 0;
public static final int KA = 0;
public static final int KG = 0;
public static final int KV = 0;
public static final ArmFeedforward ARM_FEEDFORWARD = new ArmFeedforward(0, 0, 0, 0);
maya1414 marked this conversation as resolved.
Show resolved Hide resolved
public static final double GEAR_RATIO = 1 / (28.0 * (60.0 / 16.0));
public static final double ARM_LENGTH = 0.44;
public static final double ARM_MASS_KG = 0.44;
public static final Rotation2d BACKWARD_ANGLE_LIMIT = Rotation2d.fromDegrees(-81);
public static final Rotation2d FORWARD_ANGLE_LIMIT = Rotation2d.fromDegrees(90);
public static final Rotation2d TOLERANCE = Rotation2d.fromDegrees(3);
}
4 changes: 4 additions & 0 deletions src/main/java/training/subsystems/elbow/ElbowFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package training.subsystems.elbow;

public class ElbowFactory {
}
61 changes: 61 additions & 0 deletions src/main/java/training/subsystems/elbow/ElbowNEO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package training.subsystems.elbow;

import com.revrobotics.CANSparkBase;
import com.revrobotics.CANSparkLowLevel;
import com.revrobotics.CANSparkMax;
import edu.wpi.first.math.controller.ArmFeedforward;
import edu.wpi.first.math.geometry.Rotation2d;

public class ElbowNEO implements IElbow{
maya1414 marked this conversation as resolved.
Show resolved Hide resolved

private CANSparkMax motor;
private static ElbowNEO instance;
private ArmFeedforward armFeedforward;
maya1414 marked this conversation as resolved.
Show resolved Hide resolved

private ElbowNEO() {
this.armFeedforward = ElbowConstants.ARM_FEEDFORWARD;
this.motor = new CANSparkMax(ElbowConstants.MOTOR_ID, CANSparkLowLevel.MotorType.kBrushless);
motor.getPIDController().setP(ElbowConstants.P);
motor.getPIDController().setI(ElbowConstants.I);
motor.getPIDController().setD(ElbowConstants.D);
}

public void init() {
if (instance == null) {
instance = new ElbowNEO();
}
}

public ElbowNEO getInstance() {
init();
return instance;
}

public Rotation2d getPosition() {
return Rotation2d.fromRotations(motor.getEncoder().getPosition());
}

public Rotation2d getVelocity() {
return Rotation2d.fromRotations(motor.getEncoder().getVelocity());
}


maya1414 marked this conversation as resolved.
Show resolved Hide resolved
public void goToAngle(Rotation2d targetAngle) {
motor.getPIDController()
.setReference(
targetAngle.getDegrees(),
CANSparkBase.ControlType.kPosition,
ElbowConstants.PID_SLOT,
ElbowConstants.ARM_FEEDFORWARD.calculate(getPosition().getRadians(), getVelocity().getRotations())
maya1414 marked this conversation as resolved.
Show resolved Hide resolved
);
}

public boolean isAtAngle(Rotation2d targetAngle) {
return Math.abs(targetAngle.getDegrees() - motor.getEncoder().getPosition()) == 0;
maya1414 marked this conversation as resolved.
Show resolved Hide resolved
}

public void stayAtPosition() {
goToAngle(getPosition());
}

}
55 changes: 55 additions & 0 deletions src/main/java/training/subsystems/elbow/ElbowSimulation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package training.subsystems.elbow;

import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.controls.PositionVoltage;
import edu.wpi.first.math.controller.ArmFeedforward;
import edu.wpi.first.math.controller.PIDController;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.system.plant.DCMotor;
import edu.wpi.first.wpilibj.simulation.SingleJointedArmSim;
import utils.simulation.SingleJointedArmSimulation;

public class ElbowSimulation implements IElbow {

private SingleJointedArmSimulation elbowSimulation;
private ArmFeedforward armFeedforward;
private PIDController controller;
private PositionVoltage positionVoltage;

private ElbowSimulation() {
SingleJointedArmSim armSim = new SingleJointedArmSim(
DCMotor.getFalcon500(SimulationElbowConstants.NUMBER_OF_MOTORS),
maya1414 marked this conversation as resolved.
Show resolved Hide resolved
SimulationElbowConstants.GEAR_RATIO,
SingleJointedArmSim.estimateMOI(ElbowConstants.ARM_LENGTH, ElbowConstants.ARM_MASS_KG),
ElbowConstants.ARM_LENGTH,
ElbowConstants.BACKWARD_ANGLE_LIMIT.getRadians(),
ElbowConstants.FORWARD_ANGLE_LIMIT.getRadians(),
false,
ElbowConstants.PresetPositions.STARTING.ANGLE.getRadians()
);
elbowSimulation = new SingleJointedArmSimulation(armSim);
controller = new PIDController(SimulationElbowConstants.P, SimulationElbowConstants.I, SimulationElbowConstants.D);
TalonFXConfiguration config = new TalonFXConfiguration();
config.Slot0.kP = controller.getP();
config.Slot0.kI = controller.getI();
config.Slot0.kD = controller.getD();
elbowSimulation.applyConfiguration(config);
}

public void goToAngle(Rotation2d targetAngle) {
elbowSimulation.setControl(positionVoltage.withPosition(targetAngle.getRotations()));
}

public Rotation2d getPosition() {
return elbowSimulation.getPosition();
}

public Rotation2d getVelocity() {
return elbowSimulation.getVelocity();
}

public void stayAtPosition() {
goToAngle(getPosition());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package training.subsystems.elbow;

public class SimulationElbowConstants {

public static final int NUMBER_OF_MOTORS = 1;
maya1414 marked this conversation as resolved.
Show resolved Hide resolved
public static final double GEAR_RATIO = 1 / ElbowConstants.GEAR_RATIO;

public static final double P = 1;

public static final double I = 0;

public static final double D = 0;

}
7 changes: 7 additions & 0 deletions src/main/java/training/subsystems/roller/IRoller.java
maya1414 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package training.subsystems.roller;

public interface IRoller {

void goToSpeed(double targetSpeed);

}
Loading
Loading