Skip to content

Commit 79eac1c

Browse files
committed
physics: Add intake arm sim
1 parent 421edf7 commit 79eac1c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

physics.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from wpimath.units import kilogram_square_meters
2323

2424
from components.chassis import SwerveModule
25+
from components.intake import IntakeComponent
2526
from components.wrist import WristComponent
2627
from utilities import game
2728
from utilities.functions import constrain_angle
@@ -139,6 +140,28 @@ def __init__(self, physics_controller: PhysicsInterface, robot: MyRobot):
139140
),
140141
]
141142

143+
# Intake arm simulation
144+
intake_arm_gearbox = DCMotor.NEO(1)
145+
self.intake_arm_motor = rev.SparkMaxSim(
146+
robot.intake_component.arm_motor, intake_arm_gearbox
147+
)
148+
self.intake_arm_encoder_sim = DutyCycleEncoderSim(
149+
robot.intake_component.encoder
150+
)
151+
self.intake_arm = SparkArmSim(
152+
SingleJointedArmSim(
153+
intake_arm_gearbox,
154+
IntakeComponent.gear_ratio,
155+
moi=0.035579622,
156+
armLength=0.22,
157+
minAngle=IntakeComponent.DEPLOYED_ANGLE,
158+
maxAngle=IntakeComponent.RETRACTED_ANGLE,
159+
simulateGravity=True,
160+
startingAngle=IntakeComponent.RETRACTED_ANGLE,
161+
),
162+
self.intake_arm_motor,
163+
)
164+
142165
wrist_gearbox = DCMotor.NEO(1)
143166
wrist_motor = rev.SparkMaxSim(robot.wrist.motor, wrist_gearbox)
144167
self.wrist_encoder_sim = AnalogEncoderSim(robot.wrist.wrist_encoder)
@@ -228,6 +251,10 @@ def update_sim(self, now: float, tm_diff: float) -> None:
228251
self.vision_sim.update(self.physics_controller.get_pose())
229252
self.vision_sim_counter = 0
230253

254+
# Update intake arm simulation
255+
self.intake_arm.update(tm_diff)
256+
self.intake_arm_encoder_sim.set(self.intake_arm.mech_sim.getAngle())
257+
231258
# Update wrist simulation
232259
self.wrist.update(tm_diff)
233260
self.wrist_encoder_sim.set(

0 commit comments

Comments
 (0)