Skip to content

Commit 2bbc6f2

Browse files
LeanMeanBeanMachine4774L9-bms
authored andcommitted
add wrist com difference and add wrist_COM in sim
1 parent 741c9bf commit 2bbc6f2

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

components/ballistics.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
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
1718
from utilities.game import (
1819
ALGAE_MAX_DIAMETER,
1920
ALGAE_MIN_DIAMETER,
@@ -58,9 +59,17 @@ class BallisticsComponent:
5859
}
5960

6061
FLYWHEEL_ANGLE_LOOKUP = {
61-
ALGAE_MIN_DIAMETER: (math.radians(-10), math.radians(-15), math.radians(-25)),
62+
ALGAE_MIN_DIAMETER: (
63+
math.radians(-10) + WristComponent.COM_DIFFERENCE,
64+
math.radians(-15) + WristComponent.COM_DIFFERENCE,
65+
math.radians(-25) + WristComponent.COM_DIFFERENCE
66+
),
6267
# 16.5: (math.radians(-11.0), math.radians(-19), -25),
63-
ALGAE_MAX_DIAMETER: (math.radians(-10), math.radians(-15), math.radians(-25)),
68+
ALGAE_MAX_DIAMETER: (
69+
math.radians(-10) + WristComponent.COM_DIFFERENCE,
70+
math.radians(-15) + WristComponent.COM_DIFFERENCE,
71+
math.radians(-25) + WristComponent.COM_DIFFERENCE
72+
),
6473
}
6574
# fmt: on
6675
BALL_SIZES = list(FLYWHEEL_ANGLE_LOOKUP.keys())

components/wrist.py

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

2222

2323
class WristComponent:
24-
ENCODER_ZERO_OFFSET = 4.011863
25-
MAXIMUM_DEPRESSION = math.radians(-112.0)
26-
MAXIMUM_ELEVATION = math.radians(0)
27-
NEUTRAL_ANGLE = math.radians(-90.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
28+
NEUTRAL_ANGLE = math.radians(-90.0) + COM_DIFFERENCE
2829

2930
WRIST_MAX_VEL = math.radians(180.0)
3031
WRIST_MAX_ACC = math.radians(360.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 test_inclination(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
@@ -169,5 +178,9 @@ def execute(self) -> None:
169178
self.pid.calculate(self.inclination(), tracked_state.position) + ff
170179
)
171180

172-
self.wrist_ligament.setAngle(self.inclination_deg())
181+
self.wrist_ligament.setAngle(
182+
self.inclination_deg() - math.degrees(WristComponent.COM_DIFFERENCE)
183+
)
184+
185+
self.wrist_COM_ligament.setAngle(self.inclination_deg())
173186
# self.wrist_ligament.setAngle(math.degrees(desired_state.position))

controllers/algae_shooter.py

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

23-
SHOOT_ANGLE = tunable(-50.0)
23+
SHOOT_ANGLE = tunable(-50.0 + math.degrees(WristComponent.COM_DIFFERENCE))
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
29+
2830
def __init__(self) -> None:
2931
pass
3032

@@ -44,7 +46,7 @@ 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(self.MEASURING_ANGLE)
4850

4951
self.next_state(self.preparing)
5052

controllers/floor_intake.py

Lines changed: 1 addition & 1 deletion
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))
17+
HANDOFF_POSITION = tunable(math.radians(-112.0) + WristComponent.COM_DIFFERENCE)
1818

1919
def __init__(self):
2020
self.intake_upper = False

controllers/reef_intake.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,13 @@ 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(
76+
math.radians(self.L3_INTAKE_ANGLE) + WristComponent.COM_DIFFERENCE
77+
)
7678
else:
77-
self.wrist.tilt_to(math.radians(self.L2_INTAKE_ANGLE))
79+
self.wrist.tilt_to(
80+
math.radians(self.L2_INTAKE_ANGLE) + WristComponent.COM_DIFFERENCE
81+
)
7882
self.last_l3 = current_is_L3
7983

8084
if not self.holding_coral:

0 commit comments

Comments
 (0)