Skip to content

Commit 75fc430

Browse files
authored
Merge pull request #421 from thedropbears/update-wrist-coord-scheme
Update wrist coordinate scheme
2 parents 741c9bf + 1b4330d commit 75fc430

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

components/ballistics.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,17 @@ class BallisticsComponent:
5858
}
5959

6060
FLYWHEEL_ANGLE_LOOKUP = {
61-
ALGAE_MIN_DIAMETER: (math.radians(-10), math.radians(-15), math.radians(-25)),
61+
ALGAE_MIN_DIAMETER: (
62+
math.radians(-10),
63+
math.radians(-15),
64+
math.radians(-25)
65+
),
6266
# 16.5: (math.radians(-11.0), math.radians(-19), -25),
63-
ALGAE_MAX_DIAMETER: (math.radians(-10), math.radians(-15), math.radians(-25)),
67+
ALGAE_MAX_DIAMETER: (
68+
math.radians(-10),
69+
math.radians(-15),
70+
math.radians(-25)
71+
),
6472
}
6573
# fmt: on
6674
BALL_SIZES = list(FLYWHEEL_ANGLE_LOOKUP.keys())

components/wrist.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121

2222

2323
class WristComponent:
24-
ENCODER_ZERO_OFFSET = 4.011863
25-
MAXIMUM_DEPRESSION = math.radians(-112.0)
26-
MAXIMUM_ELEVATION = math.radians(0)
24+
ENCODER_ZERO_OFFSET = 3.46463832679
25+
COM_DIFFERENCE = 0.54722467321
26+
MAXIMUM_DEPRESSION = math.radians(-112.0) + COM_DIFFERENCE
27+
MAXIMUM_ELEVATION = math.radians(0) + COM_DIFFERENCE
2728
NEUTRAL_ANGLE = math.radians(-90.0)
2829

2930
WRIST_MAX_VEL = math.radians(180.0)
@@ -37,6 +38,10 @@ def __init__(self, mech_root: wpilib.MechanismRoot2d):
3738
"wrist", length=0.5, angle=0, color=wpilib.Color8Bit(wpilib.Color.kYellow)
3839
)
3940

41+
self.wrist_COM_ligament = mech_root.appendLigament(
42+
"wrist_COM", length=0.5, angle=0, color=wpilib.Color8Bit(wpilib.Color.kBlue)
43+
)
44+
4045
self.wrist_encoder = DutyCycleEncoder(DioChannel.WRIST_ENCODER, math.tau, 0)
4146
configure_through_bore_encoder(self.wrist_encoder)
4247
self.wrist_encoder.setInverted(False)
@@ -117,6 +122,10 @@ def inclination(self) -> float:
117122
def inclination_deg(self) -> float:
118123
return math.degrees(self.inclination())
119124

125+
@feedback
126+
def shooter_FOR_inclination_deg(self) -> float:
127+
return math.degrees(self.inclination() - self.COM_DIFFERENCE)
128+
120129
@feedback
121130
def shoot_angle_deg(self) -> float:
122131
return self.inclination_deg() + 90
@@ -134,6 +143,13 @@ def at_setpoint(self) -> bool:
134143
self.desired_state.velocity - self.current_velocity()
135144
) < WristComponent.VEL_TOLERANCE
136145

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+
self.tilt_to(pos + self.COM_DIFFERENCE)
151+
152+
# Tilts to an angle with respect to the COM FOR
137153
def tilt_to(self, pos: float) -> None:
138154
clamped_angle = clamp(pos, self.MAXIMUM_DEPRESSION, self.MAXIMUM_ELEVATION)
139155

@@ -151,7 +167,7 @@ def _tilt_to(self, pos: float):
151167
)
152168

153169
def go_to_neutral(self) -> None:
154-
self.tilt_to(WristComponent.NEUTRAL_ANGLE)
170+
self.tilt_to_shooter_FOR(WristComponent.NEUTRAL_ANGLE)
155171

156172
@feedback
157173
def at_limit(self) -> bool:
@@ -169,5 +185,7 @@ def execute(self) -> None:
169185
self.pid.calculate(self.inclination(), tracked_state.position) + ff
170186
)
171187

172-
self.wrist_ligament.setAngle(self.inclination_deg())
188+
self.wrist_ligament.setAngle(self.shooter_FOR_inclination_deg())
189+
190+
self.wrist_COM_ligament.setAngle(self.inclination_deg())
173191
# self.wrist_ligament.setAngle(math.degrees(desired_state.position))

controllers/algae_shooter.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class AlgaeShooter(StateMachine):
2525
BOTTOM_SHOOT_SPEED = tunable(65.0)
2626
use_ballistics = tunable(True)
2727

28+
MEASURING_ANGLE = math.radians(-15.0)
29+
2830
def __init__(self) -> None:
2931
pass
3032

@@ -44,20 +46,20 @@ def shoot(self) -> None:
4446

4547
@state(first=True)
4648
def measuring(self):
47-
self.wrist.tilt_to(math.radians(-15.0))
49+
self.wrist.tilt_to_shooter_FOR(self.MEASURING_ANGLE)
4850

4951
self.next_state(self.preparing)
5052

5153
@state(must_finish=True)
5254
def preparing(self):
5355
if self.use_ballistics:
5456
solution = self.ballistics_component.current_solution()
55-
self.wrist.tilt_to(solution.inclination)
57+
self.wrist.tilt_to_shooter_FOR(solution.inclination)
5658
self.shooter_component.spin_flywheels(
5759
solution.top_speed, solution.bottom_speed
5860
)
5961
else:
60-
self.wrist.tilt_to(math.radians(self.SHOOT_ANGLE))
62+
self.wrist.tilt_to_shooter_FOR(math.radians(self.SHOOT_ANGLE))
6163
self.shooter_component.spin_flywheels(
6264
self.TOP_SHOOT_SPEED, self.BOTTOM_SHOOT_SPEED
6365
)

controllers/floor_intake.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +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(math.radians(self.L3_INTAKE_ANGLE))
75+
self.wrist.tilt_to_shooter_FOR(math.radians(self.L3_INTAKE_ANGLE))
7676
else:
77-
self.wrist.tilt_to(math.radians(self.L2_INTAKE_ANGLE))
77+
self.wrist.tilt_to_shooter_FOR(math.radians(self.L2_INTAKE_ANGLE))
7878
self.last_l3 = current_is_L3
7979

8080
if not self.holding_coral:

0 commit comments

Comments
 (0)