Skip to content

Commit 8a58212

Browse files
committed
Add more MotorControl documentation
1 parent 72d4763 commit 8a58212

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

docs/api/motor.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
Motor
22
=====
33

4-
Work in progress...
4+
Controlling the motors directly is not very precise because the NXT firmware
5+
does not expose the needed method for precise control. If you need more than
6+
basic controls, :class:`nxt.motcont.MotCont` provides finer controls thanks to
7+
a program running on the NXT brick.
8+
9+
Work in progress... The :class:`nxt.motor.Motor` class will probably be
10+
reworked in a future version.
511

612
.. automodule:: nxt.motor
713
:members:

nxt/motcont.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,24 @@ def cmd(
115115
smoothstart: bool = False,
116116
brake: bool = False,
117117
) -> None:
118-
"""Send a CONTROLLED_MOTORCMD to MotorControl.
118+
"""Send a controlled motor command to MotorControl.
119119
120120
:param ports: Port or ports to control, use one of the port identifiers, or
121121
an iterable returning one or two of them.
122122
:param power: Speed or power, -100 to 100.
123-
:param tacholimit: Position to drive to, 1 to 999999, or 0 for unlimited.
123+
:param tacholimit: Position to drive to, 1 to 999999.
124124
:param speedreg: ``True`` to enable regulation.
125125
:param smoothstart: ``True`` to enable smooth start.
126126
:param brake: ``True`` to hold brake at end of movement.
127+
128+
The motors on the selected ports must be idle, i.e. they can not be carrying out
129+
any other movement commands. If this should happen, the NXT will indicate this
130+
error by a signal (high and low beep) and will drop the message. To find out if
131+
a motor is ready to accept new commands, use the :meth:`is_ready` method. It is
132+
also possible to stop the motor before using :meth:`set_output_state` method.
133+
134+
In certain situations, :meth:`set_output_state` method should be used instead.
135+
See :meth:`set_output_state` for more details.
127136
"""
128137
self._interval_is_ready()
129138
ports, strports = self._decode_ports(ports, 2)
@@ -173,13 +182,29 @@ def set_output_state(
173182
tacholimit: int,
174183
speedreg: bool = True,
175184
) -> None:
176-
"""Send a CLASSIC_MOTORCMD to MotorControl.
185+
"""Send a classic motor command to MotorControl.
177186
178187
:param ports: Port or ports to control, use one of the port identifiers, or
179188
an iterable returning one or two of them.
180189
:param power: Speed or power, -100 to 100.
181190
:param tacholimit: Position to drive to, 1 to 999999, or 0 for unlimited.
182191
:param speedreg: ``True`` to enable regulation.
192+
193+
This is similar to the regular :meth:`nxt.brick.Brick.set_output_state` method,
194+
but informs the MotorControl program to avoid any unwanted side effect.
195+
196+
When to use :meth:`set_output_state` instead of :meth:`cmd`:
197+
198+
- when tacholimit is 0 for unlimited movement,
199+
- or when the motor must coast (spin freely) after tacholimit has been reached
200+
(it will overshoot then),
201+
- or when you want to be able to change the power of a running motor at runtime.
202+
203+
Also use this method to stop a currently running motor:
204+
205+
- To stop and let a motor spin freely (coasting), use `power` 0 and no
206+
regulation.
207+
- To stop and hold the current position (brake), use `power` 0 with regulation.
183208
"""
184209
self._interval_is_ready()
185210
ports, strports = self._decode_ports(ports, 2)

0 commit comments

Comments
 (0)