newton.controllers.ControllerJointImpedance#
- class newton.controllers.ControllerJointImpedance(model, *, articulations=None, joints=None, stiffness, damping, use_gravity_compensation=True, use_coriolis_compensation=True, use_inertia_decoupling=True, has_qdd_feedforward=False)[source]#
Bases:
ControllerBaseJoint-space impedance controller with internally computed dynamics.
Implements the joint-space impedance control law. This model-based variant computes the mass matrix, gravity, and Coriolis terms itself: it evaluates forward kinematics and the enabled dynamics terms from
modelon everystep(), so the caller supplies only joint positions and velocities.modelis borrowed, not owned — it is never written to, and changes to it are visible to the controller immediately.Joint selection.
articulationsandjointsselect the controlled joints, following Label Matching: each is a list of model indices and/or label patterns (or a single pattern), matched againstarticulation_labeland the leaf component ofjoint_labelrespectively. The constructor resolves them to each selected joint’s starting coordinate/DOF index in the model — one entry per joint, not per DOF — and validates the result.q_startandqd_startexpose the resolved indices afterward, e.g. to gather/scatter a compact port against a simulation-sized array.Ports. Most arrays passed in and out are compact: one entry per controlled DOF — robot 0’s DOFs first, then robot 1’s — rather than one entry per DOF in the model.
inputs.joint_qandinputs.joint_qdare the exception and cover the whole model, since the dynamics terms depend on uncontrolled joints too. A compact port may be bound to a plain array, or to an indexed view of a simulation-sized array:outputs.joint_f = control.joint_f[controller.qd_start] # scatter to the sim
Each articulation in
modelis one robot. Only joints spanning a single coordinate and a single DOF can be controlled, since the PD error termq_des - qis only a well-defined scalar subtraction for those; every other joint (Fixed, or any multi-DOF type) is read for FK and dynamics but never actuated. The defaultjointsselection leaves such joints uncontrolled automatically; explicitly naming one injointsraisesValueErrorat construction instead, as does addressing a joint that belongs to no robot, or the same DOF twice.Supports heterogeneous robot fleets — robots may have different controlled-DOF counts, and a robot may be left uncontrolled entirely. An uncontrolled robot occupies no slot in any buffer and is masked out of the FK and dynamics evaluations, so its
body_qis left untouched.model_robot_countcounts every robot in the model,controlled_robot_countonly those with controlled DOFs.See also
ControllerJointImpedanceModelFree, which takes the mass matrix, gravity, and Coriolis terms as inputs instead of computing them from aModel.Impedance law (terms enabled at construction):
- τ = [M(q) if use_inertia_decoupling else I] · (q̈_des + Kp·Δq + Kd·Δq̇)
[C(q,q̇)·q̇ if use_coriolis_compensation else 0]
[g(q) if use_gravity_compensation else 0]
- Parameters:
model (Model) –
Modelwhose articulations are the robots. Articulations may mix controlled single-DOF joints with uncontrolled joints of any type. The controller’s device andrequires_gradare taken frommodel; every other array argument (stiffness,damping) must match both.articulations (list[int | str | re.Pattern[str]] | str | re.Pattern[str] | None) – Articulation indices or label patterns to control, as a list or as a single pattern.
Noneselects every articulation inmodel.joints (list[int | str | re.Pattern[str]] | str | re.Pattern[str] | None) – Model joint indices or label patterns to control within the selected articulations, as a list or as a single pattern.
Noneselects every joint spanning exactly one coordinate and one DOF — the only kind this controller can actuate — in each selected articulation; any other joint (Fixed, or a multi-DOF type such as a floating base) is left uncontrolled instead of rejected. A joint named explicitly is not filtered this way and still raisesValueErrorif it is not 1-coordinate/1-DOF.stiffness (wp.array[wp.float32] | float | None) – Position-error gain Kp. Units depend on
use_inertia_decoupling: [1/s²] when enabled, since the PD term is then an acceleration premultiplied by M(q); otherwise [N/m or N·m/rad]. Pass a scalar to apply the same gain to every controlled DOF, an array of shape [total_controlled_dofs] to set them individually, orNoneto readinputs.stiffnesseach step.damping (wp.array[wp.float32] | float | None) – Velocity-error gain Kd, [1/s] when
use_inertia_decouplingis enabled, otherwise [N·s/m or N·m·s/rad]. Same format asstiffness.use_gravity_compensation (bool) – Add gravity generalized forces to τ.
use_coriolis_compensation (bool) – Add Coriolis generalized forces to τ.
use_inertia_decoupling (bool) – Premultiply the PD term by M(q).
has_qdd_feedforward (bool) – Accept a desired-acceleration feedforward via
inputs.joint_qdd.
- class Inputs#
Bases:
objectInput struct returned by
input().Dynamics fields (mass matrix, gravity, Coriolis) are computed internally and do not appear here.
- damping: wp.array[wp.float32] | wp.indexedarray[wp.float32] | None#
Velocity-error gain Kd, shape [total_controlled_dofs]. [1/s] when
use_inertia_decouplingis enabled, otherwise [N·s/m or N·m·s/rad].Nonewhen gains are baked at construction.
- joint_q: wp.array[wp.float32] | wp.indexedarray[wp.float32]#
Current joint positions [m or rad], shape [model.joint_coord_count].
- joint_q_des: wp.array[wp.float32] | wp.indexedarray[wp.float32]#
Desired joint positions [m or rad], shape [total_controlled_dofs].
- joint_qd: wp.array[wp.float32] | wp.indexedarray[wp.float32]#
Current joint velocities [m/s or rad/s], shape [model.joint_dof_count].
- joint_qd_des: wp.array[wp.float32] | wp.indexedarray[wp.float32]#
Desired joint velocities [m/s or rad/s], shape [total_controlled_dofs].
- class Outputs#
Bases:
objectOutput struct returned by
output().- joint_f: wp.array[wp.float32] | wp.indexedarray[wp.float32]#
Joint torque command [N or N·m], shape [total_controlled_dofs].
- __init__(model, *, articulations=None, joints=None, stiffness, damping, use_gravity_compensation=True, use_coriolis_compensation=True, use_inertia_decoupling=True, has_qdd_feedforward=False)#
- is_graphable()#
- step(*, inputs, outputs, dt)#
Run one impedance-control step.
- property q_start: wp.array[wp.int32]#
Model coordinate index of each controlled joint, shape [total_controlled_dofs].
Use to gather or scatter a compact port against a simulation-sized coordinate array, e.g.
model.joint_q[controller.q_start].
- property qd_start: wp.array[wp.int32]#
Model DOF index of each controlled joint, shape [total_controlled_dofs].
Use to scatter a compact port into a simulation-sized array, e.g.
control.joint_f[controller.qd_start].