frax
frax dynamics adapters for OpenSCvx.
The recommended entry-point is FraxDynamics, a DynamicsAdapter that goes
directly into the dynamics= slot of Problem and exposes the synthesized
State/Control objects on .states / .controls::
from frax.robots.franka_panda import load_panda
import openscvx as ox
dyn = ox.FraxDynamics(load_panda())
problem = ox.Problem(
dynamics=dyn,
states=dyn.states,
controls=dyn.controls,
...
)
Joint limits and torque bounds are read automatically from the robot's URDF and set on the State/Control objects. Override them after construction if needed::
q, qd = dyn.states
q.initial = np.array([0.0, -0.7854, 0.0, -2.3562, 0.0, 1.5708, 0.7854])
Because frax.Robot is registered as a JAX static pytree
(@jax.tree_util.register_static), it is captured safely inside the BYOF
callable without special handling.
The lower-level frax_dynamics factory is also public for advanced users who
need to assemble their own BYOF dynamics dict::
from openscvx.integrations import frax_dynamics
q = ox.State("q", shape=(robot.num_joints,))
qd = ox.State("qd", shape=(robot.num_joints,))
tau = ox.Control("tau", shape=(robot.num_actuated_joints,))
problem = ox.Problem(
dynamics={"q": qd},
byof={"dynamics": {"qd": frax_dynamics(robot, q=q, qd=qd, tau=tau)}},
states=[q, qd],
controls=[tau],
...
)
Note
frax uses Euler-angle / rotation-matrix representation for all joint DOFs,
including floating-base joints. There is no nq != nv split, so
dynamics_dict is always {"q": qd} regardless of robot type.
FraxDynamics
¶
Bases: DynamicsAdapter
First-class frax dynamics adapter for Problem.
Wraps a frax.Robot so it can be passed directly to the dynamics=
argument of Problem. The adapter constructs default q / qd State
objects and a tau Control matching the robot's joint count, exposes
them via .states / .controls, and routes the frax forward dynamics
through the BYOF channel internally — without requiring the user to know
about BYOF.
Joint limits and torque bounds are read from the robot's URDF and auto-populated on the State/Control objects. Override any of them after construction if you want tighter problem-specific bounds::
dyn = ox.FraxDynamics(load_panda())
q, qd = dyn.states
q.initial = np.array([0.0, -0.7854, 0.0, -2.3562, 0.0, 1.5708, 0.7854])
# tighten velocity limits for a slow approach
qd.max = np.full(7, 1.0)
Example
Franka Panda::
from frax.robots.franka_panda import load_panda
import openscvx as ox
dyn = ox.FraxDynamics(load_panda())
problem = ox.Problem(
dynamics=dyn,
states=dyn.states,
controls=dyn.controls,
constraints=[...],
N=50,
time=ox.Time(...),
)
Floating-base robots (robot.includes_floating_dof = True) are
supported. The tau Control covers only the num_actuated_joints
actuated DOFs; the adapter inserts the required zero-torque entries for the
unactuated floating-base DOFs internally.
Custom State/Control names are not supported — drop to the lower-level
frax_dynamics helper for that.
Auto-populated bounds
q.min/q.max: from the URDF<limit lower/upper>.qd.min/qd.max: from the URDF<limit velocity>(mirrored as±max_vel).tau.min/tau.max: from the URDF<limit effort>for the actuated joints.
frax's ±1e6 "no limit" sentinel (used for floating-base DOFs) is
mapped to ±inf on all of the above.
Source code in openscvx/integrations/frax.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
expand() -> Tuple[dict, dict]
¶
Return (dynamics_dict, byof_dict) for this frax robot.
frax always has nq == nv (no quaternion floating-base split), so
dynamics_dict is always {"q": qd} and the full joint
acceleration goes through BYOF.
Source code in openscvx/integrations/frax.py
frax_dynamics(robot: Any, *, q: 'State | slice', qd: 'State | slice', tau: 'Control | slice') -> Callable
¶
Wrap a frax.Robot as a BYOF dynamics function.
Returns a callable f(x, u, node, params) -> qdd (shape
(robot.num_joints,)) suitable for byof["dynamics"]["qd"].
For floating-base robots (robot.includes_floating_dof = True), the
tau control covers only the num_actuated_joints actuated DOFs.
Internally, the callable prepends six zeros to form the full
(num_joints,) torque vector before calling
robot.forward_dynamics. The floating-base DOFs are assumed to appear
first in the joint ordering (standard robotics convention, verified for
frax.load_g1).
robot is captured in the closure safely because frax.Robot is
decorated with @jax.tree_util.register_static, making it a hashable
JAX static type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robot
|
Any
|
A |
required |
q
|
'State | slice'
|
Position state (or slice into the unified |
required |
qd
|
'State | slice'
|
Velocity state (or slice). Length must equal |
required |
tau
|
'Control | slice'
|
Control variable (or slice into the unified |
required |
Returns:
| Type | Description |
|---|---|
Callable
|
A function |
Callable
|
dynamics signature. The output is |
Callable
|
vector of shape |
Example
Franka Panda joint-space dynamics::
from frax.robots.franka_panda import load_panda
import openscvx as ox
from openscvx.integrations import frax_dynamics
robot = load_panda()
q = ox.State("q", shape=(robot.num_joints,))
qd = ox.State("qd", shape=(robot.num_joints,))
tau = ox.Control("tau", shape=(robot.num_actuated_joints,))
qdd = frax_dynamics(robot, q=q, qd=qd, tau=tau)
problem = ox.Problem(
dynamics={"q": qd},
byof={"dynamics": {"qd": qdd}},
states=[q, qd],
controls=[tau],
...
)
Source code in openscvx/integrations/frax.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |