This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Driver Station Computer
committed
Dec 19, 2024
1 parent
14ed720
commit 7d1c6f0
Showing
2 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/main/java/com/team766/robot/burro_elevator/mechanisms/Elevator.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,45 @@ | ||
package com.team766.robot.burro_elevator.mechanisms; | ||
|
||
import com.team766.framework.Mechanism; | ||
import com.team766.hal.MotorController.ControlMode; | ||
import com.team766.hal.RobotProvider; | ||
import com.team766.hal.wpilib.CANSparkMaxMotorController; | ||
import com.team766.library.RateLimiter; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
|
||
public class Elevator extends Mechanism { | ||
private static final double MOTOR_ROTATIONS_TO_ELEVATOR_POSITION = | ||
(0.25 /*chain pitch = distance per tooth*/) | ||
* (18. /*teeth per rotation of sprocket*/) | ||
* (1. / (3. * 4. * 4.) /*planetary gearbox*/); | ||
|
||
private final CANSparkMaxMotorController motor; | ||
private final RateLimiter dashboardRateLimiter = new RateLimiter(0.1); | ||
|
||
public Elevator() { | ||
motor = (CANSparkMaxMotorController) RobotProvider.instance.getMotor("elevator.Motor"); | ||
motor.setSmartCurrentLimit(10, 80, 200); | ||
} | ||
|
||
public void setPower(final double power) { | ||
checkContextOwnership(); | ||
motor.set(power); | ||
} | ||
|
||
public void setPosition(final double position) { | ||
checkContextOwnership(); | ||
|
||
motor.set(ControlMode.Position, position / MOTOR_ROTATIONS_TO_ELEVATOR_POSITION); | ||
} | ||
|
||
public double getPosition() { | ||
return motor.getSensorPosition() * MOTOR_ROTATIONS_TO_ELEVATOR_POSITION; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
if (dashboardRateLimiter.next()) { | ||
SmartDashboard.putNumber("[Elevator] Position", getPosition()); | ||
} | ||
} | ||
} |
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