From 0f97678a7831b3666a8a3e85d21fee9e5df754fc Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 3 Mar 2018 03:24:08 +0100 Subject: [PATCH] Throttling power --- platypush/plugins/gpio/zeroborg/__init__.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/platypush/plugins/gpio/zeroborg/__init__.py b/platypush/plugins/gpio/zeroborg/__init__.py index b00b402180..e97ef3e8d3 100644 --- a/platypush/plugins/gpio/zeroborg/__init__.py +++ b/platypush/plugins/gpio/zeroborg/__init__.py @@ -41,6 +41,7 @@ class GpioZeroborgPlugin(Plugin): self.v_out = v_out self.max_power = v_out / float(v_in) self.auto_mode = False + self._direction = None self.zb = ZeroBorg.ZeroBorg() self.zb.Init() @@ -57,6 +58,8 @@ class GpioZeroborgPlugin(Plugin): def drive(self, direction): + prev_direction = self._direction + self._can_run = True self._direction = direction.lower() logging.info('Received ZeroBorg drive command: {}'.format(direction)) @@ -74,10 +77,11 @@ class GpioZeroborgPlugin(Plugin): while distance is None: distance = self.get_distance() - print(distance) if distance > 250.0: # distance in mm self._direction = Direction.DIR_UP.value else: + logging.info('Physical obstacle detected at {} mm'. + format(distance)) self._direction = Direction.DIR_LEFT.value time.sleep(0.1) @@ -98,10 +102,12 @@ class GpioZeroborgPlugin(Plugin): logging.warning('Invalid direction: {}'.format(direction)) self.stop() - self.zb.SetMotor1(left * self.max_power) - self.zb.SetMotor2(left * self.max_power) - self.zb.SetMotor3(-right * self.max_power) - self.zb.SetMotor4(-right * self.max_power) + power = 0.6 # Still debugging the right power range + + self.zb.SetMotor1(power * left * self.max_power) + self.zb.SetMotor2(power * left * self.max_power) + self.zb.SetMotor3(power * -right * self.max_power) + self.zb.SetMotor4(power * -right * self.max_power) self.auto_mode = False