11import math
22
3- from magicbot import StateMachine , state
3+ from magicbot import StateMachine , feedback , state
44
55from components .chassis import ChassisComponent
66from components .climber import ClimberComponent
@@ -15,33 +15,42 @@ class ClimberStateMachine(StateMachine):
1515
1616 def __init__ (self ):
1717 self .has_deployed = False
18+ self .seen_left = False
19+ self .seen_right = False
1820 self .heading_to_cage = 0.0
1921 self .should_localize = True
2022
2123 def on_disable (self ) -> None :
22- self .has_deployed = False
2324 super ().on_disable ()
2425
2526 def deploy (self , * , localize : bool = True ) -> None :
2627 self .should_localize = localize
28+ self .has_deployed = False
29+ self .seen_right = False
30+ self .seen_left = False
2731 self .engage ("deploying" , force = True )
2832
2933 def deploy_without_localization (self ) -> None :
3034 self .deploy (localize = False )
3135
3236 def retract (self ) -> None :
33- if self .has_deployed :
37+ if self .has_deployed and self . is_ready_to_climb () :
3438 self .engage ("retracting" , force = True )
3539
3640 @state (first = True , must_finish = True )
3741 def deploying (self , initial_call ) -> None :
38- self .status_lights .climber_deploying (
39- left_okay = self .climber .is_left_engaged (),
40- right_okay = self .climber .is_right_engaged (),
41- )
4242 if initial_call :
4343 self .climber .go_to_deploy ()
4444
45+ if self .climber .is_left_engaged ():
46+ self .seen_left = True
47+ if self .climber .is_right_engaged ():
48+ self .seen_right = True
49+ self .status_lights .climber_deploying (
50+ left_okay = self .seen_left ,
51+ right_okay = self .seen_right ,
52+ )
53+
4554 if self .climber .is_deployed ():
4655 self .climber .stop_pid_update ()
4756 self .has_deployed = True
@@ -65,21 +74,9 @@ def deploying(self, initial_call) -> None:
6574 )
6675 self .chassis .snap_to_heading (self .heading_to_cage )
6776
77+ @feedback
6878 def is_ready_to_climb (self ) -> bool :
69- return self .climber .is_left_engaged () and self .climber .is_right_engaged ()
70-
71- def pre_climb (self ) -> None :
72- self .engage ("pre_climbing" , force = True )
73-
74- @state (must_finish = True )
75- def pre_climbing (self ) -> None :
76- self .status_lights .climber_pre_climb (
77- left_okay = self .climber .is_left_engaged (),
78- right_okay = self .climber .is_right_engaged (),
79- )
80- self .climber .start_pid_update ()
81- self .chassis .stop_snapping ()
82- self .climber .go_to_pre_climb ()
79+ return self .seen_left and self .seen_right
8380
8481 @state (must_finish = True )
8582 def retracting (self ) -> None :
0 commit comments