Skip to content

Commit ec02595

Browse files
add check for servo control
If an unregistered servo is called to control when the state machine is not active the processor appears to hang. Better to throw and let the programmer know they did a thing that is a bit silly.
1 parent 6f000ef commit ec02595

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

PicoAutonomousRobotics.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ def _servo_pwm():
8787

8888
#doesnt actually register/unregister, just stops and starts the servo PIO
8989
def registerServo(self,servo):
90-
self.servos[servo].active(1)
90+
if(not self.servos[servo].active()):
91+
self.servos[servo].active(1)
9192
def deregisterServo(self, servo):
92-
self.servos[servo].active(0)
93+
if(self.servos[servo].active()):
94+
self.servos[servo].active(0)
9395

9496
# goToPosition takes a degree position for the serov to goto.
9597
# 0degrees->180 degrees is 0->2000us, plus offset of 500uS
@@ -104,7 +106,11 @@ def goToPeriod(self,servo, period):
104106
period = 500
105107
if(period >2500):
106108
period =2500
107-
self.servos[servo].put(period)
109+
#check if servo SM is active, otherwise we are trying to control a thing we do not have control over
110+
if self.servos[servo].active():
111+
self.servos[servo].put(period)
112+
else:
113+
raise Exception("TRYING TO CONTROL UNREGISTERED SERVO") #harsh, but at least you'll know
108114

109115
def _initServos(self):
110116
servoPins = [21,10,17,11]

0 commit comments

Comments
 (0)