Mercurial > maestro-servo
changeset 16:0cb3f825183e
Allow to specify servo center
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Wed, 25 Jun 2014 16:19:14 +0200 |
| parents | 083ca25d82a2 |
| children | 39f631544ede |
| files | maestro.py |
| diffstat | 1 files changed, 10 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/maestro.py Wed Jun 25 16:15:17 2014 +0200 +++ b/maestro.py Wed Jun 25 16:19:14 2014 +0200 @@ -76,7 +76,8 @@ min_position = 3968 max_position = 8064 - def __init__(self, maestro, index, max_degrees=90, reverse=False): + def __init__(self, maestro, index, center=None, + max_degrees=90, reverse=False): self.maestro = maestro self.index = index self.reverse = reverse @@ -84,6 +85,11 @@ self._angle = 0 self._speed = 0 self._accel = 0 + self.width = self.max_position - self.min_position + if self.center is None: + self.center = self.min_position + self.width / 2 + else: + self.center = center @property def angle(self): @@ -92,12 +98,10 @@ @angle.setter def angle(self, degrees): self._angle = degrees - width = self.max_position - self.min_position - position = (width * degrees) / self.max_degrees + position = (self.width * degrees) / self.max_degrees if self.reverse: position = -position - center = self.min_position + width / 2 - target = center + position + target = self.center + position target = min(self.max_position, max(self.min_position, target)) self.maestro.set_target(self.index, target) @@ -108,8 +112,7 @@ @speed.setter def speed(self, degrees_per_second): self._speed = degrees_per_second - width = self.max_position - self.min_position - speed = self.max_degrees / (width * degrees_per_second) + speed = self.max_degrees / (self.width * degrees_per_second) self.maestro.set_speed(self.index, speed) @property
