Skip to content

Commit e2dabbf

Browse files
committed
Added new command and limits for arm | NOT FINISHED PLEASE HELP IM TIRED
1 parent bac2f77 commit e2dabbf

File tree

5 files changed

+71
-19
lines changed

5 files changed

+71
-19
lines changed

src/main/java/org/carlmontrobotics/Constants.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,15 @@ public static final class Armc {
165165
//fine for now, change it later before use - ("Incorect use of setIZone()" Issue #22)
166166
//public static final double MAX_FF_VEL_RAD_P_S = 0.2; //rad/s
167167
public static final double MAX_FF_ACCEL_RAD_P_S = 53.728/4; // rad / s^2 ((.89*2)/(1.477/(61.875^2))/61.875)-20.84
168-
168+
public static final double SOFT_LIMIT_LOCATION_IN_RADIANS = 0;
169169

170170
public static final double MIN_VOLTAGE = -0.5; //-((kS + kG + 1)/12);
171171
public static final double MAX_VOLTAGE = 0.5; //(kS + kG + 1)/12;
172-
172+
173173
// if needed
174174
public static final double COM_ARM_LENGTH_METERS = 0.381;
175175
public static final double ARM_MASS_KG = 9.59302503;
176-
176+
177177
public static TrapezoidProfile.Constraints TRAP_CONSTRAINTS;//initalized by arm constructor
178178
// other0;
179179

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.carlmontrobotics.commands;
2+
3+
import org.carlmontrobotics.subsystems.Arm;
4+
5+
import static org.carlmontrobotics.Constants.Armc.*;
6+
7+
import org.carlmontrobotics.Constants.Armc.*;
8+
import edu.wpi.first.wpilibj2.command.Command;
9+
10+
public class ClimbArmSoftLimit extends Command {
11+
//TODO: Debug this entire thing because it is 1 am and no way i did this correctly
12+
private Arm arm;
13+
public ClimbArmSoftLimit(Arm arm) {
14+
this.arm = arm;
15+
addRequirements(arm);
16+
}
17+
@Override
18+
public void initialize() {
19+
arm.setLimitsForClimbOn();
20+
arm.setArmTarget(CLIMBER_UP_ANGLE_RAD);
21+
arm.setBooleanDrive(true);
22+
}
23+
@Override
24+
public void execute() {
25+
arm.driveArmMax(-1);
26+
arm.setSoftLimit( (float) SOFT_LIMIT_LOCATION_IN_RADIANS); //TODO: Find out what limit actually is defined as
27+
}
28+
@Override
29+
public void end(boolean interrupted) {
30+
arm.stopArm(); //OR maintain small voltage to keep arm in place?
31+
arm.resetSoftLimit();
32+
arm.setBooleanDrive(false);
33+
}
34+
@Override
35+
public boolean isFinished() {
36+
return arm.getArmPos() <= CLIMBER_DOWN_ANGLE_RAD + 0.02 || arm.getArmPos() >= CLIMBER_DOWN_ANGLE_RAD - 0.05; //TODO: Figure out the actual climb position
37+
}
38+
}

src/main/java/org/carlmontrobotics/commands/TeleopEffector.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,8 @@ public void execute() {
5656
intake.setRPMOutake(MANUAL_RPM_MAX * joystick.getAsDouble());
5757
}
5858
//manipulatorController.setRumble(RumbleType.kBothRumble, 0.5);
59-
if(!hasIntaked && intake.intakeDetectsNote()) {
60-
manipulatorController.setRumble(RumbleType.kBothRumble, 0.5);
61-
hasIntaked = true;
62-
timer.start();
63-
}
64-
if(hasIntaked && timer.get() > 1) {
65-
manipulatorController.setRumble(RumbleType.kBothRumble, 0);
66-
timer.stop();
59+
if(intake.intakeDetectsNote()) {
60+
manipulatorController.setRumble(RumbleType.kBothRumble, 0.4);
6761
}
6862
/*
6963
intake.setRPMIntake(MANUAL_RPM_MAX * joystick.getAsDouble());
@@ -74,7 +68,7 @@ public void execute() {
7468
// Called once the command ends or is interrupted.
7569
@Override
7670
public void end(boolean interrupted) {
77-
71+
manipulatorController.setRumble(RumbleType.kBothRumble, 0); //Reasoning: I WANNA TEST WHAT HAPPENS WHEN ANOTHER CMD IS USED OVER DEFAULT
7872
}
7973

8074
// Returns true when the command should end.

src/main/java/org/carlmontrobotics/commands/moveClimber.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public moveClimber(Arm arm) {
3030
// Called when the command is initially scheduled.
3131
@Override
3232
public void initialize() {
33-
arm.callDrive = false;//turn normal arm periodic off
33+
arm.setBooleanDrive(false);//turn normal arm periodic off
3434
//arm.setArmTarget(goal);
3535
SmartDashboard.putNumber("climber volts", 0);
3636
}
@@ -56,7 +56,7 @@ public void execute() {
5656
public void end(boolean interrupted) {
5757
arm.driveMotor(Volt.of(0));
5858
arm.setArmTarget(arm.getArmPos());
59-
arm.callDrive = true;
59+
arm.setBooleanDrive(false);
6060
}
6161

6262
// Returns true when the command should end.

src/main/java/org/carlmontrobotics/subsystems/Arm.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.revrobotics.AbsoluteEncoder;
1111
import com.revrobotics.CANSparkBase;
1212
import com.revrobotics.CANSparkBase.IdleMode;
13+
import com.revrobotics.CANSparkBase.SoftLimitDirection;
1314
import com.revrobotics.CANSparkMax;
1415
import com.revrobotics.RelativeEncoder;
1516
import com.revrobotics.SparkAbsoluteEncoder;
@@ -55,8 +56,7 @@
5556

5657
// Arm angle is measured from horizontal on the intake side of the robot and bounded between -3π/2 and π/2
5758
public class Arm extends SubsystemBase {
58-
public boolean armClimbing = false;
59-
public boolean callDrive = true;
59+
private boolean callDrive = true;
6060
private final CANSparkMax armMotorMaster/* left */ = MotorControllerFactory.createSparkMax(ARM_MOTOR_PORT_MASTER,
6161
MotorConfig.NEO);
6262
private final CANSparkMax armMotorFollower/* right */ = MotorControllerFactory
@@ -150,6 +150,9 @@ public Arm() {
150150
lastArmPos = getArmPos();
151151
lastMeasuredTime = Timer.getFPGATimestamp();
152152
}
153+
public void setBooleanDrive(boolean climb) {
154+
callDrive = climb;
155+
}
153156

154157
@Override
155158
public void periodic() {
@@ -207,7 +210,7 @@ public void periodic() {
207210
isArmEncoderConnected = currTime - lastMeasuredTime < DISCONNECTED_ENCODER_TIMEOUT_SEC;
208211

209212
if (isArmEncoderConnected) {
210-
if (callDrive || true) {
213+
if (callDrive) {
211214
driveArm();
212215
}
213216
} else {
@@ -219,7 +222,7 @@ public void periodic() {
219222
autoCancelArmCommand();
220223

221224
}
222-
225+
223226
public void autoCancelArmCommand() {
224227
if (!(getDefaultCommand() instanceof TeleopArm) || DriverStation.isAutonomous())
225228
return;
@@ -260,6 +263,14 @@ public void stopArm() {
260263
armMotorMaster.set(0);
261264

262265
}
266+
public void driveArmMax(int direction) {
267+
drivearm(6 * direction); //STARTING WITH SLOWER SPEED FOR TESTING
268+
}
269+
public void setLimitsForClimbOn() {
270+
armPIDMaster.setOutputRange(-12, 12);
271+
armMotorMaster.setOpenLoopRampRate(5);
272+
armMotorMaster.enableSoftLimit(SoftLimitDirection.kReverse, true);
273+
}
263274
/**
264275
*
265276
* @param targetPos in radians
@@ -321,7 +332,14 @@ public double getArmPos() {
321332
public double getArmVel() {
322333
return armMasterEncoder.getVelocity();
323334
}
324-
335+
public void setSoftLimit(float limit) {
336+
337+
armMotorMaster.setSoftLimit(SoftLimitDirection.kReverse, limit);
338+
}
339+
public void resetSoftLimit() {
340+
armPIDMaster.setOutputRange(-12/MIN_VOLTAGE, 12/MAX_VOLTAGE);
341+
armMotorMaster.enableSoftLimit(SoftLimitDirection.kReverse, false);
342+
}
325343
public TrapezoidProfile.State getCurrentArmState() {
326344
return new TrapezoidProfile.State(getArmPos(), getArmVel());
327345
}
@@ -363,6 +381,8 @@ public void initSendable(SendableBuilder builder){
363381
builder.addBooleanProperty("ArmPIDAtSetpoint", () -> armAtSetpoint(), null);
364382
builder.addDoubleProperty("Arm Goal Pos (rad)", () -> goalState.position, null);
365383
builder.addDoubleProperty("InternalArmVelocity", () -> armMasterEncoder.getVelocity(), null);
384+
builder.addDoubleProperty("Soft limit Forward", () -> armMotorMaster.getSoftLimit(SoftLimitDirection.kForward), null);
385+
builder.addDoubleProperty("Soft limit Reverse", () -> armMotorMaster.getSoftLimit(SoftLimitDirection.kReverse), null);
366386
}
367387

368388
public double getMaxVelRad(){

0 commit comments

Comments
 (0)