Skip to content

Commit 2f1843f

Browse files
yuvaltassacopybara-github
authored andcommitted
Redesign the dcmotor controller: setpoint inputs, torque-space gains.
The dcmotor input block is any subset of the canonical list [pos, vel, ff, voltage], selected with input="pos vel ff voltage" and recorded as mjtCtrlInput bits in actuator_ctrlspec like pid. Tokens are required in canonical order: the attribute denotes a set, the block always packs canonically, and accepting permutations invites reading the string as a layout choice. The mode flag in gainprm[8] is retired (reserved, written 0). Controller gains are now in torque space, as for pid: the controller commands tau = kp*(q*-l) + kd*(v*-ldot) + ki*x_I + tau_ff over the present inputs (absent setpoints frozen at zero) and converts to drive voltage V = R/K * tau + K*ldot. The second term compensates back-EMF, as the current loop of a real torque-mode driver does (torque commands are current commands): commanded torque is delivered exactly until a limit binds, and the torque-speed envelope emerges from the Vmax clamp. The map uses the nameplate R: thermal resistance growth is not compensated, so a hot motor under-delivers by R/R(T). A stateless setpoint dcmotor now matches <pid> exactly, for any K and R; the old back-EMF droop remains available as the physical behavior of the raw voltage path. Voltage-space datasheet gains convert by K/R. Controller inputs require a positive motor constant (the map divides by K), and controller gains require a controller input. ff and voltage are distinct inputs, different in kind: ff is a torque feedforward added to the controller output, uniform with pid's ff (feedforward in the actuator's output space), while voltage is the raw terminal voltage of the physical device, injected downstream of the controller and its Vmax clamp, unclamped (ctrlrange bounds it if desired). input="voltage" is the default: the plain voltage-commanded motor, whose behavior is unchanged by this commit. The integrator always accumulates position error; the old velocity mode's integral term, ki*(int(u)dt - theta), which tracked the integral of the velocity command, is retired without replacement, keeping ki mode-independent -- commanded integrated velocity belongs to an integrator activation state, not to controller gains. slewmax rate-limits the first controller input -- position setpoint (rad/s), velocity setpoint (rad/s^2) or torque feedforward (N*m/s), each a real driver feature (reference ramping, ramped-velocity and ramped-torque input modes); the raw voltage input is never rate-limited and slewmax requires a controller input. input="none" selects the empty signature: the actuator owns no controls at all (nu = 0 is now legal with actuators present) and is purely passive -- LuGre friction, cogging and back-EMF braking as passive joint forces. This exists because auxiliary dynamic states (the LuGre bristle) attach to actuators, not joints. The terminal voltage is identically zero, i.e. a shorted motor (dynamic braking); motorconst=0 decouples the electrical branch. mjINPUT_NONE is a distinct enum value because ctrlspec = 0 means "unset, use the type default". History and delay require an input; the controller voltage override and input read in mj_fwdActuation are gated on a nonempty block. The analytic velocity derivative of the controller becomes dV/dw = -kd*R/K + K, whose second term cancels the back-EMF bias exactly: the net damping of an unclipped torque-mode motor is -kd, and of a voltage-mode or passive motor -K^2/R. Viewers label inputs via mj_actuatorInputName: pos, vel, ff, voltage. The dcmotor LaTeX design doc is updated accordingly: torque-space units, the tau->V map and its saturation-generated envelope, the input-block pipeline figure, and a Passive Operation section. PiperOrigin-RevId: 965795351 Change-Id: Ibc308ca21bd6bad014e77f950ee08feaad449b73
1 parent 11fa4a5 commit 2f1843f

29 files changed

Lines changed: 576 additions & 352 deletions

‎doc/XMLreference.rst‎

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5691,7 +5691,7 @@ specify them independently.
56915691

56925692
.. _actuator-general-dyntype:
56935693

5694-
:at:`dyntype`: :at-val:`[none, integrator, filter, filterexact, pid, muscle, user], "none"`
5694+
:at:`dyntype`: :at-val:`[none, integrator, filter, filterexact, pid, dcmotor, muscle, user], "none"`
56955695
Activation dynamics type for the actuator. The available dynamics types were already described in the :ref:`Actuation
56965696
model <geActuation>` section. Repeating that description in somewhat different notation (corresponding to the mjModel
56975697
and mjData fields involved) we have:
@@ -5711,7 +5711,7 @@ specify them independently.
57115711

