api: flake8

This commit is contained in:
Laurens Valk
2019-06-04 15:45:36 +02:00
parent 0d3b682223
commit 8d37450fac
10 changed files with 307 additions and 122 deletions
+6 -4
View File
@@ -61,7 +61,8 @@ copyright = '2018-2019 The Pybricks MicroPython Authors'
author = ''
_TITLE = 'Pybricks Modules and Examples'
_DISCLAIMER = 'LEGO, the LEGO logo, MINDSTORMS and the MINDSTORMS EV3 logo are trademarks and/or copyrights of the LEGO Group.'
_DISCLAIMER = 'LEGO, the LEGO logo, MINDSTORMS and the MINDSTORMS EV3 logo are\
trademarks and/or copyrights of the LEGO Group.'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
@@ -108,8 +109,8 @@ numfig_format = {
autodoc_member_order = 'bysource'
autodoc_default_flags = ['members', 'undoc-members']
autoclass_content = 'both' # This ensures init arguments are not ignored but added to class docstring.
add_module_names = False # Hide module name
autoclass_content = 'both' # This ensures init arguments are not ignored
add_module_names = False # Hide module name
# -- Options for HTML output ----------------------------------------------
@@ -221,7 +222,8 @@ latex_elements = {
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, ''.join([project, '-v', version, '.tex']), _TITLE, author, 'manual'),
(master_doc, ''.join([project, '-v', version, '.tex']), _TITLE,
author, 'manual'),
]
latex_logo = '../common/images/pybricks-logo-large.png'
-1
View File
@@ -4,5 +4,4 @@
# Pybricks documentation build configuration file
#
import os
import sys
exec(open(os.path.abspath("../common/conf.py")).read())
-1
View File
@@ -4,5 +4,4 @@
# Pybricks documentation build configuration file
#
import os
import sys
exec(open(os.path.abspath("../common/conf.py")).read())
+205 -60
View File
@@ -1,4 +1,5 @@
"""Generic cross-platform module for typical hub devices like displays, speakers, and batteries."""
"""Generic cross-platform module for typical hub devices like displays,
speakers, and batteries."""
from parameters import Align, Direction, Stop
@@ -11,20 +12,38 @@ class Motor():
Arguments:
port (Port): Port to which the motor is connected.
direction (Direction): Positive speed direction (*Default*: Direction.CLOCKWISE).
gears (list): List of gears linked to the motor (*Default*: ``None``).
direction (Direction): Positive speed direction
(*Default*: `Direction.CLOCKWISE`).
gears (list):
List of gears linked to the motor (*Default*:``None``).
For example: ``[12, 36]`` represents a gear train with a 12-tooth and a 36-tooth gear. See :ref:`ratio` for illustrated examples.
Use a list of lists for multiple gear trains, such as ``[[12, 36], [20, 16, 40]]``.
For example: ``[12, 36]`` represents a gear train with a
12-tooth and a 36-tooth gear. See :ref:`ratio` for illustrated
examples.
When you specify a gear train, all motor commands and settings are automatically adjusted to account for the resulting gear ratio. The motor direction remains unchanged, no matter how many gears you choose.
Use a list of lists for multiple gear trains, such as
``[[12, 36], [20, 16, 40]]``.
For example, with ``gears=[12, 36]``, the gear ratio is 3, which means that the output is mechanically slowed down by a factor of 3. To compensate, the motor will automatically turn 3 times as fast and 3 times as far when you give a motor command. So when you choose ``run_angle(200, 90)``, your mechanism output simply turns at 200 deg/s for 90 degrees.
When you specify a gear train, all motor commands and settings
are automatically adjusted to account for the resulting gear
ratio. The motor direction remains unchanged, no matter how
many gears you choose.
The same holds for the documentation below: When it states "motor angle" or "motor speed", you can read this as "mechanism output angle" and "mechanism output speed", and so on, as the gear ratio is automatically accounted for.
For example, with ``gears=[12, 36]``, the gear ratio is 3,
which means that the output is mechanically slowed down by a
factor of 3. To compensate, the motor will automatically turn 3
times as fast and 3 times as far when you give a motor command.
So when you choose ``run_angle(200, 90)``, your mechanism
output simply turns at 200 deg/s for 90 degrees.
The ``gears`` setting is only available for motors with rotation sensors.
The same holds for the documentation below: When it states
"motor angle" or "motor speed", you can read this as "mechanism
output angle" and "mechanism output speed", and so on, as the
gear ratio is automatically accounted for.
The ``gears`` setting is only available for motors with
rotation sensors.
"""
pass
@@ -57,11 +76,19 @@ class Motor():
def stalled(self):
"""Check whether the motor is currently stalled.
A motor is stalled when it cannot move even with the maximum torque. For example, when something is blocking the motor or your mechanism simply cannot turn any further.
A motor is stalled when it cannot move even with the maximum torque.
For example, when something is blocking the motor or your mechanism
simply cannot turn any further.
Specifically, the motor is stalled when the duty cycle computed by the PID controllers has reached the maximum (so ``duty`` = ``duty_limit``) and still the motor cannot reach a minimal speed (so ``speed`` < ``stall_speed``) for a period of at least ``stall_time``.
Specifically, the motor is stalled when the duty cycle computed by the
PID controllers has reached the maximum (so ``duty`` = ``duty_limit``)
and still the motor cannot reach a minimal speed
(so ``speed`` < ``stall_speed``) for a period of at
least ``stall_time``.
You can change the ``duty_limit``, ``stall_speed``, and ``stall_time`` settings using :meth:`.set_dc_settings` and :meth:`.set_pid_settings` in order to change the sensitivity to being stalled.
You can change the ``duty_limit``, ``stall_speed``, and ``stall_time``
settings using :meth:`.set_dc_settings` and :meth:`.set_pid_settings`
in order to change the sensitivity to being stalled.
Returns:
bool: ``True`` if the motor is stalled, ``False`` if it is not.
@@ -83,14 +110,18 @@ class Motor():
Stop the motor.
Arguments:
stop_type (Stop): Whether to coast, brake, or hold (*Default*: :class:`Stop.COAST <parameters.Stop>`).
stop_type (Stop): Whether to coast, brake, or hold (*Default*:
:class:`Stop.COAST <parameters.Stop>`).
"""
pass
def run(self, speed):
"""Keep the motor running at a constant speed (angular velocity).
The motor will accelerate towards the requested speed and the duty cycle is automatically adjusted to keep the speed constant, even under some load. This continues in the background until you give the motor a new command or the program stops.
The motor will accelerate towards the requested speed and the duty
cycle is automatically adjusted to keep the speed constant, even under
some load. This continues in the background until you give the motor a
new command or the program stops.
Arguments:
speed (:ref:`speed`): Speed of the motor.
@@ -100,108 +131,211 @@ class Motor():
def run_time(self, speed, time, stop_type=Stop.COAST, wait=True):
"""run_time(speed, time, stop_type=Stop.COAST, wait=True)
Run the motor at a constant speed (angular velocity) for a given amount of time.
Run the motor at a constant speed (angular velocity) for a given amount
of time.
The motor will accelerate towards the requested speed and the duty cycle is automatically adjusted to keep the speed constant, even under some load. It begins to decelerate just in time to reach standstill after the specified duration.
The motor will accelerate towards the requested speed and the duty
cycle is automatically adjusted to keep the speed constant, even under
some load. It begins to decelerate just in time to reach standstill
after the specified duration.
Arguments:
speed (:ref:`speed`): Speed of the motor.
time (:ref:`time`): Duration of the maneuver.
stop_type (Stop): Whether to coast, brake, or hold after coming to a standstill (*Default*: :class:`Stop.COAST <parameters.Stop>`).
wait (bool): Wait for the maneuver to complete before continuing with the rest of the program (*Default*: ``True``). This means that your program waits for the specified ``time``.
stop_type (Stop): Whether to coast, brake, or hold after coming to
a standstill (*Default*:
:class:`Stop.COAST <parameters.Stop>`).
wait (bool): Wait for the maneuver to complete before continuing
with the rest of the program (*Default*: ``True``).
This means that your program waits for the
specified ``time``.
"""
pass
def run_angle(self, speed, rotation_angle, stop_type=Stop.COAST, wait=True):
def run_angle(self, speed, rotation_angle,
stop_type=Stop.COAST, wait=True):
"""run_angle(speed, rotation_angle, stop_type=Stop.COAST, wait=True)
Run the motor at a constant speed (angular velocity) by a given angle.
The motor will accelerate towards the requested speed and the duty cycle is automatically adjusted to keep the speed constant, even under some load. It begins to decelerate just in time so that it comes to a standstill after traversing the given angle.
The motor will accelerate towards the requested speed and the duty
cycle is automatically adjusted to keep the speed constant, even under
some load. It begins to decelerate just in time so that it comes to a
standstill after traversing the given angle.
Arguments:
speed (:ref:`speed`): Speed of the motor.
rotation_angle (:ref:`angle`): Angle by which the motor should rotate.
stop_type (Stop): Whether to coast, brake, or hold after coming to a standstill (*Default*: :class:`Stop.COAST <parameters.Stop>`).
wait (bool): Wait for the maneuver to complete before continuing with the rest of the program (*Default*: ``True``). This means that your program waits until the motor has traveled precisely the requested angle.
rotation_angle (:ref:`angle`): Angle by which the motor should
rotate.
stop_type (Stop): Whether to coast, brake, or hold after coming to
a standstill (*Default*:
:class:`Stop.COAST <parameters.Stop>`).
wait (bool): Wait for the maneuver to complete before continuing
with the rest of the program (*Default*: ``True``).
This means that your program waits until the motor has
traveled precisely the requested angle.
"""
pass
def run_target(self, speed, target_angle, stop_type=Stop.COAST, wait=True):
"""run_target(speed, target_angle, stop_type=Stop.COAST, wait=True)
Run the motor at a constant speed (angular velocity) towards a given target angle.
Run the motor at a constant speed (angular velocity) towards a given
target angle.
The motor will accelerate towards the requested speed and the duty cycle is automatically adjusted to keep the speed constant, even under some load. It begins to decelerate just in time so that it comes to a standstill at the given target angle.
The motor will accelerate towards the requested speed and the duty
cycle is automatically adjusted to keep the speed constant, even under
some load. It begins to decelerate just in time so that it comes to a
standstill at the given target angle.
The direction of rotation is automatically selected based on the target angle.
The direction of rotation is automatically selected based on the target
angle.
Arguments:
speed (:ref:`speed`): Absolute speed of the motor. The direction will be automatically selected based on the target angle: it makes no difference if you specify a positive or negative speed.
target_angle (:ref:`angle`): Target angle that the motor should rotate to, regardless of its current angle.
stop_type (Stop): Whether to coast, brake, or hold after coming to a standstill (*Default*: :class:`Stop.COAST <parameters.Stop>`).
wait (bool): Wait for the maneuver to complete before continuing with the rest of the program (*Default*: ``True``). This means that your program waits until the motor has reached the target angle.
speed (:ref:`speed`): Absolute speed of the motor. The direction
will be automatically selected based on the
target angle: it makes no difference if you
specify a positive or negative speed.
target_angle (:ref:`angle`): Target angle that the motor should
rotate to, regardless of its current
angle.
stop_type (Stop): Whether to coast, brake, or hold after coming to
a standstill (*Default*:
:class:`Stop.COAST <parameters.Stop>`).
wait (bool): Wait for the maneuver to complete before continuing
with the rest of the program (*Default*: ``True``).
This means that your program waits until the motor
has reached the target angle.
"""
pass
def run_until_stalled(self, speed, stop_type=Stop.COAST, duty_limit=None):
"""run_until_stalled(speed, stop_type=Stop.COAST, duty_limit=default)
Run the motor at a constant speed (angular velocity) until it stalls. The motor is considered stalled when it cannot move even with the maximum torque. See :meth:`.stalled` for a more precise definition.
Run the motor at a constant speed (angular velocity) until it stalls.
The motor is considered stalled when it cannot move even with the
maximum torque. See :meth:`.stalled` for a more precise definition.
The ``duty_limit`` argument lets you temporarily limit the motor torque during this maneuver. This is useful to avoid applying the full motor torque to a geared or lever mechanism.
The ``duty_limit`` argument lets you temporarily limit the motor torque
during this maneuver. This is useful to avoid applying the full motor
torque to a geared or lever mechanism.
Arguments:
speed (:ref:`speed`): Speed of the motor.
stop_type (Stop): Whether to coast, brake, or hold after coming to a standstill (*Default*: :class:`Stop.COAST <parameters.Stop>`).
duty_limit (:ref:`percentage`): Relative torque limit. This limit works just like :meth:`.set_dc_settings`, but in this case the limit is temporary: it returns to its previous value after completing this command.
stop_type (Stop): Whether to coast, brake, or hold after coming to
a standstill (*Default*:
:class:`Stop.COAST <parameters.Stop>`).
duty_limit (:ref:`percentage`): Relative torque limit. This limit
works just like
:meth:`.set_dc_settings`, but in
this case the limit is temporary:
it returns to its previous value
after completing this command.
"""
pass
def track_target(self, target_angle):
"""Track a target angle that varies in time.
This function is quite similar to :meth:`.run_target`, but speed and acceleration settings are ignored: it will move to the target angle as fast as possible. Instead, you adjust speed and acceleration by choosing how fast or slow you vary the ``target_angle``.
This function is quite similar to :meth:`.run_target`, but speed and
acceleration settings are ignored: it will move to the target angle as
fast as possible. Instead, you adjust speed and acceleration by
choosing how fast or slow you vary the ``target_angle``.
This method is useful in fast loops where the motor target changes continuously.
This method is useful in fast loops where the motor target changes
continuously.
Arguments:
target_angle (:ref:`angle`): Target angle that the motor should rotate to.
target_angle (:ref:`angle`): Target angle that the motor should
rotate to.
"""
pass
def set_dc_settings(self, duty_limit, duty_offset):
"""Configure the settings to adjust the behavior of the :meth:`.dc` command. This also affects all of the ``run`` commands, which use the :meth:`.dc` method in the background.
"""Configure the settings to adjust the behavior of the :meth:`.dc`
command. This also affects all of the ``run`` commands, which use
the :meth:`.dc` method in the background.
Arguments:
duty_limit (:ref:`percentage`): Relative torque limit during subsequent motor commands. This sets the maximum duty cycle that is applied during any subsequent motor command. This reduces the maximum torque output to a percentage of the absolute maximum stall torque. This is useful to avoid applying the full motor torque to a geared or lever mechanism, or to prevent your LEGO® train from unintentionally going at full speed. (*Default*: 100).
duty_offset (:ref:`percentage`): Minimum duty cycle given when you use :meth:`.dc`. This adds a small feed forward torque so that your motor will move even for very low duty cycle values, which can be useful when you create your own feedback controllers (*Default*: 0).
duty_limit (:ref:`percentage`): Relative torque limit during
subsequent motor commands. This
sets the maximum duty cycle that is
applied during any subsequent motor
command. This reduces the maximum
torque output to a percentage of
the absolute maximum stall torque.
This is useful to avoid applying
the full motor torque to a geared
or lever mechanism, or to prevent
your LEGO® train from
unintentionally going at full
speed. (*Default*: 100).
duty_offset (:ref:`percentage`): Minimum duty cycle given when you
use :meth:`.dc`. This adds a small
feed forward torque so that your
motor will move even for very low
duty cycle values, which can be
useful when you create your own
feedback controllers
(*Default*: 0).
"""
pass
def set_run_settings(self, max_speed, acceleration):
"""Configure the maximum speed and acceleration/deceleration of the motor for all run commands.
"""Configure the maximum speed and acceleration/deceleration of the
motor for all run commands.
This applies to the ``run``, ``run_time``, ``run_angle``, ``run_target``, or ``run_until_stalled`` commands you give the motor. See also the :ref:`default parameters <defaultpars>` for each motor.
This applies to the ``run``, ``run_time``, ``run_angle``,
``run_target``, or ``run_until_stalled`` commands you give the motor.
See also the :ref:`default parameters <defaultpars>` for each motor.
Arguments:
max_speed (:ref:`speed`): Maximum speed of the motor during a motor command.
acceleration (:ref:`acceleration`): Acceleration towards the target speed and deceleration towards standstill. This should be a positive value. The motor will automatically change the sign to decelerate as needed.
max_speed (:ref:`speed`): Maximum speed of the motor during a motor
command.
acceleration (:ref:`acceleration`): Acceleration towards the target
speed and deceleration towards
standstill. This should be a
positive value. The motor will
automatically change the sign
to decelerate as needed.
"""
pass
def set_pid_settings(self, kp, ki, kd, tight_loop_limit, angle_tolerance, speed_tolerance, stall_speed, stall_time):
"""Configure the settings of the position and speed controllers. See also :ref:`pid` and the :ref:`default parameters <defaultpars>` for each motor.
def set_pid_settings(self, kp, ki, kd, tight_loop_limit, angle_tolerance,
speed_tolerance, stall_speed, stall_time):
"""Configure the settings of the position and speed controllers.
See also :ref:`pid` and the :ref:`default parameters <defaultpars>`
for each motor.
Arguments:
kp (int): Proportional position (and integral speed) control constant.
kp (int): Proportional position (and integral speed) control
constant.
ki (int): Integral position control constant.
kd (int): Derivative position (and proportional speed) control constant.
tight_loop_limit (:ref:`time`): If you execute any of the ``run`` commands within this interval after starting the previous command, the controllers assume that you want to control the speed directly. This means that it will ignore the acceleration setting and immediately begin tracking the speed you give in the ``run`` command. This is useful in a fast loop, where you usually want the motors to respond quickly rather than accelerate smoothly, for example with a line-following robot.
angle_tolerance (:ref:`angle`): Allowed deviation from the target angle before motion is considered complete.
speed_tolerance (:ref:`speed`): Allowed deviation from zero speed before motion is considered complete.
kd (int): Derivative position (and proportional speed) control\
constant.
tight_loop_limit (:ref:`time`): If you execute any of the ``run``
commands within this interval after
starting the previous command, the
controllers assume that you want to
control the speed directly. This
means that it will ignore the
acceleration setting and
immediately begin tracking the
speed you give in the ``run``
command. This is useful in a fast
loop, where you usually want the
motors to respond quickly rather
than accelerate smoothly, for
example with a line-following
robot.
angle_tolerance (:ref:`angle`): Allowed deviation from the target
angle before motion is considered
complete.
speed_tolerance (:ref:`speed`): Allowed deviation from zero speed
before motion is considered
complete.
stall_speed (:ref:`speed`): See :meth:`.stalled`.
stall_time (:ref:`time`): See :meth:`.stalled`.
"""
@@ -222,24 +356,32 @@ class Display():
Parameters:
text (str): The text to display.
coordinate (tuple): ``(x, y)`` coordinate tuple. It is the top-left corner of the first character. If no coordinate is specified, it is printed on the next line.
coordinate (tuple): ``(x, y)`` coordinate tuple. It is the top-left
corner of the first character. If no coordinate
is specified, it is printed on the next line.
"""
pass
@staticmethod
def image(self, file_name, alignment=Align.CENTER, coordinate=None, clear=True):
def image(self, file_name,
alignment=Align.CENTER, coordinate=None, clear=True):
"""image(file_name, alignment=Align.CENTER, coordinate=None, clear=True)
Show an image file.
You can specify its placement either using ``alignment`` or by specifying a ``coordinate``, but not both.
You can specify its placement either using ``alignment`` or by
specifying a ``coordinate``, but not both.
Arguments:
file_name (str): Path to the image file. Paths may be absolute or relative from the project folder.
alignment (Align): Where to place the image (*Default*: Align.CENTER).
coordinate (tuple): ``(x, y)`` coordinate tuple. It is the top-left corner of the image (*Default*: None).
clear (bool): Whether to clear the screen before showing the image (*Default*: ``True``).
file_name (str): Path to the image file. Paths may be absolute or
relative from the project folder.
alignment (Align): Where to place the image
(*Default*: Align.CENTER).
coordinate (tuple): ``(x, y)`` coordinate tuple. It is the top-left
corner of the image (*Default*: None).
clear (bool): Whether to clear the screen before showing the image
(*Default*: ``True``).
"""
pass
@@ -253,7 +395,8 @@ class Speaker():
"""Play a beep/tone.
Arguments:
frequency (:ref:`frequency`): Frequency of the beep (*Default*: 500).
frequency (:ref:`frequency`): Frequency of the beep
(*Default*: 500).
duration (:ref:`time`): Duration of the beep (*Default*: 100).
volume (:ref:`percentage`): Volume of the beep (*Default*: 30).
"""
@@ -313,7 +456,8 @@ class ColorLight():
"""Turn on the light at the specified color.
Arguments:
color (Color): Color of the light. The light turns off if you choose ``None`` or a color that is not available.
color (Color): Color of the light. The light turns off if you
choose ``None`` or a color that is not available.
"""
pass
@@ -333,6 +477,7 @@ class ColorLight():
"""
pass
class Battery():
"""Get the status of a battery."""
-3
View File
@@ -1,6 +1,5 @@
"""LEGO® MINDSTORMS® EV3 Brick."""
from parameters import Color
from _common import Speaker, Display, Battery, ColorLight
@@ -14,8 +13,6 @@ def buttons():
pass
sound = Speaker()
display = Display()
battery = Battery()
+45 -25
View File
@@ -38,7 +38,8 @@ class TouchSensor():
"""Check if the sensor is pressed.
Returns:
:obj:`bool`: ``True`` if the sensor is pressed, ``False`` if it is not pressed.
:obj:`bool`: ``True`` if the sensor is pressed, ``False`` if it is
not pressed.
"""
pass
@@ -69,7 +70,9 @@ class ColorSensor():
:returns:
``Color.BLACK``, ``Color.BLUE``, ``Color.GREEN``, ``Color.YELLOW``,
``Color.RED``, ``Color.WHITE``, ``Color.BROWN`` or ``None``.
:rtype: :class:`Color <parameters.Color>`, or ``None`` if no color is detected.
:rtype: :class:`Color <parameters.Color>`, or ``None`` if no color is
detected.
"""
pass
@@ -77,7 +80,8 @@ class ColorSensor():
"""Measure the ambient light intensity.
Returns:
:ref:`percentage`: Ambient light intensity, ranging from 0 (dark) to 100 (bright).
:ref:`percentage`: Ambient light intensity, ranging from 0 (dark)
to 100 (bright).
"""
pass
@@ -85,17 +89,20 @@ class ColorSensor():
"""Measure the reflection of a surface using a red light.
Returns:
:ref:`percentage`: Reflection, ranging from 0 (no reflection) to 100 (high reflection).
:ref:`percentage`: Reflection, ranging from 0 (no reflection) to
100 (high reflection).
"""
pass
def rgb(self):
"""Measure the reflection of a surface using a red, green, and then a blue light.
"""Measure the reflection of a surface using a red, green, and then a
blue light.
Returns:
tuple of three :ref:`percentages <percentage>`: Reflection for red, green, and blue light, each ranging from 0.0 (no reflection) to 100.0 (high reflection).
tuple of three :ref:`percentages <percentage>`: Reflection for red,
green, and blue light, each ranging from 0.0 (no reflection) to
100.0 (high reflection).
"""
pass
@@ -119,22 +126,27 @@ class InfraredSensor():
pass
def distance(self):
"""Measure the relative distance between the sensor and an object using infrared light.
"""Measure the relative distance between the sensor and an object using
infrared light.
Returns:
:ref:`relativedistance`: Relative distance ranging from 0 (closest) to 100 (farthest).
:ref:`relativedistance`: Relative distance ranging from 0 (closest)
to 100 (farthest).
"""
pass
def beacon(self, channel):
"""Measure the relative distance and angle between the remote and the infrared sensor.
"""Measure the relative distance and angle between the remote and the
infrared sensor.
Arguments:
channel (int): Channel number of the remote.
:returns: Tuple of relative distance (0 to 100) and approximate angle (-75 to 75 degrees) between remote and infrared sensor.
:rtype: (:ref:`relativedistance`, :ref:`angle`) or (``None``, ``None``) if no remote is detected.
:returns: Tuple of relative distance (0 to 100) and approximate angle
(-75 to 75 degrees) between remote and infrared sensor.
:rtype: (:ref:`relativedistance`, :ref:`angle`) or
(``None``, ``None``) if no remote is detected.
"""
pass
@@ -144,7 +156,7 @@ class InfraredSensor():
Arguments:
channel (int): Channel number of the remote.
:returns: List of pressed buttons on the remote on the specified channel.
:returns: List of pressed buttons on the remote on selected channel.
:rtype: List of :class:`Button <parameters.Button>`
"""
@@ -165,7 +177,9 @@ class GyroSensor():
Arguments:
port (Port): Port to which the sensor is connected.
direction (Direction): Positive rotation direction when looking at the red dot on top of the sensor (*Default*: Direction.CLOCKWISE).
direction (Direction): Positive rotation direction when looking at
the red dot on top of the sensor
(*Default*: Direction.CLOCKWISE).
"""
pass
@@ -229,16 +243,18 @@ class UltrasonicSensor():
pass
def distance(self, silent=False):
"""Measure the distance between the sensor and an object using ultrasonic sound waves.
"""Measure the distance between the sensor and an object using
ultrasonic sound waves.
Arguments:
silent (bool): Choose ``True`` to turn the sensor off after measuring the distance.
Choose ``False`` to leave the sensor on (*Default*).
When you choose ``silent=True``, the sensor does not emit sounds waves
except when taking the measurement. This reduces interference with
other ultrasonic sensors, but turning the sensor off takes approximately 300 ms each time.
silent (bool): Choose ``True`` to turn the sensor off after
measuring the distance. Choose ``False`` to leave
the sensor on (*Default*). When you choose
``silent=True``, the sensor does not
emit sounds waves except when taking the
measurement. This reduces interference with other
ultrasonic sensors, but turning the sensor off takes
approximately 300 ms each time.
Returns:
:ref:`distance`: Distance (millimeters).
@@ -247,11 +263,15 @@ class UltrasonicSensor():
pass
def presence(self):
"""Check for the presence of other ultrasonic sensors by detecting ultrasonic sounds.
"""Check for the presence of other ultrasonic sensors by detecting
ultrasonic sounds.
If the other ultrasonic sensor is operating in silent mode, you can only detect the presence of that sensor while it is taking a measurement.
If the other ultrasonic sensor is operating in silent mode, you can
only detect the presence of that sensor while it is taking a
measurement.
Returns:
:obj:`bool`: ``True`` if ultrasonic sounds are detected, ``False`` if not.
:obj:`bool`: ``True`` if ultrasonic sounds are detected,
``False`` if not.
"""
pass
+19 -7
View File
@@ -31,34 +31,46 @@ class ColorDistanceSensor():
:returns:
``Color.BLACK``, ``Color.BLUE``, ``Color.GREEN``, ``Color.YELLOW``,
``Color.RED``, ``Color.WHITE``, or ``None``.
:rtype: :class:`Color <parameters.Color>`, or ``None`` if no color is detected.
:rtype: :class:`Color <parameters.Color>`, or ``None`` if no color is
detected.
"""
pass
def ambient(self):
"""Measure the ambient light intensity.
Returns:
:ref:`percentage`: Ambient light intensity, ranging from 0 (dark) to 100 (bright).
:ref:`percentage`: Ambient light intensity, ranging from 0 (dark)
to 100 (bright).
"""
pass
def reflection(self):
"""Measure the reflection of a surface using a red light.
Returns:
:ref:`percentage`: Reflection, ranging from 0.0 (no reflection) to 100.0 (high reflection).
:ref:`percentage`: Reflection, ranging from 0.0 (no reflection) to
100.0 (high reflection).
"""
pass
def rgb(self):
"""Measure the reflection of a surface using a red, green, and then a blue light.
"""Measure the reflection of a surface using a red, green, and then a
blue light.
Returns:
tuple of three :ref:`percentages <percentage>`: Reflection for red, green, and blue light, each ranging from 0.0 (no reflection) to 100.0 (high reflection).
tuple of three :ref:`percentages <percentage>`: Reflection for red,
green, and blue light, each ranging from 0.0 (no reflection) to
100.0 (high reflection).
"""
pass
def distance(self):
"""Measure the relative distance between the sensor and an object using infrared light.
"""Measure the relative distance between the sensor and an object using
infrared light.
Returns:
:ref:`relativedistance`: Relative distance ranging from 0 (closest) to 100 (farthest).
:ref:`relativedistance`: Relative distance ranging from 0 (closest)
to 100 (farthest).
"""
pass
+19 -14
View File
@@ -72,9 +72,11 @@ class Stop(Enum):
.. data:: HOLD
Keep controlling the motor to hold it at the commanded angle. This is only available on motors with encoders.
Keep controlling the motor to hold it at the commanded angle. This is
only available on motors with encoders.
The stop type defines the resistance to motion after coming to a standstill:
The stop type defines the resistance to motion after coming to a
standstill:
+-----------+-------------+------------------------------------------+
|Parameter | Resistance | Physical meaning |
@@ -94,7 +96,8 @@ class Stop(Enum):
class Direction():
"""Rotational direction for positive speed values: clockwise or counterclockwise.
"""Rotational direction for positive speed values: clockwise or
counterclockwise.
.. data:: CLOCKWISE
@@ -104,9 +107,11 @@ class Direction():
A positive speed value should make the motor move counterclockwise.
For all motors, this is defined when looking at the shaft, just like looking at a clock.
For all motors, this is defined when looking at the shaft, just like
looking at a clock.
For NXT or EV3 motors, make sure to look at the motor with the red/orange shaft to the lower right.
For NXT or EV3 motors, make sure to look at the motor with the red/orange
shaft to the lower right.
+----------------------------+-------------------+-----------------+
| Parameter | Positive speed | Negative speed |
@@ -126,25 +131,25 @@ class Direction():
____ _____
/ \\
/ _____________ \\
/ / \ \\
/ / \\ \\
| | _ | |
| | __| |__ | |
v | |__ o __| | v
| |_| |
| |
\______________/
\\______________/
Large EV3 Motor:
________
/ \ ___ ___
_| \ / \\
________
/ \\ ___ ___
_| \\ / \\
| ----/------ \\
counterclockwise | __\__ | clockwise
\__________ v / \ v
-------| + |
\_____/
counterclockwise | __\\__ | clockwise
\\ __________ v / \\ v
-------| + |
\\_____/
"""
+11 -6
View File
@@ -1,10 +1,11 @@
"""Robotics module for the Pybricks API."""
from parameters import Stop, Direction
from parameters import Stop
class DriveBase():
"""Class representing a robotic vehicle with two powered wheels and optional wheel caster(s)."""
"""Class representing a robotic vehicle with two powered wheels and
optional wheel caster(s)."""
def __init__(self, left_motor, right_motor, wheel_diameter, axle_track):
"""DriveBase(left_motor, right_motor, wheel_diameter, axle_track)
@@ -13,12 +14,14 @@ class DriveBase():
left_motor (Motor): The motor that drives the left wheel.
right_motor (Motor): The motor that drives the right wheel.
wheel_diameter (:ref:`dimension`): Diameter of the wheels.
axle_track (:ref:`dimension`): Distance between the midpoints of the two wheels.
axle_track (:ref:`dimension`): Distance between the midpoints of
the two wheels.
"""
def drive(self, speed, steering):
"""Start driving at the specified speed and turnrate, both measured at the center point between the wheels of the robot.
"""Start driving at the specified speed and turnrate, both measured at
the center point between the wheels of the robot.
Arguments:
speed (:ref:`travelspeed`): Forward speed of the robot.
@@ -27,7 +30,8 @@ class DriveBase():
pass
def drive_time(self, speed, steering, time):
"""Drive at the specified speed and turnrate for a given amount of time, and then stop.
"""Drive at the specified speed and turnrate for a given amount of
time, and then stop.
Arguments:
speed (:ref:`travelspeed`): Forward speed of the robot.
@@ -43,6 +47,7 @@ class DriveBase():
Stop the robot.
Arguments:
stop_type (Stop): Whether to coast, brake, or hold (*Default*: :class:`Stop.COAST <parameters.Stop>`).
stop_type (Stop): Whether to coast, brake, or hold (*Default*:
:class:`Stop.COAST <parameters.Stop>`).
"""
pass
+2 -1
View File
@@ -21,7 +21,8 @@ def wait(time):
class StopWatch():
"""A stopwatch to measure time intervals. Similar to the stopwatch feature on your phone."""
"""A stopwatch to measure time intervals. Similar to the stopwatch
feature on your phone."""
def __init__(self):
pass