mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Merge pull request #96 from waveform80/pwm-toggle-motor-reverse
Fix #91
This commit is contained in:
@@ -360,6 +360,16 @@ class Robot(SourceMixin, CompositeDevice):
|
|||||||
self._left.forward(speed)
|
self._left.forward(speed)
|
||||||
self._right.backward(speed)
|
self._right.backward(speed)
|
||||||
|
|
||||||
|
def reverse(self):
|
||||||
|
"""
|
||||||
|
Reverse the robot's current motor directions. If the robot is currently
|
||||||
|
running full speed forward, it will run full speed backward. If the
|
||||||
|
roboto is turning left at half-speed, it will turn right at half-speed.
|
||||||
|
If the robot is currently stopped it will remain stopped.
|
||||||
|
"""
|
||||||
|
self._left.value = -self._left.value
|
||||||
|
self._right.value = -self._right.value
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
"""
|
"""
|
||||||
Stop the robot.
|
Stop the robot.
|
||||||
|
|||||||
@@ -255,6 +255,15 @@ class PWMOutputDevice(DigitalOutputDevice):
|
|||||||
self._stop_blink()
|
self._stop_blink()
|
||||||
self._write(value)
|
self._write(value)
|
||||||
|
|
||||||
|
def toggle(self):
|
||||||
|
"""
|
||||||
|
Toggle the state of the device. If the device is currently off
|
||||||
|
(`value` is 0.0), this changes it to "fully" on (`value` is 1.0). If
|
||||||
|
the device has a duty cycle (`value`) of 0.1, this will toggle it to
|
||||||
|
0.9, and so on.
|
||||||
|
"""
|
||||||
|
self.value = 1.0 - self.value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_active(self):
|
def is_active(self):
|
||||||
"""
|
"""
|
||||||
@@ -414,6 +423,14 @@ class Motor(SourceMixin, CompositeDevice):
|
|||||||
self._forward.off()
|
self._forward.off()
|
||||||
self._backward.value = speed
|
self._backward.value = speed
|
||||||
|
|
||||||
|
def reverse(self):
|
||||||
|
"""
|
||||||
|
Reverse the current direction of the motor. If the motor is currently
|
||||||
|
idle this does nothing. Otherwise, the motor's direction will be
|
||||||
|
reversed at the current speed.
|
||||||
|
"""
|
||||||
|
self.value = -self.value
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
"""
|
"""
|
||||||
Stop the motor
|
Stop the motor
|
||||||
|
|||||||
Reference in New Issue
Block a user