Skip to content

ssqpy.model.constraints

constraints

Submodule containing classes for assigning constraints to optimization
stages. This includes the general StageConstraints class, as well as
predefined constraints for ease of use.

BoxRow

BoxRow(row, index, is_control=False)

A constraint row whose gradient is always +1 on one state or control
entry and zero elsewhere, so it bounds that entry directly

row property writable

row

Row of the constraint's difference vector

index property writable

index

Entry of dx, or of du if is_control is set

is_control property writable

is_control

Whether the row bounds a control instead of a state

StageConstraints

General abstract constraint function for an optimization stage \(k\): \(\boldsymbol{c}_k(\boldsymbol{x}, \boldsymbol{u})\)
Defines the required functions for stage constraints, while providing
default implementations for some

names

names()

Get all constraints' names for StageConstraints.

set_enabled

set_enabled(enabled)

Set enabled status for StageConstraints

enabled

enabled()

Whether this constraint is enabled

output_size

output_size()

Get the constraints function output size.

lower_bound

lower_bound()

Get the constraints' lower bound vector.

upper_bound

upper_bound()

Get the constraints' upper bound vector.

state_only_rows

state_only_rows()

Rows of the difference vector that depend only on \(\boldsymbol{x}\), so
their gradient with respect to \(\boldsymbol{u}\) is always zero
Defaults to none, so every row is treated as depending on \(\boldsymbol{u}\)

box_rows

box_rows()

Rows that bound a single state or control entry, which some QP solvers
handle more cheaply than general constraints
Defaults to none, so every row is passed as a general constraint

constraint_diff_size

constraint_diff_size()

Size of the difference vector: \(\boldsymbol{c}_k(\boldsymbol{x}_1, \boldsymbol{u}_1) \ominus \boldsymbol{c}_k(\boldsymbol{x}_2, \boldsymbol{u}_2)\)
Where \(\ominus\): the defined right_minus operator

right_minus

right_minus(x, y)

The \(\ominus\) operator, which outputs the difference of two constraint
vectors in tangent space

evaluate

evaluate(x, u)

Evaluate function \(f(\boldsymbol{x}, \boldsymbol{u})\)
Returns: output vector, \(n \times 1\)

gradient

gradient(x, u)

Get constraint Jacobians with respect to \(\boldsymbol{x}\) and \(\boldsymbol{u}\), evaluated at
given \((\boldsymbol{x}, \boldsymbol{u})\): \(\nabla_x \boldsymbol{c}_k(\boldsymbol{x}, \boldsymbol{u})\) and \(\nabla_u \boldsymbol{c}_k(\boldsymbol{x}, \boldsymbol{u})\)
Returns:
dX: gradient with respect to \(\boldsymbol{x}\), \(n_c \times n_{dx}\)
dU: gradient with respect to \(\boldsymbol{u}\), \(n_c \times n_u\)

hessprod_xx

hessprod_xx(x, u, mu)

Get product \(\nabla_{x} \mu_k^\top \nabla_{x} \boldsymbol{c}_k(\boldsymbol{x}, \boldsymbol{u})\)
Returns:
Pxx: Product, \(n_{dx} \times n_{dx}\)

hessprod_xu

hessprod_xu(x, u, mu)

Get product \(\nabla_{x} \mu_k^\top \nabla_{u} \boldsymbol{c}_k(\boldsymbol{x}, \boldsymbol{u})\)
Returns:
Pxu: Product, \(n_{dx} \times n_u\)

hessprod_uu

hessprod_uu(x, u, mu)

Get product \(\nabla_{u} \mu_k^\top \nabla_{u} \boldsymbol{c}_k(\boldsymbol{x}, \boldsymbol{u})\)
Returns:
Puu: Product, \(n_u \times n_u\)

JointAngleConstraint

JointAngleConstraint(model, lb, ub, name='')

Bases: StageConstraints

Predefined joint angle constraint

Creates a constraint on the joint angles of the model

Note: this constraint is separate to any potential innate constraints
\(\boldsymbol{q}_l \leq \boldsymbol{q} \leq \boldsymbol{q}_u\)

where:

  • \(\boldsymbol{q}_l\), \(\boldsymbol{q}_u\): Lower and upper configuration vectors
  • \(\boldsymbol{q}\): The model's joint configuration vector

Assumes:

  • The model joint configuration is the first part of the state vector (size model.nq()), appearing after the floating base (if present)

