movement_primitives.dmp.DMP

class movement_primitives.dmp.DMP(n_dims, execution_time=1.0, dt=0.01, n_weights_per_dim=10, int_dt=0.001, p_gain=0.0, smooth_scaling=False)

Bases: WeightParametersMixin, DMPBase

Dynamical movement primitive (DMP).

Equation of transformation system (according to [1], Eq. 2.1):

\[\ddot{y} = (\alpha_y (\beta_y (g - y) - \tau \dot{y}) + f(z) + C_t) / \tau^2\]

and if smooth scaling is activated (according to [2]):

\[\ddot{y} = (\alpha_y (\beta_y (g - y) - \tau \dot{y} - \underline{\beta_y (g - y_0) z}) + f(z) + C_t) / \tau^2\]
Parameters:
n_dimsint

State space dimensions.

execution_timefloat, optional (default: 1)

Execution time of the DMP: \(\tau\).

dtfloat, optional (default: 0.01)

Time difference between DMP steps: \(\Delta t\).

n_weights_per_dimint, optional (default: 10)

Number of weights of the function approximator per dimension.

int_dtfloat, optional (default: 0.001)

Time difference for Euler integration of transformation system.

p_gainfloat, optional (default: 0)

Gain for proportional controller of DMP tracking error. The domain is [0, execution_time**2/dt].

smooth_scalingbool, optional (default: False)

Avoids jumps during the beginning of DMP execution when the goal is changed and the trajectory is scaled by interpolating between the old and new scaling of the trajectory.

References

[1]

Ijspeert, A. J., Nakanishi, J., Hoffmann, H., Pastor, P., Schaal, S. (2013). Dynamical Movement Primitives: Learning Attractor Models for Motor Behaviors. Neural Computation 25 (2), 328-373. DOI: 10.1162/NECO_a_00393, https://homes.cs.washington.edu/~todorov/courses/amath579/reading/DynamicPrimitives.pdf

[2]

Pastor, P., Hoffmann, H., Asfour, T., Schaal, S. (2009). Learning and Generalization of Motor Skills by Learning from Demonstration. In 2009 IEEE International Conference on Robotics and Automation, (pp. 763-768). DOI: 10.1109/ROBOT.2009.5152385, https://h2t.iar.kit.edu/pdf/Pastor2009.pdf

Attributes:
execution_time_float

Execution time of the DMP.

dt_float

Time difference between DMP steps. This value can be changed to adapt the frequency.

Methods

configure([t, start_y, start_yd, start_ydd, ...])

Set meta parameters.

get_weights()

Get weight vector of DMP.

imitate(T, Y[, regularization_coefficient, ...])

Imitate demonstration.

n_steps_open_loop(last_y, last_yd, n_steps)

Perform 'n_steps' steps.

open_loop([run_t, coupling_term, step_function])

Run DMP open loop.

reset()

Reset DMP to initial state and time.

set_weights(weights)

Set weight vector of DMP.

step(last_y, last_yd[, coupling_term, ...])

DMP step.

get_execution_time_

set_execution_time_

__init__(n_dims, execution_time=1.0, dt=0.01, n_weights_per_dim=10, int_dt=0.001, p_gain=0.0, smooth_scaling=False)

Methods

__init__(n_dims[, execution_time, dt, ...])

configure([t, start_y, start_yd, start_ydd, ...])

Set meta parameters.

get_execution_time_()

get_weights()

Get weight vector of DMP.

imitate(T, Y[, regularization_coefficient, ...])

Imitate demonstration.

n_steps_open_loop(last_y, last_yd, n_steps)

Perform 'n_steps' steps.

open_loop([run_t, coupling_term, step_function])

Run DMP open loop.

reset()

Reset DMP to initial state and time.

set_execution_time_(execution_time)

set_weights(weights)

Set weight vector of DMP.

step(last_y, last_yd[, coupling_term, ...])

DMP step.

Attributes

execution_time_

n_weights

Total number of weights configuring the forcing term.

configure(t=None, start_y=None, start_yd=None, start_ydd=None, goal_y=None, goal_yd=None, goal_ydd=None)

Set meta parameters.

Parameters:
tfloat, optional

Time at current step.

start_yarray, shape (n_dims,)

Initial state.

start_ydarray, shape (n_vel_dims,)

Initial velocity.

start_yddarray, shape (n_vel_dims,)

Initial acceleration.

goal_yarray, shape (n_dims,)

Goal state.

goal_ydarray, shape (n_vel_dims,)

Goal velocity.

goal_yddarray, shape (n_vel_dims,)

Goal acceleration.

get_weights()

Get weight vector of DMP.

Returns:
weightsarray, shape (N * n_weights_per_dim,)

Current weights of the DMP. N depends on the type of DMP

imitate(T, Y, regularization_coefficient=0.0, allow_final_velocity=False)

Imitate demonstration.

Parameters:
Tarray, shape (n_steps,)

Time for each step.

Yarray, shape (n_steps, n_dims)

State at each step.

regularization_coefficientfloat, optional (default: 0)

Regularization coefficient for regression.

allow_final_velocitybool, optional (default: False)

Allow a final velocity.

n_steps_open_loop(last_y, last_yd, n_steps)

Perform ‘n_steps’ steps.

Parameters:
last_yarray, shape (n_dims,)

Last state.

last_ydarray, shape (n_dims,)

Last time derivative of state (e.g., velocity).

n_stepsint

Number of steps.

Returns:
yarray, shape (n_dims,)

Next state.

ydarray, shape (n_dims,)

Next time derivative of state (e.g., velocity).

property n_weights

Total number of weights configuring the forcing term.

open_loop(run_t=None, coupling_term=None, step_function='rk4-cython')

Run DMP open loop.

Parameters:
run_tfloat, optional (default: execution_time)

Run time of DMP. Can be shorter or longer than execution_time.

coupling_termobject, optional (default: None)

Coupling term that will be added to velocity.

step_functionstr, optional (default: ‘rk4-cython’)

DMP integration function. Possible options: ‘rk4’, ‘euler’, ‘euler-cython’, ‘rk4-cython’.

Returns:
Tarray, shape (n_steps,)

Time for each step.

Yarray, shape (n_steps, n_dims)

State at each step.

Raises:
ValueError

If step function is unknown.

reset()

Reset DMP to initial state and time.

set_weights(weights)

Set weight vector of DMP.

Parameters:
weightsarray, shape (N * n_weights_per_dim,)

New weights of the DMP. N depends on the type of DMP

step(last_y, last_yd, coupling_term=None, step_function='rk4-cython')

DMP step.

Parameters:
last_yarray, shape (n_dims,)

Last state.

last_ydarray, shape (n_dims,)

Last time derivative of state (e.g., velocity).

coupling_termobject, optional (default: None)

Coupling term that will be added to velocity.

step_functionstr, optional (default: ‘rk4-cython’)

DMP integration function. Possible options: ‘rk4’, ‘euler’, ‘euler-cython’, ‘rk4-cython’.

Returns:
yarray, shape (n_dims,)

Next state.

ydarray, shape (n_dims,)

Next time derivative of state (e.g., velocity).