Skip to content

Commit b25637f

Browse files
authored
Improve clarity of motor docs (#489)
1 parent 10776f6 commit b25637f

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

README.rst

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ trying this out.
9595
else:
9696
leds.set_color(leds.led_groups.LEFT, leds.led_colors.RED)
9797
98-
Running a motor
99-
~~~~~~~~~~~~~~~
98+
Running a single motor
99+
~~~~~~~~~~~~~~~~~~~~~~
100100

101101
This will run a LEGO Large Motor at 75% of maximum speed for 5 rotations.
102102

@@ -109,8 +109,8 @@ You can also run a motor for a number of degrees, an amount of time, or simply
109109
start it and let it run until you tell it to stop. Additionally, other units are
110110
also available. See the following pages for more information:
111111

112-
- http://python-ev3dev.readthedocs.io/en/stretch/motors.html#ev3dev.motor.Motor.on_for_degrees
113-
- http://python-ev3dev.readthedocs.io/en/stretch/motors.html#units
112+
- http://python-ev3dev.readthedocs.io/en/ev3dev-stretch/motors.html#ev3dev.motor.Motor.on_for_degrees
113+
- http://python-ev3dev.readthedocs.io/en/ev3dev-stretch/motors.html#units
114114

115115
Driving with two motors
116116
~~~~~~~~~~~~~~~~~~~~~~~
@@ -119,17 +119,20 @@ The simplest drive control style is with the `MoveTank` class:
119119

120120
.. code-block:: python
121121
122-
drive = MoveTank(OUTPUT_A, OUTPUT_B)
122+
tank_drive = MoveTank(OUTPUT_A, OUTPUT_B)
123123
124124
# drive in a turn for 5 rotations of the outer motor
125-
# the first two parameters are percentages; they can also be unit classes.
126-
drive.on_for_rotations(50, 75, 10)
125+
# the first two parameters can be unit classes or percentages.
126+
tank_drive.on_for_rotations(SpeedPercent(50), SpeedPercent(75), 10)
127127
128-
# drive in a different turn for 3 rotations of the outer motor
129-
drive.on_for_rotations(60, 30, 3)
128+
# drive in a different turn for 3 seconds
129+
tank_drive.on_for_seconds(SpeedPercent(60), SpeedPercent(30), 3)
130130
131131
There are also `MoveSteering` and `MoveJoystick` classes which provide different
132-
styles of control. Take a look at the corresponding documentation for more detail.
132+
styles of control. See the following pages for more information:
133+
134+
- http://python-ev3dev.readthedocs.io/en/ev3dev-stretch/motors.html#multiple-motor-groups
135+
- http://python-ev3dev.readthedocs.io/en/ev3dev-stretch/motors.html#units
133136

134137
Using text-to-speech
135138
~~~~~~~~~~~~~~~~~~~~

docs/motors.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Motor classes
1010
Units
1111
-----
1212

13-
Most methods which run motors with accept a ``speed_pct`` argument. While this can be provided as an integer which will be interpreted as a percentage of max speed, you can also specify an instance of any of the following classes, each of which represents a different unit system:
13+
Most methods which run motors with accept a ``speed`` or ``speed_pct`` argument. While this can be provided as an integer which will be interpreted as a percentage of max speed, you can also specify an instance of any of the following classes, each of which represents a different unit system:
1414

1515
.. autoclass:: SpeedInteger
1616
.. autoclass:: SpeedPercent

ev3dev2/motor.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,9 +1695,9 @@ class MoveTank(MotorSet):
16951695
16961696
.. code:: python
16971697
1698-
drive = MoveTank(OUTPUT_A, OUTPUT_B)
1698+
tank_drive = MoveTank(OUTPUT_A, OUTPUT_B)
16991699
# drive in a turn for 10 rotations of the outer motor
1700-
drive.on_for_rotations(50, 75, 10)
1700+
tank_drive.on_for_rotations(50, 75, 10)
17011701
"""
17021702

17031703
def __init__(self, left_motor_port, right_motor_port, desc=None, motor_class=LargeMotor):
@@ -1847,17 +1847,19 @@ class MoveSteering(MoveTank):
18471847
Controls a pair of motors simultaneously, via a single "steering" value.
18481848
18491849
steering [-100, 100]:
1850-
* -100 means turn left as fast as possible,
1850+
* -100 means turn left on the spot (right motor at 100% forward, left motor at 100% backward),
18511851
* 0 means drive in a straight line, and
1852-
* 100 means turn right as fast as possible.
1852+
* 100 means turn right on the spot (left motor at 100% forward, right motor at 100% backward).
18531853
1854+
"steering" can be any number between -100 and 100.
1855+
18541856
Example:
18551857
18561858
.. code:: python
18571859
1858-
drive = MoveSteering(OUTPUT_A, OUTPUT_B)
1860+
steering_drive = MoveSteering(OUTPUT_A, OUTPUT_B)
18591861
# drive in a turn for 10 rotations of the outer motor
1860-
drive.on_for_rotations(-20, 75, 10)
1862+
steering_drive.on_for_rotations(-20, 75, 10)
18611863
"""
18621864
def on_for_rotations(self, steering, speed_pct, rotations, brake=True, block=True):
18631865
"""
@@ -1899,9 +1901,9 @@ def get_speed_steering(self, steering, speed_pct):
18991901
afterwards to make the motors move.
19001902
19011903
steering [-100, 100]:
1902-
* -100 means turn left as fast as possible,
1904+
* -100 means turn left on the spot (right motor at 100% forward, left motor at 100% backward),
19031905
* 0 means drive in a straight line, and
1904-
* 100 means turn right as fast as possible.
1906+
* 100 means turn right on the spot (left motor at 100% forward, right motor at 100% backward).
19051907
19061908
speed_pct:
19071909
The speed that should be applied to the outmost motor (the one
@@ -1939,7 +1941,25 @@ class MoveJoystick(MoveTank):
19391941
def on(self, x, y, max_speed, radius=100.0):
19401942
"""
19411943
Convert x,y joystick coordinates to left/right motor speed percentages
1942-
and move the motors
1944+
and move the motors.
1945+
1946+
This will use a classic "arcade drive" algorithm: a full-forward joystick
1947+
goes straight forward and likewise for full-backward. Pushing the joystick
1948+
all the way to one side will make it turn on the spot in that direction.
1949+
Positions in the middle will control how fast the vehicle moves and how
1950+
sharply it turns.
1951+
1952+
"x", "y":
1953+
The X and Y coordinates of the joystick's position, with
1954+
(0,0) representing the center position. X is horizontal and Y is vertical.
1955+
1956+
max_speed (default 100%):
1957+
A percentage or other SpeedInteger, controlling the maximum motor speed.
1958+
1959+
radius (default 100):
1960+
The radius of the joystick, controlling the range of the input (x, y) values.
1961+
e.g. if "x" and "y" can be between -1 and 1, radius should be set to "1".
1962+
19431963
"""
19441964

19451965
# If joystick is in the middle stop the tank

0 commit comments

Comments
 (0)