57125712
.. _actuator-general-gaintype:
57135713

5714-
:at:`gaintype`: :at-val:`[fixed, affine, muscle, pid, so3, user], "fixed"`
5714+
:at:`gaintype`: :at-val:`[fixed, affine, muscle, dcmotor, pid, so3, user], "fixed"`
57155715
The gain and bias together determine the output of the force generation mechanism, which is currently assumed to be
57165716
affine. As already explained in :ref:`Actuation model <geActuation>`, the general formula is:
57175717
scalar_force = gain_term \* (act or ctrl) + bias_term.
@@ -5724,14 +5724,15 @@ specify them independently.
57245724
fixed gain_term = gainprm[0]
57255725
affine gain_term = gain_prm[0] + gain_prm[1]*length + gain_prm[2]*velocity
57265726
muscle gain_term = mju_muscleGain(...)
5727+
dcmotor DC motor gain (K or K/R), see :ref:`dcmotor<actuator-dcmotor>`
57275728
pid PID controller with setpoint inputs, see :ref:`pid<actuator-pid>`
57285729
so3 geodesic orientation servo, computed jointly over 3 force outputs, see :ref:`orientation<actuator-orientation>`
57295730
user gain_term = mjcb_act_gain(...)
57305731
======= ===============================
57315732

57325733
.. _actuator-general-biastype:
57335734

5734-
:at:`biastype`: :at-val:`[none, affine, muscle, so3, user], "none"`
5735+
:at:`biastype`: :at-val:`[none, affine, muscle, dcmotor, so3, user], "none"`
57355736
The keywords have the following meaning:
57365737

57375738
======= ================================================================
@@ -5740,6 +5741,7 @@ specify them independently.
57405741
none bias_term = 0
57415742
affine bias_term = biasprm[0] + biasprm[1]*length + biasprm[2]*velocity
57425743
muscle bias_term = mju_muscleBias(...)
5744+
dcmotor DC motor bias: back-EMF, cogging, LuGre friction, see :ref:`dcmotor<actuator-dcmotor>`
57435745
so3 damping term of the geodesic orientation servo, see :ref:`orientation<actuator-orientation>`
57445746
user bias_term = mjcb_act_bias(...)
57455747
======= ================================================================
@@ -5784,8 +5786,9 @@ specify them independently.
57845786
:at:`input`: :at-val:`string, optional`
57855787
Input signature of the actuator: which controls make up its control block, recorded in
57865788
``mjModel.actuator_ctrlspec``. For gaintype "so3" it selects the orientation chart: "expmap" (3 controls, the
5787-
default) or "quat" (4 controls); see :ref:`orientation/input<actuator-orientation-input>`. For gaintype "pid" it is
5788-
a token list selecting the input subset; see :ref:`pid/input<actuator-pid-input>`.
5789+
default) or "quat" (4 controls); see :ref:`orientation/input<actuator-orientation-input>`. For gaintypes "pid" and
5790+
"dcmotor" it is a token list selecting the input subset; see :ref:`pid/input<actuator-pid-input>` and
5791+
:ref:`dcmotor/input<actuator-dcmotor-input>`.
57895792

57905793
.. _actuator-general-actearly:
57915794

@@ -6806,8 +6809,11 @@ the stateless case.
68066809
- :ref:`resistance<actuator-dcmotor-resistance>`, :ref:`motorconst<actuator-dcmotor-motorconst>` and
68076810
:ref:`nominal<actuator-dcmotor-nominal>` are each optional, but some combination of them is required.
68086811
See Section 2.1 of the `technical note <_static/dcmotor.pdf>`__.
6809-
- The control :ref:`input<actuator-dcmotor-input>` semantic is either the voltage applied to the motor terminals (the
6810-
default), or a position or velocity target for a :ref:`PID controller<actuator-dcmotor-controller>`.
6812+
- The control block is selected by :ref:`input<actuator-dcmotor-input>`: any subset of ``[pos, vel, ff]``, where
6813+
``pos`` and ``vel`` are setpoint inputs to the on-board :ref:`PID controller<actuator-dcmotor-controller>` and
6814+
``ff`` is a torque feedforward added to its output; the ``voltage`` input is the raw terminal voltage. The
6815+
default is the plain voltage-commanded motor. With
6816+
``input="none"`` the actuator has no control inputs at all and acts as a purely passive device.
68116817
- Optional features include electrical dynamics (:ref:`inductance<actuator-dcmotor-inductance>`),
68126818
:ref:`cogging torque<actuator-dcmotor-cogging>`, :ref:`thermal resistance variation<actuator-dcmotor-thermal>`, and
68136819
:ref:`LuGre<actuator-dcmotor-lugre>` friction.
@@ -6946,22 +6952,37 @@ This element has the following custom attributes in addition to the common attri
69466952

