Skip to content

Commit ae97053

Browse files
authored
MoveJoyStick should use SpeedPercent (#537)
1 parent fb7b79d commit ae97053

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

debian/changelog

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

3+
* MoveJoyStick should use SpeedPercent
34
* renamed GyroSensor rate_and_angle to angle_and_rate
45

56
-- Kaelin Laundry <wasabifan@outlook.com> Sat, 27 Oct 2018 21:18:00 -0700

ev3dev2/control/webserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def do_GET(self):
209209

210210
if joystick_engaged:
211211
if seq > max_move_xy_seq:
212-
self.robot.on(x, y, motor_max_speed)
212+
self.robot.on(x, y)
213213
max_move_xy_seq = seq
214214
log.debug("seq %d: (x, y) (%4d, %4d)" % (seq, x, y))
215215
else:

ev3dev2/motor.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,7 @@ class MoveJoystick(MoveTank):
19291929
Used to control a pair of motors via a single joystick vector.
19301930
"""
19311931

1932-
def on(self, x, y, max_speed=100.0, radius=100.0):
1932+
def on(self, x, y, radius=100.0):
19331933
"""
19341934
Convert x,y joystick coordinates to left/right motor speed percentages
19351935
and move the motors.
@@ -1944,13 +1944,9 @@ def on(self, x, y, max_speed=100.0, radius=100.0):
19441944
The X and Y coordinates of the joystick's position, with
19451945
(0,0) representing the center position. X is horizontal and Y is vertical.
19461946
1947-
max_speed (default 100%):
1948-
A percentage or other SpeedValue, controlling the maximum motor speed.
1949-
19501947
radius (default 100):
19511948
The radius of the joystick, controlling the range of the input (x, y) values.
19521949
e.g. if "x" and "y" can be between -1 and 1, radius should be set to "1".
1953-
19541950
"""
19551951

19561952
# If joystick is in the middle stop the tank
@@ -1987,8 +1983,9 @@ def on(self, x, y, max_speed=100.0, radius=100.0):
19871983
# init_left_speed_percentage, init_right_speed_percentage,
19881984
# left_speed_percentage, right_speed_percentage))
19891985

1990-
MoveTank.on(self, SpeedNativeUnits(left_speed_percentage / 100 * self.left_motor._speed_native_units(max_speed)), SpeedNativeUnits(right_speed_percentage / 100 * self.right_motor._speed_native_units(max_speed)))
1991-
1986+
MoveTank.on(self,
1987+
SpeedPercent(left_speed_percentage),
1988+
SpeedPercent(right_speed_percentage))
19921989

19931990
@staticmethod
19941991
def angle_to_speed_percentage(angle):

tests/api_tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,12 @@ def test_joystick_units(self):
316316
populate_arena([('large_motor', 0, 'outA'), ('large_motor', 1, 'outB')])
317317

318318
drive = MoveJoystick(OUTPUT_A, OUTPUT_B)
319-
drive.on(100, 100, max_speed=SpeedPercent(50))
320319

320+
# With the joystick at (x, y) of (0, 50) we should drive straigh ahead
321+
# at 50% of max_speed
322+
drive.on(0, 50)
321323
self.assertEqual(drive.left_motor.speed_sp, 1050 / 2)
322-
self.assertAlmostEqual(drive.right_motor.speed_sp, 0)
324+
self.assertEqual(drive.right_motor.speed_sp, 1050 / 2)
323325

324326
def test_units(self):
325327
clean_arena()

0 commit comments

Comments
 (0)