double_pendulum.analysis

Submodules

double_pendulum.analysis.benchmark

class double_pendulum.analysis.benchmark.benchmarker(controller, x0, dt, t_final, goal, epsilon=[0.1, 0.1, 1.0, 1.0], check_only_final_state=False, friction_compensation=True, integrator='runge_kutta', save_dir='benchmark')

Bases: object

benchmark(compute_model_robustness=True, compute_noise_robustness=True, compute_unoise_robustness=True, compute_uresponsiveness_robustness=True, compute_delay_robustness=True, mpar_vars=['Ir', 'm1r1', 'I1', 'b1', 'cf1', 'm2r2', 'm2', 'I2', 'b2', 'cf2'], modelpar_var_lists={'I1': [], 'I2': [], 'Ir': [], 'b1': [], 'b2': [], 'cf1': [], 'cf2': [], 'm1r1': [], 'm2': [], 'm2r2': []}, repetitions=10, meas_noise_mode='vel', meas_noise_sigma_list=[0.1, 0.3, 0.5], meas_noise_cut=0.5, meas_noise_vfilters=['None'], meas_noise_vfilter_args={'alpha': 0.3}, u_noise_sigma_list=[0.1, 0.5, 1.0], u_responses=[1.0, 1.1, 1.2, 1.3, 1.4, 1.5], delay_mode='vel', delays=[0.01, 0.02, 0.05, 0.1])
check_delay_robustness(delay_mode='posvel', delays=[])
check_goal_success(x_traj)
check_meas_noise_robustness(repetitions=10, meas_noise_mode='vel', meas_noise_sigma_list=[], meas_noise_cut=0.0, meas_noise_vfilters=['None'], meas_noise_vfilter_args={'lowpass_alpha': 0.3})
check_modelpar_robustness(mpar_vars=['Ir', 'm1r1', 'I1', 'b1', 'cf1', 'm2r2', 'm2', 'I2', 'b2', 'cf2'], var_lists={'I1': [], 'I2': [], 'Ir': [], 'b1': [], 'b2': [], 'cf1': [], 'cf2': [], 'm1r1': [], 'm2': [], 'm2r2': []})
check_perturbation_robustness(time_stamps=[], tau_perts=[])
check_unoise_robustness(repetitions=10, u_noise_sigma_list=[])
check_uresponsiveness_robustness(u_responses=[])
compute_cost(x_traj, u_traj, mode='free')
compute_ref_cost()
compute_success_measure(x_traj, u_traj)
set_cost_par(Q, R, Qf)
set_init_traj(trajectory_csv)
set_model_parameter(mass=[0.608, 0.63], length=[0.3, 0.2], com=[0.275, 0.166], damping=[0.081, 0.0], cfric=[0.093, 0.186], gravity=9.81, inertia=[0.05472, 0.02522], motor_inertia=0.0, torque_limit=[0.0, 6.0], model_pars=None)
simulate_and_get_cost(mass, length, com, damping, gravity, cfric, inertia, motor_inertia, torque_limit)

double_pendulum.analysis.benchmark_plot

double_pendulum.analysis.benchmark_plot.plot_benchmark_results(results_dir, filename='results.pkl', costlim=[0, 1000000.0], show=False, save=True, file_format='pdf', scale=1.0)
double_pendulum.analysis.benchmark_plot.plot_model_robustness_multi(results_dirs, costlim, show=True, labels=[], save_dir='')

double_pendulum.analysis.benchmark_scores

double_pendulum.analysis.benchmark_scores.get_delay_score(res_dict)
double_pendulum.analysis.benchmark_scores.get_measurement_noise_score(res_dict)
double_pendulum.analysis.benchmark_scores.get_model_score(res_dict)
double_pendulum.analysis.benchmark_scores.get_scores(results_dir, filename='results.pkl')
double_pendulum.analysis.benchmark_scores.get_unoise_score(res_dict)
double_pendulum.analysis.benchmark_scores.get_uresponsiveness_score(res_dict)

double_pendulum.analysis.leaderboard

double_pendulum.analysis.leaderboard.get_energy(X, U)

get_energy.

Get the mechanical energy used during the swingup.

Parameters:
Xarray-like

shape=(N, 4) states, units=[rad, rad, rad/s, rad/s] order=[angle1, angle2, velocity1, velocity2]

Uarray-like

shape=(N, 2) actuations/motor torques order=[u1, u2], units=[Nm]

Returns:
float

energy

double_pendulum.analysis.leaderboard.get_integrated_torque(T, U)

get_integrated_torque.

Get the (discrete) time integral over the torque.

Parameters:
Tarray-like

time points, unit=[s] shape=(N,)