69476953
.. _actuator-dcmotor-input:
69486954

6949-
:at:`input`: :at-val:`[voltage, position, velocity], "voltage"`
6950-
Specifies the input signal semantics. In "voltage" mode, the control directly sets applied motor voltage. In
6951-
"position" or "velocity" modes, the :ref:`PID controller<actuator-dcmotor-controller>` uses the control as a
6952-
reference setpoint relative to the joint trajectory. (see `tech note <_static/dcmotor.pdf>`__, Section 2.5)
6955+
:at:`input`: :at-val:`string, "voltage"`
6956+
Input signature: a space-separated subset of the tokens "pos", "vel", "ff" and "voltage", required in this
6957+
canonical order. The ``pos`` and ``vel`` inputs are setpoints for the on-board
6958+
:ref:`controller<actuator-dcmotor-controller>`, and ``ff`` is a torque feedforward added to its output, as for
6959+
:ref:`pid/input<actuator-pid-input>`. The ``voltage`` input is different in kind: it is the raw terminal voltage
6960+
of the physical device, applied downstream of the controller and its :at-val:`Vmax` clamp.
6961+
``input="voltage"`` (the default) is the plain voltage-commanded motor. Absent setpoint inputs are fixed at zero.
6962+
The keyword "none" selects the empty signature: the actuator has no control inputs and is purely
6963+
passive, useful for modeling :ref:`friction<actuator-dcmotor-lugre>` and :ref:`cogging<actuator-dcmotor-cogging>`
6964+
as passive joint forces. The terminal voltage is zero, so back-EMF drives current through the (shorted) motor and
6965+
brakes the joint; setting :ref:`motorconst<actuator-dcmotor-motorconst>` to zero disables the electrical branch.
6966+
(see `tech note <_static/dcmotor.pdf>`__, Section 2.5)
69536967

69546968
.. _actuator-dcmotor-controller:
69556969

69566970
:at:`controller`: :at-val:`real(6), "0 0 0 0 0 0"`
69576971
PID controller parameters, defined as :at:`controller` = ":at-val:`kp` :at-val:`ki` :at-val:`kd`
6958-
:at-val:`slewmax` :at-val:`Imax` :at-val:`Vmax`". Depending on the :at:`input` mode, the controller stabilizes
6959-
either position or velocity. If the :at:`input` mode is voltage, :at-val:`kp`, :at-val:`ki`, :at-val:`kd` are
6960-
ignored. :at-val:`Vmax` sets the maximum drive voltage :math:`v_{\max}` (Volt); in position/velocity modes it clamps
6961-
the controller output, in voltage mode it clamps the control signal (if :at:`ctrlrange` is also set, the tighter
6962-
limit wins). A value of 0 (the default) disables the respective feature. When positive, :at-val:`slewmax` limits the
6963-
setpoint rate-of-change, :at-val:`Imax` clamps the integrator state (anti-windup), and :at-val:`Vmax` clamps the
6964-
drive voltage. (see `tech note <_static/dcmotor.pdf>`__, Section 2.5)
6972+
:at-val:`slewmax` :at-val:`Imax` :at-val:`Vmax`". The gains are in torque space, as for
6973+
:ref:`pid<actuator-pid>`: the controller commands the torque
6974+
:math:`\tau = k_p (u_{pos} - l) + k_d (u_{vel} - \dot{l}) + k_i x_I + u_{f\!f}` over the inputs present in the
6975+
:ref:`input<actuator-dcmotor-input>` signature, absent setpoints being fixed at zero, and drives the voltage
6976+
:math:`v = (R/K)\,\tau + K \dot{l}`, the second term compensating back-EMF as in a current-controlled driver:
6977+
commanded torque is delivered exactly until a limit is reached. Torque-space gains from datasheet voltage-space
6978+
values are obtained by multiplying by :math:`K/R`. The integrator state
6979+
:math:`x_I` accumulates position error and requires the ``pos`` input; controller gains require a controller
6980+
input and a positive :ref:`motorconst<actuator-dcmotor-motorconst>`.
6981+
A value of 0 (the default) disables the respective feature. When positive, :at-val:`slewmax` limits the
6982+
rate-of-change of the first input (position setpoint in rad/s, or with signatures lacking ``pos``, velocity
6983+
setpoint or torque feedforward), :at-val:`Imax` clamps the integrator state (anti-windup), and :at-val:`Vmax`
6984+
clamps the drive voltage :math:`v_{\max}` (Volt), upstream of the raw ``voltage`` input.
6985+
(see `tech note <_static/dcmotor.pdf>`__, Section 2.5)
69656986

