Skip to content

Commit 056f721

Browse files
authored
Fix call to "off" when MoveJoystick.on is called with joystick centered (#578)
* Fix call to "off" when MoveJoystick.on is called with joystick centered Fixes #575
1 parent 5536725 commit 056f721

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

ev3dev2/motor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2214,7 +2214,7 @@ def on(self, x, y, radius=100.0):
22142214

22152215
# If joystick is in the middle stop the tank
22162216
if not x and not y:
2217-
MoveTank.off()
2217+
self.off()
22182218
return
22192219

22202220
vector_length = sqrt(x*x + y*y)

tests/api_tests.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def test_steering_large_value(self):
316316
self.assertEqual(drive.right_motor.position_sp, 10 * 360)
317317
self.assertEqual(drive.right_motor.speed_sp, 400)
318318

319-
def test_joystick_units(self):
319+
def test_joystick(self):
320320
clean_arena()
321321
populate_arena([('large_motor', 0, 'outA'), ('large_motor', 1, 'outB')])
322322

@@ -327,6 +327,13 @@ def test_joystick_units(self):
327327
drive.on(0, 50)
328328
self.assertEqual(drive.left_motor.speed_sp, 1050 / 2)
329329
self.assertEqual(drive.right_motor.speed_sp, 1050 / 2)
330+
self.assertEqual(drive.left_motor._get_attribute(None, 'command')[1], 'run-forever')
331+
self.assertEqual(drive.right_motor._get_attribute(None, 'command')[1], 'run-forever')
332+
333+
# With the joystick centered, motors should both be stopped
334+
drive.on(0, 0)
335+
self.assertEqual(drive.left_motor._get_attribute(None, 'command')[1], 'stop')
336+
self.assertEqual(drive.right_motor._get_attribute(None, 'command')[1], 'stop')
330337

331338
def test_units(self):
332339
clean_arena()

0 commit comments

Comments
 (0)