set_lower_bound

set_lower_bound(lower_bound)

Sets the lower bound.

set_upper_bound

set_upper_bound(upper_bound)

Sets the upper bound.

JointVelocityConstraint

JointVelocityConstraint(model, lb, ub, name='')

Bases: StageConstraints

Predefined joint velocity constraint

Creates a constraint on the joint velocities of the model

Note: this constraint is separate to any potential innate constraints
\(\boldsymbol{q}_{v,l} \leq \boldsymbol{q}_v \leq \boldsymbol{q}_{v, u}\)

where:

  • \(\boldsymbol{q}_{v,l}\), \(\boldsymbol{q}_{v,u}\): Lower and upper joint velocity vectors
  • \(\boldsymbol{q}_v\): The model's joint velocity vector

Assumes:

  • The model joint velocity is the final part of the state vector (size model.nv())

set_lower_bound

set_lower_bound(lower_bound)

Sets the lower bound.

set_upper_bound

set_upper_bound(upper_bound)

Sets the upper bound.

JointControlConstraint

JointControlConstraint(model, lb, ub, name='')

Bases: StageConstraints

Predefined joint control constraint

Creates a constraint on the joint part of the control vector

This can either act as a torque constraint (FD mode) or an acceleration
constraint (ID mode)

Note: this constraint is separate to any potential innate constraints
\(\boldsymbol{u}_{c,l} \leq \boldsymbol{u}_c \leq \boldsymbol{u}_{c, u}\)

where:

  • \(\boldsymbol{u}_{c,l}\), \(\boldsymbol{u}_{c,u}\): Lower and upper joint control vectors
  • \(\boldsymbol{u}_c\): The joint part of the control vector

Assumes:

  • The model control is the first part of the control vector (size model.nu())

set_lower_bound

set_lower_bound(lower_bound)

Sets the lower bound.

set_upper_bound

set_upper_bound(upper_bound)

Sets the upper bound.

FloatingBaseTranslationBound

FloatingBaseTranslationBound(model, lb, ub, reference_frame=..., center=..., name='')

Bases: StageConstraints

Floating base position bound constraint

Creates a linear bound constraint on the position of the floating base:
\(\boldsymbol{b}_l \leq R^\top (p_f - \boldsymbol{c}) \leq \boldsymbol{b}_u\)

