Skip to content

Commit 083a6d2

Browse files
committed
physics: Simulate algae interaction using physical properties
1 parent d0070e2 commit 083a6d2

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

physics.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ def __init__(self, physics_controller: PhysicsInterface, robot: MyRobot):
180180

181181
self.imu = robot.chassis.imu.sim_state
182182

183+
self.injector = rev.SparkMaxSim(
184+
robot.injector_component.injector_1, DCMotor.NEO550(1)
185+
)
186+
183187
self.vision_sim = VisionSystemSim("main")
184188
self.vision_sim.addAprilTags(game.apriltag_layout)
185189
properties = SimCameraProperties.OV9281_1280_720()
@@ -199,9 +203,6 @@ def __init__(self, physics_controller: PhysicsInterface, robot: MyRobot):
199203
robot.injector_component.algae_limit_switch
200204
)
201205
self.algae_pickup_counter = 0
202-
self.floor_intake = robot.floor_intake
203-
self.reef_intake = robot.reef_intake
204-
self.algae_shooter = robot.algae_shooter
205206

206207
def update_sim(self, now: float, tm_diff: float) -> None:
207208
# Enable the Phoenix6 simulated devices
@@ -251,25 +252,35 @@ def update_sim(self, now: float, tm_diff: float) -> None:
251252

252253
# Update intake arm simulation
253254
self.intake_arm.update(tm_diff)
255+
intake_arm_angle = self.intake_arm.mech_sim.getAngle()
254256
self.intake_arm_encoder_sim.set(
255-
self.intake_arm.mech_sim.getAngle() + IntakeComponent.ARM_ENCODER_OFFSET
257+
intake_arm_angle + IntakeComponent.ARM_ENCODER_OFFSET
256258
)
257259

258260
# Update wrist simulation
259261
self.wrist.update(tm_diff)
260-
self.wrist_encoder_sim.set(
261-
self.wrist.mech_sim.getAngle() + WristComponent.ENCODER_ZERO_OFFSET
262-
)
262+
wrist_angle = self.wrist.mech_sim.getAngle()
263+
self.wrist_encoder_sim.set(wrist_angle + WristComponent.ENCODER_ZERO_OFFSET)
263264

265+
injector_output = self.injector.getAppliedOutput()
264266
# Simulate algae pick up
265-
if self.floor_intake.current_state == "intaking":
267+
if (
268+
wrist_angle < WristComponent.NEUTRAL_ANGLE
269+
and intake_arm_angle < IntakeComponent.RETRACTED_ANGLE
270+
and injector_output < 0
271+
):
266272
# Simulate driving around for a couple of seconds
267273
self.algae_pickup_counter += 1
268274
if self.algae_pickup_counter == 100:
269275
self.algae_limit_switch_sim.setValue(False)
270276
else:
271277
self.algae_pickup_counter = 0
272-
if self.reef_intake.current_state == "intaking":
278+
279+
# Reef intake
280+
if (
281+
wrist_angle > WristComponent.NEUTRAL_ANGLE + WristComponent.TOLERANCE
282+
and injector_output < 0
283+
):
273284
# Check near reef
274285
pose = self.physics_controller.get_pose()
275286
pos = pose.translation()
@@ -278,6 +289,7 @@ def update_sim(self, now: float, tm_diff: float) -> None:
278289
or pos.distance(game.RED_REEF_POS) < 2.0
279290
):
280291
self.algae_limit_switch_sim.setValue(False)
292+
281293
# Algae shooting
282-
if self.algae_shooter.current_state == "shooting":
294+
if injector_output > 0:
283295
self.algae_limit_switch_sim.setValue(True)

0 commit comments

Comments
 (0)