Skip to content

Commit 9eb8d33

Browse files
LeanMeanBeanMachine4774L9-bms
authored andcommitted
create tilt_to_shooter_FOR method and replaced tilt_to references
1 parent 8583b81 commit 9eb8d33

File tree

5 files changed

+32
-26
lines changed

5 files changed

+32
-26
lines changed

components/ballistics.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from components.injector import InjectorComponent
1515
from components.led_component import LightStrip
1616
from components.shooter import ShooterComponent
17-
from components.wrist import WristComponent
1817
from utilities.game import (
1918
ALGAE_MAX_DIAMETER,
2019
ALGAE_MIN_DIAMETER,
@@ -60,14 +59,15 @@ class BallisticsComponent:
6059

6160
FLYWHEEL_ANGLE_LOOKUP = {
6261
ALGAE_MIN_DIAMETER: (
63-
math.radians(-10) + WristComponent.COM_DIFFERENCE,
64-
math.radians(-15) + WristComponent.COM_DIFFERENCE,
65-
math.radians(-25) + WristComponent.COM_DIFFERENCE
62+
math.radians(-10),
63+
math.radians(-15),
64+
math.radians(-25)
6665
),
66+
# 16.5: (math.radians(-11.0), math.radians(-19), -25),
6767
ALGAE_MAX_DIAMETER: (
68-
math.radians(-10) + WristComponent.COM_DIFFERENCE,
69-
math.radians(-15) + WristComponent.COM_DIFFERENCE,
70-
math.radians(-25) + WristComponent.COM_DIFFERENCE
68+
math.radians(-10),
69+
math.radians(-15),
70+
math.radians(-25)
7171
),
7272
}
7373
# fmt: on

components/wrist.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class WristComponent:
2525
COM_DIFFERENCE = 0.54722467321
2626
MAXIMUM_DEPRESSION = math.radians(-112.0) + COM_DIFFERENCE
2727
MAXIMUM_ELEVATION = math.radians(0) + COM_DIFFERENCE
28-
NEUTRAL_ANGLE = math.radians(-90.0) + COM_DIFFERENCE
28+
NEUTRAL_ANGLE = math.radians(-90.0)
2929

3030
WRIST_MAX_VEL = math.radians(180.0)
3131
WRIST_MAX_ACC = math.radians(360.0)
@@ -123,7 +123,7 @@ def inclination_deg(self) -> float:
123123
return math.degrees(self.inclination())
124124

125125
@feedback
126-
def test_inclination(self) -> float:
126+
def shooter_FOR_inclination(self) -> float:
127127
return math.degrees(self.inclination() - self.COM_DIFFERENCE)
128128

129129
@feedback
@@ -143,6 +143,18 @@ def at_setpoint(self) -> bool:
143143
self.desired_state.velocity - self.current_velocity()
144144
) < WristComponent.VEL_TOLERANCE
145145

146+
# Tilts to an angle with regards to the shooter frame of reference.
147+
# Shooter FOR takes the arm as in-line with the backplate of the shooter
148+
# SHould be called with angles in the shooter FOR
149+
def tilt_to_shooter_FOR(self, pos: float) -> None:
150+
clamped_angle = clamp(
151+
(pos + self.COM_DIFFERENCE), self.MAXIMUM_DEPRESSION, self.MAXIMUM_ELEVATION
152+
)
153+
# If the new setpoint is within the tolerance we wouldn't move anyway
154+
if abs(clamped_angle - self.desired_state.position) > self.TOLERANCE:
155+
self._tilt_to(clamped_angle)
156+
157+
# Tilts to an angle with respect to the COM FOR
146158
def tilt_to(self, pos: float) -> None:
147159
clamped_angle = clamp(pos, self.MAXIMUM_DEPRESSION, self.MAXIMUM_ELEVATION)
148160

@@ -160,7 +172,7 @@ def _tilt_to(self, pos: float):
160172
)
161173

162174
def go_to_neutral(self) -> None:
163-
self.tilt_to(WristComponent.NEUTRAL_ANGLE)
175+
self.tilt_to_shooter_FOR(WristComponent.NEUTRAL_ANGLE)
164176

