Skip to content

Commit 3a060a5

Browse files
authored
Merge pull request #225 from thedropbears/coral-placer-new
Coral placer new
2 parents 83c70d0 + 516b797 commit 3a060a5

File tree

3 files changed

+61
-12
lines changed

3 files changed

+61
-12
lines changed

autonomous/auto_base.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,14 @@ def tracking_trajectory(self, initial_call, state_tm) -> None:
100100
distance = current_pose.translation().distance(final_pose.translation())
101101
angle_error = (final_pose.rotation() - current_pose.rotation()).radians()
102102

103-
if self.current_leg > 0 and not self.injector_component.has_algae():
103+
if self.current_leg == 0:
104+
self.coral_placer.lift()
105+
106+
if (
107+
self.current_leg > 0
108+
and not self.injector_component.has_algae()
109+
and not self.coral_placer.is_executing
110+
):
104111
self.reef_intake.intake()
105112

106113
if distance < self.DISTANCE_TOLERANCE and math.isclose(
@@ -144,7 +151,7 @@ def driving_to_coral(self) -> None:
144151
def scoring_coral(self, initial_call: bool) -> None:
145152
if initial_call:
146153
self.coral_placer.place()
147-
elif not self.coral_placer.is_executing:
154+
elif self.coral_placer.coral_is_scored():
148155
self.next_state("retreating")
149156

150157
@state

controllers/coral_placer.py

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,57 @@
1-
from magicbot import StateMachine, timed_state
1+
import math
22

3-
from components.coral_placer import CoralPlacerComponent
3+
from magicbot import StateMachine, state, tunable
4+
5+
from components.chassis import ChassisComponent
6+
from components.wrist import WristComponent
47

58

69
class CoralPlacer(StateMachine):
7-
coral_placer_component: CoralPlacerComponent
10+
wrist: WristComponent
11+
chassis: ChassisComponent
12+
13+
# In degrees for tuning, converted to radians in tilt-to call
14+
CORAL_PLACE_ANGLE = tunable(0.0)
15+
CORAL_LOWER_ANGLE = tunable(-20.0)
16+
17+
RETREAT_DISTANCE = tunable(0.2)
818

919
def __init__(self):
10-
pass
20+
self.coral_scored = False
1121

12-
def place(self):
22+
def place(self) -> None:
23+
self.engage("lowering", force=True)
24+
25+
def lift(self) -> None:
1326
self.engage()
1427

15-
@timed_state(duration=2.0, first=True, must_finish=True)
16-
def placing(self):
17-
self.coral_placer_component.place()
28+
def coral_is_scored(self) -> bool:
29+
return self.coral_scored
30+
31+
@state(first=True, must_finish=True)
32+
def raising(self, initial_call: bool) -> None:
33+
if initial_call:
34+
self.coral_scored = False
35+
self.wrist.tilt_to(math.radians(self.CORAL_PLACE_ANGLE))
36+
37+
@state(must_finish=True)
38+
def lowering(self, initial_call: bool) -> None:
39+
if initial_call:
40+
self.wrist.tilt_to(math.radians(self.CORAL_LOWER_ANGLE))
41+
if self.wrist.at_setpoint():
42+
self.coral_scored = True
43+
self.next_state("safing")
44+
45+
@state(must_finish=True)
46+
def safing(self, initial_call: bool) -> None:
47+
if initial_call:
48+
self.score_pos = self.chassis.get_pose()
49+
50+
current_pose = self.chassis.get_pose()
51+
52+
distance = self.score_pos.translation().distance(current_pose.translation())
53+
54+
if distance >= self.RETREAT_DISTANCE:
55+
self.wrist.go_to_neutral()
56+
self.done()
57+
return

robot.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ def testPeriodic(self) -> None:
252252
if self.gamepad.getRightTriggerAxis() > 0.5:
253253
self.algae_shooter.shoot()
254254
if self.gamepad.getAButton():
255-
self.climber.deploy()
255+
self.coral_placer.place()
256+
if self.gamepad.getXButton():
257+
self.coral_placer.lift()
256258

257259
if self.gamepad.getLeftBumperButton():
258260
self.reef_intake.intake()
@@ -275,7 +277,7 @@ def testPeriodic(self) -> None:
275277
# Components
276278
self.chassis.execute()
277279
self.climber.execute()
278-
self.coral_placer_component.execute()
280+
# self.coral_placer_component.execute()
279281
self.shooter_component.execute()
280282
self.injector_component.execute()
281283
if self.gamepad.getStartButton():

0 commit comments

Comments
 (0)