diff --git a/doc/XMLreference.rst b/doc/XMLreference.rst index fa963647..2f423abf 100644 --- a/doc/XMLreference.rst +++ b/doc/XMLreference.rst @@ -5317,13 +5317,13 @@ This element does not have custom attributes. It only has common attributes, whi This element creates a position servo. The underlying :el:`general` attributes are set as follows: -========= ======= ========= ======= +========= ======= ========= ========= Attribute Setting Attribute Setting -========= ======= ========= ======= +========= ======= ========= ========= dyntype none dynprm 1 0 0 gaintype fixed gainprm kp 0 0 -biastype affine biasprm 0 -kp 0 -========= ======= ========= ======= +biastype affine biasprm 0 -kp -kv +========= ======= ========= ========= This element has one custom attribute in addition to the common attributes: @@ -5377,6 +5377,11 @@ This element has one custom attribute in addition to the common attributes: :at:`kp`: :at-val:`real, "1"` Position feedback gain. +.. _actuator-position-kv: + +:at:`kv`: :at-val:`real, "0"` + Damping applied by the actuator. + When using this attribute, it is recommended to use the implicitfast or implicit :ref:`integrators`. .. _actuator-velocity: @@ -5385,7 +5390,9 @@ This element has one custom attribute in addition to the common attributes: This element creates a velocity servo. Note that in order create a PD controller, one has to define two actuators: a position servo and a velocity servo. This is because MuJoCo actuators are SISO while a PD controller takes two control -inputs (reference position and reference velocity). The underlying :el:`general` attributes are set as follows: +inputs (reference position and reference velocity). +When using this actuator, it is recommended to use the implicitfast or implicit :ref:`integrators`. +The underlying :el:`general` attributes are set as follows: ========= ======= ========= ======= Attribute Setting Attribute Setting @@ -5456,14 +5463,14 @@ This element creates an integrated-velocity servo. For more information, see the :ref:`Activation clamping ` section of the Modeling chapter. The underlying :el:`general` attributes are set as follows: -========== =========== ========= ======= +========== =========== ========= ========= Attribute Setting Attribute Setting -========== =========== ========= ======= +========== =========== ========= ========= dyntype integrator dynprm 1 0 0 gaintype fixed gainprm kp 0 0 -biastype affine biasprm 0 -kp 0 +biastype affine biasprm 0 -kp -kv actlimited true -========== =========== ========= ======= +========== =========== ========= ========= This element has one custom attribute in addition to the common attributes: @@ -5518,6 +5525,11 @@ This element has one custom attribute in addition to the common attributes: :at:`kp`: :at-val:`real, "1"` Position feedback gain. +.. _actuator-intvelocity-kv: + +:at:`kv`: :at-val:`real, "0"` + Damping applied by the actuator. + When using this attribute, it is recommended to use the implicitfast or implicit :ref:`integrators`. .. _actuator-damper: @@ -5525,8 +5537,9 @@ This element has one custom attribute in addition to the common attributes: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This element is an active damper which produces a force proportional to both velocity and control: ``F = - kv * velocity -* control``, where ``kv`` must be nonnegative. :at:`ctrlrange` is required and must also be nonnegative. The underlying -:el:`general` attributes are set as follows: +* control``, where ``kv`` must be nonnegative. :at:`ctrlrange` is required and must also be nonnegative. +When using this actuator, it is recommended to use the implicitfast or implicit :ref:`integrators`. +The underlying :el:`general` attributes are set as follows: =========== ======= ========= ======= Attribute Setting Attribute Setting @@ -7680,6 +7693,8 @@ slidersite, cranksite. .. _default-position-kp: +.. _default-position-kv: + :el-prefix:`default/` |-| **position** (?) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7736,6 +7751,8 @@ tendon, slidersite, cranksite. .. _default-intvelocity-kp: +.. _default-intvelocity-kv: + :el-prefix:`default/` |-| **intvelocity** (?) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/XMLschema.rst b/doc/XMLschema.rst index a8d0d0b3..702adeb2 100644 --- a/doc/XMLschema.rst +++ b/doc/XMLschema.rst @@ -778,7 +778,7 @@ | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | | | | | :ref:`jointinparent` | :ref:`tendon` | :ref:`slidersite` | :ref:`cranksite` | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | -| | | | :ref:`site` | :ref:`refsite` | :ref:`kp` | | | +| | | | :ref:`site` | :ref:`refsite` | :ref:`kp` | :ref:`kv` | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |_| actuator |br| |_| |L| | | .. table:: | @@ -810,6 +810,8 @@ | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | | | | | :ref:`cranksite` | :ref:`site` | :ref:`refsite` | :ref:`kp` | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +| | | | :ref:`kv` | | | | | +| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |_| actuator |br| |_| |L| | | .. table:: | | :ref:`damper | \* | :class: mjcf-attributes | @@ -1440,7 +1442,7 @@ | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | | | | | :ref:`gear` | :ref:`cranklength` | :ref:`user` | :ref:`group` | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | -| | | | :ref:`kp` | | | | | +| | | | :ref:`kp` | :ref:`kv` | | | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |_| default |br| |_| |L| | | .. table:: | @@ -1462,7 +1464,7 @@ | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | | | | | :ref:`actrange` | :ref:`gear` | :ref:`cranklength` | :ref:`user` | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | -| | | | :ref:`group` | :ref:`kp` | | | | +| | | | :ref:`group` | :ref:`kp` | :ref:`kv` | | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |_| default |br| |_| |L| | | .. table:: | diff --git a/doc/changelog.rst b/doc/changelog.rst index 826c1a1d..56904ed8 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -12,6 +12,10 @@ General robust for very small or large geom sizes. - Added :ref:`frame` to MJCF, a :ref:`meta-element` which defines a pure coordinate transformation on its direct children, without requiring a :ref:`body`. +- Added the :at:`kv` attribute to the :ref:`position` and :ref:`intvelocity` + actuators, for specifying actuator-applied damping. This can be used to implement a PD controller with 0 reference + velocity. When using this attribute, it is recommended to use the implicitfast or implicit + :ref:`integrators`. Plugins ^^^^^^^ diff --git a/src/user/user_objects.cc b/src/user/user_objects.cc index 3d7ef0b8..009ecebc 100644 --- a/src/user/user_objects.cc +++ b/src/user/user_objects.cc @@ -3876,7 +3876,7 @@ void mjCActuator::Compile(void) { throw mjCError(this, "invalid control range for actuator '%s' (id = %d)", name.c_str(), id); } if (actrange[0]>=actrange[1] && actlimited) { - throw mjCError(this, "invalid activation range for actuator '%s' (id = %d)", name.c_str(), id); + throw mjCError(this, "invalid actrange for actuator '%s' (id = %d)", name.c_str(), id); } if (actlimited && dyntype == mjDYN_NONE) { throw mjCError(this, "actrange specified but dyntype is 'none' in actuator '%s' (id = %d)", diff --git a/src/xml/xml_native_reader.cc b/src/xml/xml_native_reader.cc index 4121b2b9..57671db9 100644 --- a/src/xml/xml_native_reader.cc +++ b/src/xml/xml_native_reader.cc @@ -166,16 +166,16 @@ static const char* MJCF[nMJCF][mjXATTRNUM] = { "dyntype", "gaintype", "biastype", "dynprm", "gainprm", "biasprm", "actearly"}, {"motor", "?", "8", "ctrllimited", "forcelimited", "ctrlrange", "forcerange", "gear", "cranklength", "user", "group"}, - {"position", "?", "9", "ctrllimited", "forcelimited", "ctrlrange", "forcerange", + {"position", "?", "10", "ctrllimited", "forcelimited", "ctrlrange", "forcerange", "gear", "cranklength", "user", "group", - "kp"}, + "kp", "kv"}, {"velocity", "?", "9", "ctrllimited", "forcelimited", "ctrlrange", "forcerange", "gear", "cranklength", "user", "group", "kv"}, - {"intvelocity", "?", "10", "ctrllimited", "forcelimited", + {"intvelocity", "?", "11", "ctrllimited", "forcelimited", "ctrlrange", "forcerange", "actrange", "gear", "cranklength", "user", "group", - "kp"}, + "kp", "kv"}, {"damper", "?", "8", "forcelimited", "ctrlrange", "forcerange", "gear", "cranklength", "user", "group", "kv"}, @@ -379,22 +379,22 @@ static const char* MJCF[nMJCF][mjXATTRNUM] = { "ctrllimited", "forcelimited", "ctrlrange", "forcerange", "lengthrange", "gear", "cranklength", "user", "joint", "jointinparent", "tendon", "slidersite", "cranksite", "site", "refsite"}, - {"position", "*", "19", "name", "class", "group", + {"position", "*", "20", "name", "class", "group", "ctrllimited", "forcelimited", "ctrlrange", "forcerange", "lengthrange", "gear", "cranklength", "user", "joint", "jointinparent", "tendon", "slidersite", "cranksite", "site", "refsite", - "kp"}, + "kp", "kv"}, {"velocity", "*", "19", "name", "class", "group", "ctrllimited", "forcelimited", "ctrlrange", "forcerange", "lengthrange", "gear", "cranklength", "user", "joint", "jointinparent", "tendon", "slidersite", "cranksite", "site", "refsite", "kv"}, - {"intvelocity", "*", "20", "name", "class", "group", + {"intvelocity", "*", "21", "name", "class", "group", "ctrllimited", "forcelimited", "ctrlrange", "forcerange", "actrange", "lengthrange", "gear", "cranklength", "user", "joint", "jointinparent", "tendon", "slidersite", "cranksite", "site", "refsite", - "kp"}, + "kp", "kv"}, {"damper", "*", "18", "name", "class", "group", "forcelimited", "ctrlrange", "forcerange", "lengthrange", "gear", "cranklength", "user", @@ -1895,19 +1895,26 @@ void mjXReader::OneActuator(XMLElement* elem, mjCActuator* pact) { pact->biastype = mjBIAS_NONE; } - // position servo - else if (type=="position") { - // clear bias - mjuu_zerovec(pact->biasprm, mjNBIAS); - + // position or integrated velocity servo + else if (type=="position" || type=="intvelocity") { // explicit attributes ReadAttr(elem, "kp", 1, pact->gainprm, text); pact->biasprm[1] = -pact->gainprm[0]; + if (ReadAttr(elem, "kv", 1, pact->biasprm + 2, text)) { + if (pact->biasprm[2] < 0) + throw mjXError(elem, "kv cannot be negative"); + pact->biasprm[2] *= -1; + } + // implied parameters - pact->dyntype = mjDYN_NONE; pact->gaintype = mjGAIN_FIXED; pact->biastype = mjBIAS_AFFINE; + + if (type=="intvelocity") { + pact->dyntype = mjDYN_INTEGRATOR; + pact->actlimited = 1; + } } // velocity servo @@ -1925,22 +1932,6 @@ void mjXReader::OneActuator(XMLElement* elem, mjCActuator* pact) { pact->biastype = mjBIAS_AFFINE; } - // integrated velocity - else if (type=="intvelocity") { - // clear bias - mjuu_zerovec(pact->biasprm, mjNBIAS); - - // explicit attributes - ReadAttr(elem, "kp", 1, pact->gainprm, text); - - // implied parameters - pact->dyntype = mjDYN_INTEGRATOR; - pact->gaintype = mjGAIN_FIXED; - pact->biastype = mjBIAS_AFFINE; - pact->actlimited = 1; - pact->biasprm[1] = -pact->gainprm[0]; - } - // damper else if (type=="damper") { // clear gain diff --git a/test/engine/testdata/actuation/refsite.xml b/test/engine/testdata/actuation/refsite.xml index e4b0a2fa..eda8e284 100644 --- a/test/engine/testdata/actuation/refsite.xml +++ b/test/engine/testdata/actuation/refsite.xml @@ -13,7 +13,7 @@ - + - +