pub struct State {
pub q: DVec,
pub v: DVec,
pub ctrl: DVec,
pub time: f64,
pub body_xform: Vec<SpatialTransform>,
pub qfrc_external: DVec,
}Expand description
Mutable simulation state.
Fields§
§q: DVecGeneralized positions (joint angles/displacements).
v: DVecGeneralized velocities.
ctrl: DVecControl inputs.
If the model has actuators, entry i is the raw control of actuator i
(clamped to its ctrlrange and scaled by its gear before reaching the
dynamics — see Model::actuator_forces). If the model has no
actuators, entries are raw per-DOF generalized forces.
time: f64Simulation time.
body_xform: Vec<SpatialTransform>Body-to-world transforms for each body.
qfrc_external: DVecExternal generalized forces (e.g., from contacts).
Implementations§
Source§impl State
impl State
Sourcepub fn new(nq: usize, nv: usize, nbodies: usize) -> Self
pub fn new(nq: usize, nv: usize, nbodies: usize) -> Self
Create a zero-initialized state for nq position DOFs and nv velocity DOFs.
Sourcepub fn new_with_nu(nq: usize, nv: usize, nu: usize, nbodies: usize) -> Self
pub fn new_with_nu(nq: usize, nv: usize, nu: usize, nbodies: usize) -> Self
Create a zero-initialized state, sizing ctrl for nu actuators.
ctrl is sized max(nv, nu) so that both conventions (per-DOF forces
for unactuated models, per-actuator controls otherwise) fit.
Sourcepub fn kinetic_energy(&self, mass_matrix: &DMat) -> f64
pub fn kinetic_energy(&self, mass_matrix: &DMat) -> f64
Compute total kinetic energy given mass matrix. KE = 0.5 * v^T * M * v