generators module
- class dynamapp.generators.ModelDataGenerator(model: Model, trajectory: Trajectory)[source]
Bases:
object
This class generates data based on a multibody system for a given trajectory. It computes the joint positions, velocities, accelerations, and torques based on the defined trajectory and model dynamics.
- Args:
model (Model): The multibody model to be used.
trajectory (Trajectory): The trajectory to generate data for.
- generate_trajectory_data()[source]
Generate full data for the trajectory with respect to the model's kinematics and dynamics.
- Returns:
- dict: A dictionary containing joint positions, velocities, accelerations, and torques
over the trajectory time.
- compute_velocities(q_data)[source]
Compute the joint velocities (q_dot) using the trajectory data.
- Args:
q_data (jnp.ndarray): Joint positions over the trajectory time.
- Returns:
jnp.ndarray: Joint velocities (q_dot).
- compute_accelerations(q_data, q_dot_data)[source]
Compute the joint accelerations (q_ddot) using the joint position and velocity data.
- Args:
q_data (jnp.ndarray): Joint positions over the trajectory time.
q_dot_data (jnp.ndarray): Joint velocities over the trajectory time.
- Returns:
jnp.ndarray: Joint accelerations (npoints * ndof).
- compute_torques(q_data, q_dot_data, q_ddot_data)[source]
Compute the joint torques using the Recursive Newton-Euler Algorithm (RNEA).
- Args:
q_data (jnp.ndarray): Joint positions over the trajectory time.
q_dot_data (jnp.ndarray): Joint velocities over the trajectory time.
q_ddot_data (jnp.ndarray): Joint accelerations over the trajectory time.
- Returns:
jnp.ndarray: Joint torques (tau).
- class dynamapp.generators.ModelStateDataGenerator(model_state: ModelState, num_samples: int, time_steps: int, noise_magnitude: float = 0.1, u_init: jax.numpy.ndarray = None, x_init: jax.numpy.ndarray = None)[source]
Bases:
object
Class to generate data for state-dependent multijoint system models.
This class simulates the ModelState class over time and generates a sequence of state, input, and output data.
- Args:
model_state - instance of the ModelState class
num_samples - number of samples to generate
time_steps - number of time steps per sample
noise_magnitude - magnitude of noise to add to the output
u_init - initial input vector
x_init - initial state vector
- Examples:
>>> model_state = ModelState(Imats, dhparams) >>> data_generator = ModelStateDataGenerator(model_state, num_samples=100, time_steps=200) >>> x_data, u_data, y_data = data_generator.generate_data()
- Attributes:
model_state - instance of the ModelState class
num_samples - number of samples to generate
time_steps - number of time steps per sample
noise_magnitude - magnitude of noise to add to the output
u_init - initial input vector
x_init - initial state vector
- generate_data() Tuple[jax.numpy.ndarray, jax.numpy.ndarray, jax.numpy.ndarray] [source]
Generate data for a multijoint system, consisting of input (u), state (x), and output (y).
- Args:
None
- Returns:
x_data : jnp.ndarray (num_samples, time_steps, 2*ndof) state data
u_data : jnp.ndarray (num_samples, time_steps, ndof) input data
y_data : jnp.ndarray (num_samples, time_steps, ndof) output data
- compute_data_statistics(x_data: jax.numpy.ndarray, u_data: jax.numpy.ndarray, y_data: jax.numpy.ndarray) dict [source]
Compute some statistics (mean, std) over the generated data.
- Args:
x_data : jnp.ndarray (num_samples, time_steps, 2*ndof) state data u_data : jnp.ndarray (num_samples, time_steps, ndof) input data y_data : jnp.ndarray (num_samples, time_steps, ndof) output data
- Returns:
stats : dict - statistics (mean, std) for state, input, and output data