-
Notifications
You must be signed in to change notification settings - Fork 0
Limit switch climber #35
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,49 @@ | ||
| from magicbot import tunable, will_reset_to | ||
| from rev import SparkMax, SparkMaxConfig | ||
| from rev import LimitSwitchConfig, SparkMax, SparkMaxConfig | ||
|
|
||
| from ids import SparkId | ||
| from utilities.rev import configure_spark_reset_and_persist | ||
|
|
||
|
|
||
| class ClimberComponent: | ||
| setpoint = will_reset_to(0.0) | ||
| climb_speed = tunable(0.2) | ||
| MAX_FORWARD_EXTENSION, MAX_REVERSE_EXTENSION = 120, -120 | ||
|
|
||
| current_climber_speed = will_reset_to(0.0) | ||
| forward_climber_speed, reverse_climber_speed = tunable(0.8), tunable(0.8) | ||
|
|
||
| def __init__(self): | ||
| # create motor with correct forward direction sparkmax controller | ||
| self.motor = SparkMax(SparkId.CLIMBER, SparkMax.MotorType.kBrushless) | ||
| self.forward_limit_switch = self.motor.getForwardLimitSwitch() | ||
| self.reverse_limit_switch = self.motor.getReverseLimitSwitch() | ||
| self.encoder = self.motor.getEncoder() | ||
|
|
||
| config = SparkMaxConfig() | ||
SyntaxBreak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| config.inverted(True) | ||
| config.setIdleMode(SparkMaxConfig.IdleMode.kBrake) | ||
|
|
||
| config.limitSwitch.forwardLimitSwitchType( | ||
| LimitSwitchConfig.Type.kNormallyOpen | ||
| ).forwardLimitSwitchTriggerBehavior( | ||
| LimitSwitchConfig.Behavior.kStopMovingMotor | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the default behaviour, right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know where to find the default configs |
||
| ).reverseLimitSwitchType( | ||
| LimitSwitchConfig.Type.kNormallyOpen | ||
| ).reverseLimitSwitchTriggerBehavior(LimitSwitchConfig.Behavior.kStopMovingMotor) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect you want the reverse limit switch to zero the position? Otherwise this would start at an arbitrary position and your forward soft limit might not do what you expect. |
||
|
|
||
| config.softLimit.forwardSoftLimit( | ||
| self.MAX_FORWARD_EXTENSION | ||
| ).forwardSoftLimitEnabled(True).reverseSoftLimit( | ||
| self.MAX_REVERSE_EXTENSION | ||
| ).reverseSoftLimitEnabled(True) | ||
|
|
||
| configure_spark_reset_and_persist(self.motor, config) | ||
|
|
||
| def deploy(self): | ||
| self.setpoint = -self.climb_speed | ||
| self.current_climber_speed = self.forward_climber_speed | ||
|
|
||
| def climb(self): | ||
| self.setpoint = self.climb_speed | ||
| def retract(self): | ||
| self.current_climber_speed = self.reverse_climber_speed | ||
|
|
||
| def execute(self): | ||
| self.motor.set(self.setpoint) | ||
| self.motor.set(self.current_climber_speed) | ||
Uh oh!
There was an error while loading. Please reload this page.