-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathhat_servo.py
More file actions
26 lines (20 loc) · 795 Bytes
/
hat_servo.py
File metadata and controls
26 lines (20 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import time
from generic_servo import Servo
class HatServo(Servo):
def __init__(self, name, hat_func, alternate, secs_per_180, pix_per_degree):
super(HatServo, self).__init__(name, alternate, secs_per_180, pix_per_degree)
self.__hat_func = hat_func
self.__currpos = None
self.jiggle()
def jiggle(self):
# Provoke an update from the color tracker
self.set_angle(80, pause=.1)
self.set_angle(90, pause=.1)
def get_currpos(self):
return self.__currpos
def set_angle(self, val, pause=None):
# Pan Tilt Hat servo takes value -90 to 90. pyFirmata servo takes 0 - 180. So adjust here
self.__hat_func(val - 90)
if pause is not None:
time.sleep(pause)
self.__currpos = val