Skip to content

Commit 55abf5a

Browse files
Merge pull request #396 from thedropbears/will-reset-to
Add will_reset_to's
2 parents f48b2a2 + 5edce63 commit 55abf5a

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

components/injector.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import math
22

3-
from magicbot import feedback, tunable
3+
from magicbot import feedback, tunable, will_reset_to
44
from rev import SparkMax, SparkMaxConfig
55
from wpilib import DigitalInput
66

77
from ids import DioChannel, SparkId
88

99

1010
class InjectorComponent:
11+
desired_injector_voltage = will_reset_to(0.0)
12+
should_measure = will_reset_to(False)
13+
1114
INJECTOR_INJECT_VOLTAGE = tunable(12.0)
1215
INJECTOR_INTAKE_VOLTAGE = tunable(-2.0)
1316
INJECTOR_BACKDRIVE_VOLTAGE = tunable(-0.5)
@@ -50,10 +53,6 @@ def __init__(self) -> None:
5053

5154
self.has_seen_algae: bool = False
5255

53-
self.should_measure = False
54-
55-
self.desired_injector_voltage = 0.0
56-
5756
def on_enable(self) -> None:
5857
self.has_seen_algae = False
5958

@@ -106,6 +105,3 @@ def execute(self) -> None:
106105
else:
107106
self.injector_1.setVoltage(self.desired_injector_voltage)
108107
self.injector_2.setVoltage(self.desired_injector_voltage)
109-
110-
self.should_measure = False
111-
self.desired_injector_voltage = 0.0

components/intake.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import numpy as np
44
import wpilib
5-
from magicbot import feedback, tunable
5+
from magicbot import feedback, tunable, will_reset_to
66
from phoenix5 import ControlMode, TalonSRX
77
from rev import (
88
SparkMax,
@@ -23,6 +23,7 @@
2323

2424
class IntakeComponent:
2525
intake_output = tunable(0.9)
26+
desired_output = will_reset_to(0.0)
2627

2728
# Offset is measured in the vertical position
2829
VERTICAL_ENCODER_VALUE = 4.592024
@@ -42,8 +43,6 @@ def __init__(self, intake_mech_root: wpilib.MechanismRoot2d) -> None:
4243
self.intake_motor = TalonSRX(TalonId.INTAKE)
4344
self.intake_motor.setInverted(True)
4445

45-
self.desired_output = 0.0
46-
4746
self.arm_motor = SparkMax(SparkId.INTAKE_ARM, SparkMax.MotorType.kBrushless)
4847
self.encoder = DutyCycleEncoder(DioChannel.INTAKE_ENCODER, math.tau, 0)
4948
configure_through_bore_encoder(self.encoder)
@@ -210,8 +209,6 @@ def on_enable(self) -> None:
210209
def execute(self) -> None:
211210
self.intake_motor.set(ControlMode.PercentOutput, self.desired_output)
212211

213-
self.desired_output = 0.0
214-
215212
self.tracked_state = self.motion_profile.calculate(
216213
wpilib.Timer.getFPGATimestamp() - self.last_setpoint_update_time,
217214
self.initial_state,

components/shooter.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import math
22

33
import wpilib
4-
from magicbot import feedback, tunable
4+
from magicbot import feedback, tunable, will_reset_to
55
from phoenix6.configs import (
66
ClosedLoopRampsConfigs,
77
FeedbackConfigs,
@@ -17,6 +17,9 @@
1717

1818

1919
class ShooterComponent:
20+
top_desired_flywheel_speed = will_reset_to(0.0)
21+
bottom_desired_flywheel_speed = will_reset_to(0.0)
22+
2023
FLYWHEEL_INTAKE_SPEED = tunable(-20.0)
2124
FLYWHEEL_RPS_TOLERANCE = 1.0
2225
FLYWHEEL_RAMP_TIME = 1
@@ -71,9 +74,6 @@ def __init__(self) -> None:
7174
bottom_flywheel_config.apply(flywheel_gear_ratio)
7275
bottom_flywheel_config.apply(flywheel_closed_loop_ramp_config)
7376

74-
self.top_desired_flywheel_speed = 0.0
75-
self.bottom_desired_flywheel_speed = 0.0
76-
7777
self._algae_size = 16.25
7878
self.has_measured = True
7979

@@ -146,6 +146,3 @@ def execute(self) -> None:
146146
self.bottom_desired_flywheel_speed, override_brake_dur_neutral=True
147147
)
148148
)
149-
150-
self.top_desired_flywheel_speed = 0.0
151-
self.bottom_desired_flywheel_speed = 0.0

0 commit comments

Comments
 (0)