69666987
.. _actuator-plugin:
69676988

@@ -6982,7 +7003,7 @@ Associate this actuator with an :ref:`engine plugin<exPlugin>`. Either :at:`plug
69827003

69837004
.. _actuator-plugin-dyntype:
69847005

6985-
:at:`dyntype`: :at-val:`[none, integrator, filter, filterexact, pid, muscle, user], "none"`
7006+
:at:`dyntype`: :at-val:`[none, integrator, filter, filterexact, pid, dcmotor, muscle, user], "none"`
69867007
Activation dynamics type for the actuator. The available dynamics types were already described in the :ref:`Actuation
69877008
model <geActuation>` section. If :ref:`dyntype<actuator-general-dyntype>` is not "none", an activation variable will
69887009
be added to the actuator. This variable will be added after any activation state computed by the plugin (see

‎doc/_static/dcmotor.pdf‎

33.3 KB
Binary file not shown.

‎doc/changelog.rst‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ Actuation
3131
identical to :ref:`position<actuator-position>`. The input signature is any subset of ``[pos, vel, ff]``, selected
3232
by :ref:`input<actuator-pid-input>`; absent setpoint inputs are fixed at zero, so the control vector contains no
3333
inert entries.
34+
- The :ref:`dcmotor<actuator-dcmotor>` on-board controller is redesigned: the
35+
:ref:`input<actuator-dcmotor-input>` attribute selects any subset of ``[pos, vel, ff, voltage]``, where ``pos``
36+
and ``vel`` are setpoints for the controller, ``ff`` is a torque feedforward, and ``voltage`` is the raw terminal
37+
voltage (the default, a plain voltage-commanded motor). Controller gains are in torque space, as for
38+
:ref:`pid<actuator-pid>`, and the drive voltage compensates back-EMF as in a current-controlled driver: commanded
39+
torque is delivered exactly until a limit is reached. The keyword ``input="none"`` selects the empty signature:
40+
the actuator has no control inputs and is purely passive, so friction, cogging and back-EMF braking can be used
41+
as passive joint forces.
42+
43+
.. admonition:: Breaking API changes
44+
:class: attention
45+
46+
- The mode-flag semantics of :ref:`dcmotor/input<actuator-dcmotor-input>` ("voltage", "position", "velocity",
47+
selecting the interpretation of a single control) are replaced by input signatures, and the controller gains
48+
changed from voltage space to torque space. The old velocity mode's integral term (integrated-velocity
49+
tracking) is retired without replacement; the integrator always accumulates position error.
50+
51+
**Migration:** Voltage-commanded motors (the default) are unchanged. Replace ``input="position"`` with
52+
``input="pos"`` and ``input="velocity"`` with ``input="vel"``, and multiply the controller gains by
53+
:math:`K/R` (torque per volt). The motor's back-EMF damping, previously felt in addition to the controller's
54+
damping, is now compensated: to preserve behavior when the velocity setpoint is zero, add :math:`K^2/R` to the
55+
converted :at-val:`kd`.
3456

3557
Engine
3658
^^^^^^

0 commit comments

Comments
 (0)
⌂ 换网址