Fork me on GitHub

bolero.representation.CartesianDMPBehavior

class bolero.representation.CartesianDMPBehavior(execution_time=1.0, dt=0.01, n_features=50, configuration_file=None)[source]

Cartesian Space Dynamical Movement Primitive.

Can be used to optimize the weights of a Cartesian Space DMP with a black box optimizer. This is a wrapper for the optional DMP module of bolero. Only the weights of the Cartesian Space DMP will be optimized. To optimize meta-parameters like the goal or the goal velocity, you have to implement your own wrapper. This can be a subclass of this wrapper that only overrides the methods that provide access to the parameters.

An object can be created either by passing a configuration file or the specification of a Cartesian Space DMP. A Cartesian Space DMP configuration file describes all parameters of the DMP model and it is not recommended to generate it manually.

Note that it is possible to change the trajectory significantly by setting the start and goal. However, do not expect to be able to convert the DMP between coordinate frames by setting only the start and goal. Because the position and the orientation parts are handled separately, this will result in completely different trajectories.

Parameters:
execution_time : float, optional (default: 1)

Execution time of the DMP in seconds.

dt : float, optional (default: 0.01)

Time between successive steps in seconds.

n_features : int, optional (default: 50)

Number of RBF features for each dimension of the DMP.

configuration_file : string, optional (default: None)

Name of a configuration file that should be used to initialize the DMP. If it is set all other arguments will be ignored.

__init__(execution_time=1.0, dt=0.01, n_features=50, configuration_file=None)[source]
can_step()[source]

Returns if step() can be called again.

Note that calling step() after this function returns False will not result in an error. The velocity and acceleration will be set to 0 and we hold the last position instead.

Returns:
can_step : bool

Can we call step() again?

get_args()

Get parameters for this estimator.

Returns:
params : mapping of string to any

Parameter names mapped to their values.

get_n_params()[source]

Get number of weights.

Returns:
n_params : int

Number of DMP weights

get_outputs(outputs)[source]

Get outputs of the last step.

Parameters:
outputs : array-like, shape = (7,)

Contains positions and rotations represented by quaternions, order (order: x, y, z, w, rx, ry, rz)

get_params()[source]

Get current weights.

Returns:
params : array-like, shape = (n_params,)

Current weights

imitate(X, alpha=0.0, allow_final_velocity=True)[source]

Learn weights of the DMP from demonstrations.

Parameters:
X : array, shape (7, n_steps)

The demonstrated trajectory (order: x, y, z, w, rx, ry, rz) to be imitated.

alpha : float >= 0, optional (default: 0)

The ridge parameter of linear regression. Small positive values of alpha improve the conditioning of the problem and reduce the variance of the estimates.

allow_final_velocity : bool, optional (default: True)

Allow the final velocity to be greater than 0

init(n_inputs, n_outputs)[source]

Initialize the behavior.

Parameters:
n_inputs : int

number of inputs

n_outputs : int

number of outputs

load_config(filename)[source]

Load DMP configuration.

Parameters:
filename : string

Name of YAML file

reset()[source]

Reset DMP.

save(dmp, filename)

Save DMP model.

Parameters:
dmp : object

DMP

filename : string

Name of YAML file

save_config(filename)[source]

Save DMP configuration.

Parameters:
filename : string

Name of YAML file

set_inputs(inputs)[source]

Set input for the next step.

Parameters:
inputs : array-like, shape = (7,)

Contains positions and rotations represented by quaternions, order (order: x, y, z, w, rx, ry, rz)

set_meta_parameters(keys, meta_parameters)[source]

Set DMP meta parameters.

Permitted meta-parameters:

x0 : array
Initial position
g : array
Goal
gd : array
Velocity at the goal
q0 : array
Initial rotation
qg : array
Final rotation
execution_time : float
New execution time
Parameters:
keys : list of string

names of meta-parameters

meta_parameters : list of float

values of meta-parameters

set_params(params)[source]

Set new weights.

Parameters:
params : array-like, shape = (n_params,)

New weights

step()[source]

Compute desired position, velocity and acceleration.

trajectory()[source]

Generate trajectory represented by the DMP in open loop.

The function can be used for debugging purposes.

Returns:
X : array, shape (n_steps, 7)

Positions and rotations (order: x, y, z, w, rx, ry, rz)