pybricks._common.Motor: Enable on EV3 and NXT.

Use a shared include and only index the pupdevices Motor.
This commit is contained in:
Laurens Valk
2026-08-25 10:13:58 +02:00
parent bd4a26f6ac
commit 6cd0c3b136
8 changed files with 188 additions and 139 deletions
+124
View File
@@ -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
+3 -2
View File
@@ -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
+21
View File
@@ -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
+1
View File
@@ -10,6 +10,7 @@
:maxdepth: 1
:hidden:
motor
touchsensor
lightsensor
colorsensor
+21
View File
@@ -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
+1 -126
View File
@@ -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
-----------------------
+6
View File
@@ -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."""
+11 -11
View File
@@ -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 <settings>` 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 <pybricks.pupdevices.Motor.control.limits>` 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 <settings>` 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 <pybricks.pupdevices.Motor.control.limits>` 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,