165177
@feedback
166178
def at_limit(self) -> bool:
@@ -178,9 +190,7 @@ def execute(self) -> None:
178190
self.pid.calculate(self.inclination(), tracked_state.position) + ff
179191
)
180192

181-
self.wrist_ligament.setAngle(
182-
self.inclination_deg() - math.degrees(WristComponent.COM_DIFFERENCE)
183-
)
193+
self.wrist_ligament.setAngle(self.shooter_FOR_inclination())
184194

185195
self.wrist_COM_ligament.setAngle(self.inclination_deg())
186196
# self.wrist_ligament.setAngle(math.degrees(desired_state.position))

controllers/algae_shooter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class AlgaeShooter(StateMachine):
2020
floor_intake: FloorIntake
2121
reef_intake: ReefIntake
2222

23-
SHOOT_ANGLE = tunable(-50.0 + math.degrees(WristComponent.COM_DIFFERENCE))
23+
SHOOT_ANGLE = tunable(-50.0)
2424
TOP_SHOOT_SPEED = tunable(60.0)
2525
BOTTOM_SHOOT_SPEED = tunable(65.0)
2626
use_ballistics = tunable(True)
2727

28-
MEASURING_ANGLE = math.radians(-15.0) + WristComponent.COM_DIFFERENCE
28+
MEASURING_ANGLE = math.radians(-15.0)
2929

3030
def __init__(self) -> None:
3131
pass
@@ -46,20 +46,20 @@ def shoot(self) -> None:
4646

4747
@state(first=True)
4848
def measuring(self):
49-
self.wrist.tilt_to(self.MEASURING_ANGLE)
49+
self.wrist.tilt_to_shooter_FOR(self.MEASURING_ANGLE)
5050

5151
self.next_state(self.preparing)
5252

5353
@state(must_finish=True)
5454
def preparing(self):
5555
if self.use_ballistics:
5656
solution = self.ballistics_component.current_solution()
57-
self.wrist.tilt_to(solution.inclination)
57+
self.wrist.tilt_to_shooter_FOR(solution.inclination)
5858
self.shooter_component.spin_flywheels(
5959
solution.top_speed, solution.bottom_speed
6060
)
6161
else:
62-
self.wrist.tilt_to(math.radians(self.SHOOT_ANGLE))
62+
self.wrist.tilt_to_shooter_FOR(math.radians(self.SHOOT_ANGLE))
6363
self.shooter_component.spin_flywheels(
6464
self.TOP_SHOOT_SPEED, self.BOTTOM_SHOOT_SPEED
6565
)

controllers/floor_intake.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class FloorIntake(StateMachine):
1414
wrist: WristComponent
1515
intake_component: IntakeComponent
1616

17-
HANDOFF_POSITION = tunable(math.radians(-112.0) + WristComponent.COM_DIFFERENCE)
17+
HANDOFF_POSITION = tunable(math.radians(-112.0))
1818

1919
def __init__(self):
2020
self.intake_upper = False
@@ -33,7 +33,7 @@ def intaking(self):
3333

3434
self.intake_component.intake(self.intake_upper)
3535

36-
self.wrist.tilt_to(self.HANDOFF_POSITION)
36+
self.wrist.tilt_to_shooter_FOR(self.HANDOFF_POSITION)
3737

3838
self.shooter_component.intake()
3939
self.injector_component.intake()

controllers/reef_intake.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,9 @@ def intaking(self, initial_call: bool):
7272
current_is_L3 = self.is_L3()
7373

7474
if current_is_L3:
75-
self.wrist.tilt_to(
76-
math.radians(self.L3_INTAKE_ANGLE) + WristComponent.COM_DIFFERENCE
77-
)
75+
self.wrist.tilt_to_shooter_FOR(math.radians(self.L3_INTAKE_ANGLE))
7876
else:
79-
self.wrist.tilt_to(
80-
math.radians(self.L2_INTAKE_ANGLE) + WristComponent.COM_DIFFERENCE
81-
)
77+
self.wrist.tilt_to_shooter_FOR(math.radians(self.L2_INTAKE_ANGLE))
8278
self.last_l3 = current_is_L3
8379

8480
if not self.holding_coral:

0 commit comments

Comments
 (0)