Skip to content

Commit 04f705f

Browse files
authored
MotorSet off() vs stop() (#563)
For issue #540
1 parent 0d60fca commit 04f705f

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

debian/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
python-ev3dev2 (2.0.0~beta3) stable; urgency=medium
22

33
[Daniel Walton]
4+
* Moved MoveTank.off() to MotorSet
45
* cache attributes that never change
56
* Display: correct xy variable names passed to Display.rectangle()
67
* GyroSensor wait_until_angle_changed_by added direction_sensitive option

ev3dev2/control/rc_tank.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ def main(self):
4343
# Exit cleanly so that all motors are stopped
4444
except (KeyboardInterrupt, Exception) as e:
4545
log.exception(e)
46-
self.stop()
46+
self.off()

ev3dev2/motor.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,12 +1688,26 @@ def reset(self, motors=None):
16881688
for motor in motors:
16891689
motor.reset()
16901690

1691-
def stop(self, motors=None):
1691+
def off(self, motors=None, brake=True):
1692+
"""
1693+
Stop motors immediately. Configure motors to brake if ``brake`` is set.
1694+
"""
16921695
motors = motors if motors is not None else self.motors.values()
16931696

1697+
for motor in motors:
1698+
motor._set_brake(brake)
1699+
16941700
for motor in motors:
16951701
motor.stop()
16961702

1703+
def stop(self, motors=None, brake=True):
1704+
"""
1705+
``stop`` is an alias of ``off``. This is deprecated but helps keep
1706+
the API for MotorSet somewhat similar to Motor which has both ``stop``
1707+
and ``off``.
1708+
"""
1709+
self.off(motors, brake)
1710+
16971711
def _is_state(self, motors, state):
16981712
motors = motors if motors is not None else self.motors.values()
16991713

@@ -1899,16 +1913,6 @@ def on(self, left_speed, right_speed):
18991913
self.left_motor.run_forever()
19001914
self.right_motor.run_forever()
19011915

1902-
def off(self, brake=True):
1903-
"""
1904-
Stop both motors immediately. Configure both to brake if ``brake`` is
1905-
set.
1906-
"""
1907-
self.left_motor._set_brake(brake)
1908-
self.right_motor._set_brake(brake)
1909-
self.left_motor.stop()
1910-
self.right_motor.stop()
1911-
19121916

19131917
class MoveSteering(MoveTank):
19141918
"""

0 commit comments

Comments
 (0)