Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
python-ev3dev2 (2.0.0~beta3) stable; urgency=medium

* MoveJoyStick should use SpeedPercent
* renamed GyroSensor rate_and_angle to angle_and_rate

-- Kaelin Laundry <wasabifan@outlook.com> Sat, 27 Oct 2018 21:18:00 -0700
Expand Down
2 changes: 1 addition & 1 deletion ev3dev2/control/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def do_GET(self):

if joystick_engaged:
if seq > max_move_xy_seq:
self.robot.on(x, y, motor_max_speed)
self.robot.on(x, y)
max_move_xy_seq = seq
log.debug("seq %d: (x, y) (%4d, %4d)" % (seq, x, y))
else:
Expand Down
11 changes: 4 additions & 7 deletions ev3dev2/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1929,7 +1929,7 @@ class MoveJoystick(MoveTank):
Used to control a pair of motors via a single joystick vector.
"""

def on(self, x, y, max_speed=100.0, radius=100.0):
def on(self, x, y, radius=100.0):
"""
Convert x,y joystick coordinates to left/right motor speed percentages
and move the motors.
Expand All @@ -1944,13 +1944,9 @@ def on(self, x, y, max_speed=100.0, radius=100.0):
The X and Y coordinates of the joystick's position, with
(0,0) representing the center position. X is horizontal and Y is vertical.
max_speed (default 100%):
A percentage or other SpeedValue, controlling the maximum motor speed.
radius (default 100):
The radius of the joystick, controlling the range of the input (x, y) values.
e.g. if "x" and "y" can be between -1 and 1, radius should be set to "1".
"""

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

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)))

MoveTank.on(self,
SpeedPercent(left_speed_percentage),
SpeedPercent(right_speed_percentage))

@staticmethod
def angle_to_speed_percentage(angle):
Expand Down
6 changes: 4 additions & 2 deletions tests/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,12 @@ def test_joystick_units(self):
populate_arena([('large_motor', 0, 'outA'), ('large_motor', 1, 'outB')])

drive = MoveJoystick(OUTPUT_A, OUTPUT_B)
drive.on(100, 100, max_speed=SpeedPercent(50))

# With the joystick at (x, y) of (0, 50) we should drive straigh ahead
# at 50% of max_speed
drive.on(0, 50)
self.assertEqual(drive.left_motor.speed_sp, 1050 / 2)
self.assertAlmostEqual(drive.right_motor.speed_sp, 0)
self.assertEqual(drive.right_motor.speed_sp, 1050 / 2)

def test_units(self):
clean_arena()
Expand Down