Uarray-like

shape=(N, 2) actuations/motor torques order=[u1, u2], units=[Nm]

Returns:
float

integrated torque

double_pendulum.analysis.leaderboard.get_max_tau(U)

get_max_tau.

Get the maximum torque used in the trajectory.

Parameters:
Uarray-like

shape=(N, 2) actuations/motor torques order=[u1, u2], units=[Nm]

Returns:
float

maximum torque

double_pendulum.analysis.leaderboard.get_swingup_time(T, X, eps=[0.01, 0.01, 0.01, 0.01], has_to_stay=True, mpar=None, method='height', height=0.9)

get_swingup_time. get the swingup time from a data_dict.

Parameters:
Tarray-like

time points, unit=[s] shape=(N,)

Xarray-like

shape=(N, 4) states, units=[rad, rad, rad/s, rad/s] order=[angle1, angle2, velocity1, velocity2]

Uarray-like

shape=(N, 2) actuations/motor torques order=[u1, u2], units=[Nm]

epslist

list with len(eps) = 4. The thresholds for the swingup to be successfull ([position, velocity]) default = [1e-2, 1e-2, 1e-2, 1e-2]

has_to_staybool

whether the pendulum has to stay upright until the end of the trajectory default=True

Returns:
float

swingup time

double_pendulum.analysis.leaderboard.get_tau_smoothness(U)

get_tau_smoothness.

Get the standard deviation of the changes in the torque signal.

Parameters:
Uarray-like

shape=(N, 2) actuations/motor torques order=[u1, u2], units=[Nm]

Returns:
float

torque smoothness (std of changes)

double_pendulum.analysis.leaderboard.get_torque_cost(T, U, R=array([[1., 0.], [0., 1.]]))

get_torque_cost.

Get the running cost torque with cost parameter R. The cost is normalized with the timestep.

Parameters:
Tarray-like

time points, unit=[s] shape=(N,)

Uarray-like

shape=(N, 2) actuations/motor torques order=[u1, u2], units=[Nm]

Rnumpy array

running cost weight matrix (2x2)

Returns:
float

torque cost

double_pendulum.analysis.leaderboard.get_velocity_cost(T, X, Q=array([[1., 0.], [0., 1.]]))

get_torque_cost.

Get the running velocity cost with cost matrix Q. The cost is normalized with the timestep.

Parameters:
Tarray-like

time points, unit=[s] shape=(N,)

Xarray-like

shape=(N, 4) states, units=[rad, rad, rad/s, rad/s] order=[angle1, angle2, velocity1, velocity2]

Qnumpy array

running cost weight matrix (2x2)

Returns:
float

torque cost

double_pendulum.analysis.leaderboard.leaderboard_scores(data_paths, save_to, mpar, weights={'energy': 0.0, 'integ_tau': 0.1, 'max_tau': 0.1, 'swingup_time': 0.2, 'tau_cost': 0.0, 'tau_smoothness': 0.6}, normalize={'energy': 1.0, 'integ_tau': 10.0, 'max_tau': 1.0, 'swingup_time': 10.0, 'tau_cost': 10.0, 'tau_smoothness': 1.0}, link_base='', simulation=True)

leaderboard_scores. Compute leaderboard scores from data_dictionaries which will be loaded from data_paths. Data can be either from simulation or experiments (but for comparability it should only be one).

Parameters:
data_pathsdict

contains the names and paths to the trajectory data in the form: {controller1_name: {“csv_path”: data_path1, “name”: controller1_name, “username”: username1},

controller2_name: {“csv_path”: data_path2, “name”: controller2_name, “username”: username2}, …}

save_tostring

path where the result will be saved as a csv file

weightsdict

dictionary containing the weights for the different criteria in the form: {“swingup_time”: weight1,

“max_tau”: weight2, “energy”: weight3, “integ_tau”: weight4, “tau_cost”: weight5, “tau_smoothness”: weight6, “velocity_cost” : weight7} The weights should sum up to 1 for the final score to be in the range [0, 1].

normalizedict

dictionary containing normalization constants for the different criteria in the form: {“swingup_time”: norm1,

“max_tau”: norm2, “energy”: norm3, “integ_tau”: norm4, “tau_cost”: norm5, “tau_smoothness”: norm6, “velocity_cost”: norm7} The normalization constants should be the maximum values that can be achieved by the criteria so that after dividing by the norm the result is in the range [0, 1].

simulationbool

whether to load the simulaition trajectory data

link_basestring

base-link for hosting data. Not needed for local execution

double_pendulum.analysis.utils

double_pendulum.analysis.utils.get_par_list(x0, min_rel, max_rel, n)