where:

  • \(\boldsymbol{b}_l\), \(\boldsymbol{b}_u\): Lower and upper bound vectors on the base position (in \(\mathcal{R}^3\))
  • \(p_f\): Floating base position extracted from the system state
  • \(R\): Rotation of the reference frame the bounds are expressed in (World, Fixed, Local or Base, identity for World, with Local and Base both the base's axes)
  • \(\boldsymbol{c}\): Center the bounds are taken around (in \(\mathcal{R}^3\))

Assumes:

  • The Model contains a floating-base where the base position is the first part of the configuration vector (first 3 elements of size model.nq())

set_lower_bound

set_lower_bound(lower_bound)

Sets the lower bound, along the reference frame's axes.

set_upper_bound

set_upper_bound(upper_bound)

Sets the upper bound, along the reference frame's axes.

set_reference_frame

set_reference_frame(reference_frame)

Sets the reference frame the bounds are expressed in.

set_center

set_center(center)

Sets the center the bounds are taken around.

FloatingBaseRotationBound

FloatingBaseRotationBound(model, Rref, lb=..., ub=..., name='')

Bases: StageConstraints

Predefined floating base orientation bound

Creates a nonlinear bound constraint on the orientation of the floating base:
\(\boldsymbol{b}_l \leq \log_{SO3}(R_{ref}^\top R_f) \leq \boldsymbol{b}_u\)

where:

  • \(\boldsymbol{b}_l\), \(\boldsymbol{b}_u\): Lower and upper bound vectors on the orientation error (in \(\mathcal{R}^3\))
  • \(R_f\): Floating base rotation matrix
  • \(R_{ref}\): Reference rotation matrix

Assumes:

  • The model joint configuration is the first part of the state vector (size model.nq())
  • The floating base orientation is represented as a rotation matrix in SE(3) and can be extracted from the base pose in the system state

set_Rref

set_Rref(Rref)

Sets the reference rotation.

set_lower_bound

set_lower_bound(lower_bound)

Sets the lower bound.

set_upper_bound

set_upper_bound(upper_bound)

Sets the upper bound.

FloatingBasePoseBound

Bases: StageConstraints

Predefined floating base SE(3) pose bound

Creates a nonlinear bound constraint on the full pose (position + orientation)
of the floating base:
\(\boldsymbol{b}_l \leq \log_{SE3}(T_{ref}^{-1} T_f) \leq \boldsymbol{b}_u\)

where:

  • \(\boldsymbol{b}_l\), \(\boldsymbol{b}_u\): Lower and upper bound vectors on the pose error (in \(\mathcal{R}^6\))
  • \(T_f\): Floating base pose in SE(3)
  • \(T_{ref}\): Reference pose in SE(3)

Assumes:

  • The model joint configuration is the first part of the state vector (size model.nq())
  • The floating base pose is represented as an SE(3) transform and can be extracted from the base state in the system model

set_Tref

set_Tref(Tref)

Sets the reference pose.

set_tref

set_tref(tref)

Sets the translation of the reference pose.

set_Rref

set_Rref(Rref)

Sets the rotation of the reference pose.

set_lower_bound

set_lower_bound(lower_bound)

Sets the lower bound.

set_upper_bound

set_upper_bound(upper_bound)

Sets the upper bound.

FloatingBaseLinearVelocityBound

FloatingBaseLinearVelocityBound(model, lb, ub, reference_frame=..., name='')

Bases: StageConstraints

Predefined floating base linear velocity bound

Creates a linear bound constraint on the linear velocity of the floating base:
\(\boldsymbol{b}_l \leq \boldsymbol{v}_b \leq \boldsymbol{b}_u\)

where:

  • \(\boldsymbol{b}_l\), \(\boldsymbol{b}_u\): Lower and upper bound vectors (in \(\mathcal{R}^3\))
  • \(\boldsymbol{v}_b\): Floating base linear velocity vector (in \(\mathcal{R}^3\)), expressed in the reference frame (Local or Base by default, both the base frame, World or Fixed)

Assumes:

  • The model joint configuration is the first part of the state vector (size model.nq())
  • The model joint velocity is the final part of the state vector (size model.nv())

set_lower_bound

set_lower_bound(lower_bound)

Sets the lower bound, along the reference frame's axes.

set_upper_bound

set_upper_bound(upper_bound)

Sets the upper bound, along the reference frame's axes.

set_reference_frame

set_reference_frame(reference_frame)

Sets the reference frame the bounds are expressed in.

FloatingBaseAngularVelocityBound

FloatingBaseAngularVelocityBound(model, lb, ub, reference_frame=..., name='')

Bases: StageConstraints

Predefined floating base angular velocity bound

Creates a linear bound constraint on the angular velocity of the floating base:
\(\boldsymbol{b}_l \leq \boldsymbol{\omega}_b \leq \boldsymbol{b}_u\)

where:

  • \(\boldsymbol{b}_l\), \(\boldsymbol{b}_u\): Lower and upper bound vectors (in \(\mathcal{R}^3\))
  • \(\boldsymbol{\omega}_b\): Floating base angular velocity vector (in \(\mathcal{R}^3\)), expressed in the reference frame (Local or Base by default, both the base frame, World or Fixed)

Assumes:

  • The model joint configuration is the first part of the state vector (size model.nq())
  • The model joint velocity is the final part of the state vector (size model.nv())

set_lower_bound

set_lower_bound(lower_bound)

Sets the lower bound, along the reference frame's axes.

set_upper_bound

set_upper_bound(upper_bound)

Sets the upper bound, along the reference frame's axes.

set_reference_frame

set_reference_frame(reference_frame)

Sets the reference frame the bounds are expressed in.

FrameTranslationBound

FrameTranslationBound(model, frame, lb, ub, reference_frame=..., center=..., name='')

Bases: StageConstraints

Predefined 3D position bound for a given frame

Creates a linear bound constraint on the position of a frame of the given
model:
\(\boldsymbol{b}_l \leq R^\top (\boldsymbol{p}_f - \boldsymbol{c}) \leq \boldsymbol{b}_u\)

where:

  • \(\boldsymbol{b}_l\), \(\boldsymbol{b}_u\): Lower and upper bound vectors (in \(\mathcal{R}^3\))
  • \(\boldsymbol{p}_f\): Frame position vector (in \(\mathcal{R^3}\))
  • \(R\): Rotation of the reference frame the bounds are expressed in (World, Fixed, Local or Base, identity for World)
  • \(\boldsymbol{c}\): Center the bounds are taken around (in \(\mathcal{R}^3\))

Assumes:

  • The model joint configuration is the first part of the state vector (size model.nq())

set_lower_bound

set_lower_bound(lower_bound)

Sets the lower bound, along the reference frame's axes.

set_upper_bound

set_upper_bound(upper_bound)

Sets the upper bound, along the reference frame's axes.

set_reference_frame

set_reference_frame(reference_frame)

Sets the reference frame the bounds are expressed in.

set_center

set_center(center)

Sets the center the bounds are taken around.

FrameTerrainHeightBound

FrameTerrainHeightBound(model, frame, lb, ub, name='')

Bases: StageConstraints

Predefined terrain height bound for a given frame

Creates a bound constraint on the height of a frame above the model's
terrain: \(b_l \leq p_z - h(p_x, p_y) \leq b_u\)

where:

  • \(b_l\), \(b_u\): Lower and upper bounds on the height above the terrain
  • \(\boldsymbol{p}_f\): Frame position vector (in \(\mathcal{R^3}\))
  • \(h\): Terrain height at the frame's horizontal position

Assumes:

  • The model joint configuration is the first part of the state vector (size model.nq())

set_lower_bound

set_lower_bound(lower_bound)

Sets the lower bound.

set_upper_bound

set_upper_bound(upper_bound)

Sets the upper bound.

FrameRotationBound

FrameRotationBound(model, frame, Rref, lb=..., ub=..., name='')

Bases: StageConstraints

Predefined 3D orientation bound for a given frame

Creates a nonlinear bound constraint on the orientation of a frame:
\(\boldsymbol{b}_l \leq \log_{SO3}R_{ref}^\top R_f \leq \boldsymbol{b}_u\)

where:

  • \(\boldsymbol{b}_l\), \(\boldsymbol{b}_u\): Lower and upper bound vectors on the orientation error (in \(\mathcal{R}^3\))
  • \(R_f\): Frame rotation matrix
  • \(R_{ref}\): Reference rotation matrix

Assumes:

  • The model joint configuration is the first part of the state vector (size model.nq())

set_Rref

set_Rref(Rref)

Sets the reference rotation.

set_lower_bound

set_lower_bound(lower_bound)

Sets the lower bound.

set_upper_bound

set_upper_bound(upper_bound)

Sets the upper bound.

FramePoseBound

Bases: StageConstraints

Predefined SE(3) pose bound for a given frame

Creates a nonlinear bound constraint on the pose of a frame:
\(\boldsymbol{b}_l \leq \log_{SE3}(T_{ref}^{-1} T_f) \leq \boldsymbol{b}_u\)

where:

  • \(\boldsymbol{b}_l\), \(\boldsymbol{b}_u\): Lower and upper bound vectors on the pose error (in \(\mathcal{R}^6\))
  • \(T_f\): Frame pose in SE(3)
  • \(T_{ref}\): Reference pose in SE(3)

Assumes:

  • The model joint configuration is the first part of the state vector (size model.nq())

set_Tref

set_Tref(Tref)

Sets the reference pose.

set_tref

set_tref(tref)

Sets the translation of the reference pose.

set_Rref

set_Rref(Rref)

Sets the rotation of the reference pose.

set_lower_bound

set_lower_bound(lower_bound)

Sets the lower bound.

set_upper_bound

set_upper_bound(upper_bound)

Sets the upper bound.

FrameLinearVelocityBound

FrameLinearVelocityBound(model, frame, lb, ub, reference_frame=..., name='')

Bases: StageConstraints

Predefined 3D velocity bound for a given frame

Creates a linear bound constraint on the velocity of a frame of the given
model: \(\boldsymbol{b}_l \leq \boldsymbol{v}_f \leq \boldsymbol{b}_u\)

where:

  • \(\boldsymbol{b}_l\), \(\boldsymbol{b}_u\): Lower and upper bound vectors (in \(\mathcal{R}^3\))
  • \(\boldsymbol{v}_f\): Frame velocity vector (in \(\mathcal{R^3}\)), expressed in the reference frame (World by default, Local, Fixed or Base)

Assumes:

  • The model joint configuration is the first part of the state vector (size model.nq())
  • The model joint velocity is the final part of the state vector (size model.nv())

set_lower_bound

set_lower_bound(lower_bound)

Sets the lower bound, along the reference frame's axes.

set_upper_bound

set_upper_bound(upper_bound)

Sets the upper bound, along the reference frame's axes.

set_reference_frame

set_reference_frame(reference_frame)

Sets the reference frame the bounds are expressed in.

FrameAngularVelocityBound

FrameAngularVelocityBound(model, frame, lb, ub, reference_frame=..., name='')

Bases: StageConstraints

Predefined angular velocity bound for a given frame

Creates a linear bound constraint on the angular velocity of a frame of the
given model:
\(\boldsymbol{b}_l \leq \boldsymbol{\omega}_f \leq \boldsymbol{b}_u\)

where:

  • \(\boldsymbol{b}_l\), \(\boldsymbol{b}_u\): Lower and upper bound vectors (in \(\mathcal{R}^3\))
  • \(\boldsymbol{\omega}_f\): Frame angular velocity vector (in \(\mathcal{R}^3\)), expressed in the reference frame (Local by default, World, Fixed or Base)

Assumes:

  • The model joint configuration is the first part of the state vector (size model.nq())
  • The model joint velocity is the final part of the state vector (size model.nv())

set_lower_bound

set_lower_bound(lower_bound)

Sets the lower bound, along the reference frame's axes.

set_upper_bound

set_upper_bound(upper_bound)

Sets the upper bound, along the reference frame's axes.

set_reference_frame

set_reference_frame(reference_frame)

Sets the reference frame the bounds are expressed in.

CenterOfMassBound

CenterOfMassBound(model, lb, ub, reference_frame=..., center=..., name='')

Bases: StageConstraints

Predefined center of mass bound

Creates a linear bound constraint on the center of mass of the model:
\(\boldsymbol{b}_l \leq R^\top (\boldsymbol{c} - \boldsymbol{c}_0) \leq \boldsymbol{b}_u\)

where:

  • \(\boldsymbol{b}_l\), \(\boldsymbol{b}_u\): Lower and upper bound vectors (in \(\mathcal{R}^3\))
  • \(\boldsymbol{c}\) is the center of mass of the model
  • \(R\): Rotation of the reference frame the bounds are expressed in (World, Fixed or Base, identity for World)
  • \(\boldsymbol{c}_0\): Center the bounds are taken around (in \(\mathcal{R}^3\))

Assumes:

  • The model joint configuration is the first part of the state vector (size model.nq())

set_lower_bound

set_lower_bound(lower_bound)

Sets the lower bound, along the reference frame's axes.

set_upper_bound

set_upper_bound(upper_bound)

Sets the upper bound, along the reference frame's axes.

set_reference_frame

set_reference_frame(reference_frame)

Sets the reference frame the bounds are expressed in.

set_center

set_center(center)

Sets the center the bounds are taken around.

ContactConstraint

Bases: StageConstraints

Predefined contact constraint for a given frame
Creates a set of constraints that amount to a contact force constraint for
a frame
This consists of the following 4-point linearized friction cone constraints:

  • \(f_n \gt 0\)
  • \(|f_1| \leq \mu f_n\)
  • \(|f_2| \leq \mu f_n\) As well as the following constraint on the 3D position of the frame the contact is on:
  • \(p_z = h_z\) And, unless no_slip is false, the following no-slip constraint on the linear velocity of the frame:
  • \(\boldsymbol{v}_f = \boldsymbol{0}\) where:
  • \(f_n\) is the normal of the contact force (\(f_z\))
  • \(f_1\) is the first component of the tangential contact force (\(f_x\))
  • \(f_2\) is the second component of the tangential contact force (\(f_y\))
  • \(\mu\) is the static friction coefficient at the contact
  • \(p_z\) is the \(z-\)component of the translation of the frame the contact is on
  • \(h_z\) is the height of the terrain at point \((p_x, p_y)\)
  • \(\boldsymbol{v}_f\) is the linear velocity of the frame the contact is on Note that this constraint cannot be manually added in the Python library, use the Model's addContactConstraint method instead.

set_mu

set_mu(mu)

Sets the static friction coefficient.

set_max_normal_force

set_max_normal_force(max_normal_force)

Sets the maximum normal contact force.

set_eq_tol

set_eq_tol(eq_tol)

Sets the tolerance of the contact height constraint. An infinite tolerance leaves the height free.

set_terrain

set_terrain(terrain)

Sets the terrain this contact uses for its friction cone and height in
place of the model's terrain
Passing None restores the model's terrain