diff --git a/doc/main/common/motor_members.rst.txt b/doc/main/common/motor_members.rst.txt new file mode 100644 index 0000000..99b2c9e --- /dev/null +++ b/doc/main/common/motor_members.rst.txt @@ -0,0 +1,124 @@ +.. rubric:: Measuring + +.. blockimg:: pybricks_blockMotorMeasure_motor_angle + +.. automethod:: angle + +.. blockimg:: pybricks_blockMotorResetAngle + +.. automethod:: reset_angle + +.. blockimg:: pybricks_blockMotorMeasure_motor_speed + +.. blockimg:: pybricks_blockMotorMeasure_motor_get_speed_average + +.. automethod:: speed + +.. blockimg:: pybricks_blockMotorMeasure_motor_load + +.. automethod:: load + +.. blockimg:: pybricks_blockMotorMeasure_motor_stalled + +.. automethod:: stalled + +.. rubric:: Stopping + +.. blockimg:: pybricks_blockMotorStop_Motor_coast + +.. automethod:: stop + +.. blockimg:: pybricks_blockMotorStop_Motor_brake + +.. automethod:: brake + +.. blockimg:: pybricks_blockMotorStop_Motor_hold + +.. automethod:: hold + +.. rubric:: Running forever + +.. blockimg:: pybricks_blockMotorRun_run + +.. automethod:: run + +.. blockimg:: pybricks_blockMotorDuty_Motor + +.. automethod:: dc + +.. rubric:: Running by a fixed amount + +.. automethod:: run_time + +.. blockimg:: pybricks_blockMotorRun_run_angle + +.. automethod:: run_angle + +.. blockimg:: pybricks_blockMotorRun_run_target + +.. automethod:: run_target + +.. blockimg:: pybricks_blockMotorRun_run_until_stalled + +.. automethod:: run_until_stalled + +.. blockimg:: pybricks_blockMotorTrack + +.. automethod:: track_target + +.. automethod:: done + +.. rubric:: Motor settings + +.. blockimg:: pybricks_blockMotorConfigure_motor_max_voltage + +.. automethod:: settings + +.. automethod:: close + +.. rubric:: Control settings + +.. pybricks-requirements:: pybricks-common-control + +.. blockimg:: pybricks_blockMotorConfigure_motor_max_speed + +.. blockimg:: pybricks_blockMotorConfigure_motor_acceleration + +.. blockimg:: pybricks_blockMotorConfigure_motor_max_torque + +.. autonestedmethod:: control.limits + +.. pybricks-requirements:: pybricks-common-control + +.. autonestedmethod:: control.pid + +.. pybricks-requirements:: pybricks-common-control + +.. blockimg:: pybricks_blockMotorConfigure_motor_target_tolerances + +.. autonestedmethod:: control.target_tolerances + +.. pybricks-requirements:: pybricks-common-control + +.. autonestedmethod:: control.stall_tolerances + +.. pybricks-requirements:: pybricks-common-control + +.. attribute:: control.scale + + Number of degrees that the motor turns to complete one degree at the + output of the gear train. This is the gear ratio determined from the + ``gears`` argument when initializing the motor. + +.. versionchanged:: 3.2 + + The :meth:`done`, :meth:`stalled` and :meth:`load` methods have been + moved. + +.. pybricks-requirements:: pybricks-common-control + +.. autonestedmethod:: model.state + +.. pybricks-requirements:: pybricks-common-control + +.. autonestedmethod:: model.settings diff --git a/doc/main/ev3devices/index.rst b/doc/main/ev3devices/index.rst index 826d62c..c6bfe85 100644 --- a/doc/main/ev3devices/index.rst +++ b/doc/main/ev3devices/index.rst @@ -10,17 +10,18 @@ :maxdepth: 1 :hidden: + motor touchsensor colorsensor infraredsensor ultrasonicsensor gyrosensor -.. pybricks-classlink:: Motor ../pupdevices/motor +.. pybricks-classlink:: Motor ../ev3devices/motor .. figure:: ../../main/cad/output/ev3device-motors.png :width: 100 % - :target: ../pupdevices/motor.html + :target: ../ev3devices/motor.html .. pybricks-classlink:: TouchSensor diff --git a/doc/main/ev3devices/motor.rst b/doc/main/ev3devices/motor.rst new file mode 100644 index 0000000..936e68c --- /dev/null +++ b/doc/main/ev3devices/motor.rst @@ -0,0 +1,21 @@ +.. pybricks-requirements:: + +Motors with rotation sensors +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. _fig_ev3motors: + +.. figure:: ../../main/diagrams/ev3motors.png + :width: 100 % + :alt: ev3motors + + EV3 and NXT motors with rotation sensors. The arrows indicate the default + positive direction. + +.. blockimg:: pybricks_variables_set_motor + +.. autoclass:: pybricks.ev3devices.Motor + :no-members: + :no-index: + + .. include:: ../common/motor_members.rst.txt diff --git a/doc/main/nxtdevices/index.rst b/doc/main/nxtdevices/index.rst index 47b81ca..c14bacf 100644 --- a/doc/main/nxtdevices/index.rst +++ b/doc/main/nxtdevices/index.rst @@ -10,6 +10,7 @@ :maxdepth: 1 :hidden: + motor touchsensor lightsensor colorsensor diff --git a/doc/main/nxtdevices/motor.rst b/doc/main/nxtdevices/motor.rst new file mode 100644 index 0000000..d826839 --- /dev/null +++ b/doc/main/nxtdevices/motor.rst @@ -0,0 +1,21 @@ +.. pybricks-requirements:: + +Motors with rotation sensors +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. _fig_nxtmotors: + +.. figure:: ../../main/diagrams/ev3motors.png + :width: 100 % + :alt: ev3motors + + EV3 and NXT motors with rotation sensors. The arrows indicate the default + positive direction. + +.. blockimg:: pybricks_variables_set_motor + +.. autoclass:: pybricks.nxtdevices.Motor + :no-members: + :no-index: + + .. include:: ../common/motor_members.rst.txt diff --git a/doc/main/pupdevices/motor.rst b/doc/main/pupdevices/motor.rst index e276da0..22fb230 100644 --- a/doc/main/pupdevices/motor.rst +++ b/doc/main/pupdevices/motor.rst @@ -18,132 +18,7 @@ Motors with rotation sensors .. autoclass:: pybricks.pupdevices.Motor :no-members: - .. rubric:: Measuring - - .. blockimg:: pybricks_blockMotorMeasure_motor_angle - - .. automethod:: angle - - .. blockimg:: pybricks_blockMotorResetAngle - - .. automethod:: reset_angle - - .. blockimg:: pybricks_blockMotorMeasure_motor_speed - - .. blockimg:: pybricks_blockMotorMeasure_motor_get_speed_average - - .. automethod:: speed - - .. blockimg:: pybricks_blockMotorMeasure_motor_load - - .. automethod:: load - - .. blockimg:: pybricks_blockMotorMeasure_motor_stalled - - .. automethod:: stalled - - .. rubric:: Stopping - - .. blockimg:: pybricks_blockMotorStop_Motor_coast - - .. automethod:: stop - - .. blockimg:: pybricks_blockMotorStop_Motor_brake - - .. automethod:: brake - - .. blockimg:: pybricks_blockMotorStop_Motor_hold - - .. automethod:: hold - - .. rubric:: Running forever - - .. blockimg:: pybricks_blockMotorRun_run - - .. automethod:: run - - .. blockimg:: pybricks_blockMotorDuty_Motor - - .. automethod:: dc - - .. rubric:: Running by a fixed amount - - .. automethod:: run_time - - .. blockimg:: pybricks_blockMotorRun_run_angle - - .. automethod:: run_angle - - .. blockimg:: pybricks_blockMotorRun_run_target - - .. automethod:: run_target - - .. blockimg:: pybricks_blockMotorRun_run_until_stalled - - .. automethod:: run_until_stalled - - .. blockimg:: pybricks_blockMotorTrack - - .. automethod:: track_target - - .. automethod:: done - - .. _settings: - - .. rubric:: Motor settings - - .. blockimg:: pybricks_blockMotorConfigure_motor_max_voltage - - .. automethod:: settings - - .. automethod:: close - - .. rubric:: Control settings - - .. pybricks-requirements:: pybricks-common-control - - .. blockimg:: pybricks_blockMotorConfigure_motor_max_speed - - .. blockimg:: pybricks_blockMotorConfigure_motor_acceleration - - .. blockimg:: pybricks_blockMotorConfigure_motor_max_torque - - .. autonestedmethod:: control.limits - - .. pybricks-requirements:: pybricks-common-control - - .. autonestedmethod:: control.pid - - .. pybricks-requirements:: pybricks-common-control - - .. blockimg:: pybricks_blockMotorConfigure_motor_target_tolerances - - .. autonestedmethod:: control.target_tolerances - - .. pybricks-requirements:: pybricks-common-control - - .. autonestedmethod:: control.stall_tolerances - - .. pybricks-requirements:: pybricks-common-control - - .. attribute:: control.scale - - Number of degrees that the motor turns to complete one degree at the - output of the gear train. This is the gear ratio determined from the - ``gears`` argument when initializing the motor. - - .. versionchanged:: 3.2 - - The :meth:`done`, :meth:`stalled` and :meth:`load` methods have been - moved. - - .. pybricks-requirements:: pybricks-common-control - - .. autonestedmethod:: model.state - - .. pybricks-requirements:: pybricks-common-control - - .. autonestedmethod:: model.settings + .. include:: ../common/motor_members.rst.txt Initialization examples ----------------------- diff --git a/src/pybricks/nxtdevices.py b/src/pybricks/nxtdevices.py index 7c38606..a3c9f78 100644 --- a/src/pybricks/nxtdevices.py +++ b/src/pybricks/nxtdevices.py @@ -5,6 +5,8 @@ from .parameters import Port + +from . import _common from ._common import ColorLight, CommonColorSensor from .iodevices import AnalogSensor @@ -12,6 +14,10 @@ from .iodevices import AnalogSensor from typing import Callable, Optional, Tuple +class Motor(_common.Motor): + """LEGO® MINDSTORMS® EV3 Motor.""" + + class TouchSensor: """LEGO® MINDSTORMS® NXT Touch Sensor.""" diff --git a/src/pybricks/robotics.py b/src/pybricks/robotics.py index f3e4601..18f1f77 100644 --- a/src/pybricks/robotics.py +++ b/src/pybricks/robotics.py @@ -36,20 +36,20 @@ class DriveBase: distance_control = _common.Control() """The traveled distance and drive speed are controlled by a PID - controller. You can use this attribute to change its settings. - See the :ref:`motor control ` attribute for an overview of - available methods. The ``distance_control`` attribute has the same - functionality, but the settings apply to every millimeter driven by the - drive base, instead of degrees turned by one motor.""" + controller. You can use this attribute to change its settings. See the + :meth:`motor control ` attribute + for an overview of available methods. The ``distance_control`` attribute + has the same functionality, but the settings apply to every millimeter + driven by the drive base, instead of degrees turned by one motor.""" heading_control = _common.Control() """The robot turn angle and turn rate are controlled by a PID - controller. You can use this attribute to change its settings. - See the :ref:`motor control ` attribute for an overview of - available methods. The ``heading_control`` attribute has the same - functionality, but the settings apply to every degree of rotation of the - whole drive base (viewed from the top) instead of degrees turned by one - motor.""" + controller. You can use this attribute to change its settings. See the + :meth:`motor control ` attribute + for an overview of available methods. The ``heading_control`` attribute + has the same functionality, but the settings apply to every degree of + rotation of the whole drive base (viewed from the top) instead of degrees + turned by one motor.""" def __init__( self,