generated from StuyPulse/Phil
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: reyamiller <[email protected]> Co-authored-by: ambers7 <[email protected]>
- Loading branch information
Showing
11 changed files
with
148 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/main/java/com/stuypulse/robot/commands/ElevatorDrive.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/java/com/stuypulse/robot/commands/ElevatorToBottom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package com.stuypulse.robot.commands; | ||
|
||
import com.stuypulse.robot.subsystems.Elevator; | ||
import com.stuypulse.robot.subsystems.ElevatorImpl; | ||
|
||
import static com.stuypulse.robot.constants.Settings.Elevator.*; | ||
|
||
public class ElevatorToBottom extends ElevatorToHeight { | ||
public ElevatorToBottom(Elevator elevator) { | ||
public ElevatorToBottom(ElevatorImpl elevator) { | ||
super(elevator, MIN_HEIGHT); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
src/main/java/com/stuypulse/robot/commands/ElevatorToHeight.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/java/com/stuypulse/robot/commands/ElevatorToTop.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package com.stuypulse.robot.commands; | ||
|
||
import com.stuypulse.robot.subsystems.Elevator; | ||
import com.stuypulse.robot.subsystems.ElevatorImpl; | ||
|
||
import static com.stuypulse.robot.constants.Settings.Elevator.*; | ||
|
||
public class ElevatorToTop extends ElevatorToHeight { | ||
public ElevatorToTop(Elevator elevator) { | ||
public ElevatorToTop(ElevatorImpl elevator) { | ||
super(elevator, MAX_HEIGHT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/java/com/stuypulse/robot/subsystems/ElevatorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.stuypulse.robot.subsystems; | ||
|
||
import com.revrobotics.CANSparkMax; | ||
import com.revrobotics.CANSparkMaxLowLevel.MotorType; | ||
|
||
import com.stuypulse.robot.constants.Ports; | ||
import com.revrobotics.RelativeEncoder; | ||
|
||
import edu.wpi.first.wpilibj.DigitalInput; | ||
import edu.wpi.first.wpilibj.DriverStation; | ||
import static com.stuypulse.robot.constants.Settings.Elevator.*; | ||
import static com.stuypulse.robot.constants.Settings.Elevator.Encoder.*; | ||
|
||
public class ElevatorImpl extends Elevator { | ||
// hardware | ||
public CANSparkMax leftMotor; | ||
public CANSparkMax rightMotor; | ||
|
||
public RelativeEncoder leftEncoder; | ||
public RelativeEncoder rightEncoder; | ||
|
||
public DigitalInput topLimit; | ||
public DigitalInput bottomLimit; | ||
|
||
public ElevatorImpl() { | ||
// motors | ||
leftMotor = new CANSparkMax(Ports.Elevator.LEFT, MotorType.kBrushless); | ||
rightMotor = new CANSparkMax(Ports.Elevator.RIGHT, MotorType.kBrushless); | ||
|
||
// encoders | ||
leftEncoder = leftMotor.getEncoder(); | ||
rightEncoder = rightMotor.getEncoder(); | ||
|
||
// limit switches | ||
topLimit = new DigitalInput(Ports.Elevator.TOP_LIMIT_SWITCH); | ||
bottomLimit = new DigitalInput(Ports.Elevator.BOTTOM_LIMIT_SWITCH); | ||
} | ||
|
||
public boolean atTop() { | ||
return !topLimit.get(); | ||
} | ||
|
||
public boolean atBottom() { | ||
return !bottomLimit.get(); | ||
} | ||
|
||
@Override | ||
public double getVelocity() { // average of the two? | ||
return (rightEncoder.getVelocity() + leftEncoder.getVelocity()) / 2 * ENCODER_MULTIPLIER; | ||
} | ||
|
||
@Override | ||
public double getHeight() { | ||
return (leftEncoder.getPosition() + rightEncoder.getPosition()) / 2 * ENCODER_MULTIPLIER; | ||
} | ||
|
||
public void setVoltage(double voltage) { | ||
if (atTop() && voltage > 0) { | ||
DriverStation.reportWarning("Top Limit Reached", false); | ||
|
||
voltage = 0.0; | ||
|
||
leftEncoder.setPosition(MAX_HEIGHT); | ||
rightEncoder.setPosition(MAX_HEIGHT); | ||
} else if (atBottom() && voltage < 0) { | ||
DriverStation.reportWarning("Bottom Limit Reached", false); | ||
|
||
voltage = 0.0; | ||
|
||
leftEncoder.setPosition(MIN_HEIGHT); | ||
rightEncoder.setPosition(MIN_HEIGHT); | ||
} | ||
|
||
rightMotor.setVoltage(voltage); | ||
leftMotor.setVoltage(voltage); | ||
} | ||
|
||
public void addTargetHeight(double delta) { | ||
setTargetHeight(getTargetHeight() + delta); | ||
} | ||
} |
28 changes: 10 additions & 18 deletions
28
src/main/java/com/stuypulse/robot/subsystems/SimElevator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,29 @@ | ||
package com.stuypulse.robot.subsystems; | ||
|
||
import static com.stuypulse.robot.constants.Settings.Elevator.*; | ||
import static com.stuypulse.robot.constants.Settings.FeedForward.*; | ||
import static com.stuypulse.robot.constants.Settings.PID.*; | ||
|
||
import com.stuypulse.stuylib.control.Controller; | ||
import com.stuypulse.stuylib.control.feedback.PIDController; | ||
import com.stuypulse.stuylib.control.feedforward.ElevatorFeedforward; | ||
import com.stuypulse.stuylib.network.SmartNumber; | ||
import com.stuypulse.stuylib.streams.filters.MotionProfile; | ||
|
||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.wpilibj.simulation.ElevatorSim; | ||
|
||
public class SimElevator { | ||
public class SimElevator extends Elevator { | ||
private ElevatorSim sim; | ||
|
||
private double height; | ||
private double velocity; | ||
|
||
private Controller position; | ||
private SmartNumber targetHeight; | ||
|
||
public SimElevator() { | ||
height = 0.0; | ||
velocity = 0.0; | ||
|
||
targetHeight = new SmartNumber("Target Height", MIN_HEIGHT); | ||
sim = new ElevatorSim(DCMotor.getNEO(2), GEARING, CARRIAGE_MASS, DRUM_RADIUS, MIN_HEIGHT, MAX_HEIGHT, true); | ||
} | ||
|
||
position = new PIDController(kP, kI, kD) | ||
.add(new ElevatorFeedforward(kG)) | ||
.setOutputFilter(new MotionProfile(VEL_LIMIT, ACC_LIMIT)); | ||
@Override | ||
public double getVelocity() { | ||
return sim.getVelocityMetersPerSecond(); | ||
} | ||
|
||
// sim = new ElevatorSim(DCMotor.getCIM(4), 106.94, 2.5, 1.435, MIN_HEIGHT, MAX_HEIGHT, false); | ||
@Override | ||
public double getHeight() { | ||
return sim.getPositionMeters(); | ||
} | ||
} |
Oops, something went wrong.