simple_pendulum.analysis
Analysis
Submodules
simple_pendulum.analysis.benchmark
Benchmarks
- class simple_pendulum.analysis.benchmark.benchmarker(dt=0.01, max_time=10.0, integrator='runge_kutta', benchmark_iterations=10)
Bases:
object
- benchmark(check_speed=True, check_energy=True, check_time=True, check_smoothness=True, check_consistency=True, check_robustness=True, check_sensitivity=True, check_torque_limit=True, save_path=None)
- check_consistency()
- check_reduced_torque_limit(tl=inf)
- check_regular_execution()
- check_robustness()
- check_sensitivity()
- check_speed(N=1000)
- init_pendulum(mass=0.57288, length=0.5, inertia=None, damping=0.15, coulomb_friction=0.0, gravity=9.81, torque_limit=2.0)
Initialize the pendulum parameters.
- Parameters:
- massfloat, default=0.57288
mass of the pendulum [kg]
- lengthfloat, default=0.5
length of the pendulum [m]
- inertiafloat, default=None
inertia of the pendulum [kg m^2] defaults to point mass inertia (mass*length^2)
- dampingfloat, default=0.15
damping factor of the pendulum [kg m/s]
- coulomb_frictionfloat, default=0.0
coulomb friciton of the pendulum [Nm]
- gravityfloat, default=9.81
gravity (positive direction points down) [m/s^2]
- torque_limitfloat, default=2.0
the torque_limit of the pendulum actuator
- set_controller(controller)
- simple_pendulum.analysis.benchmark.modify_pendulum_parameter(par)
Randomly modify a given parameter
simple_pendulum.analysis.leaderboard
- simple_pendulum.analysis.leaderboard.get_energy(data_dict)
get_energy.
Get the mechanical energy used during the swingup.
- Parameters:
- data_dictdict
dictionary containing the trajectory data. expected dictionary keys:
“des_time”
“des_pos”
“des_vel”
“des_tau”
“meas_time”
“meas_pos”
“meas_vel”
“meas_tau”
“vel_filt”
- Returns:
- float
energy
- simple_pendulum.analysis.leaderboard.get_integrated_torque(data_dict)
get_integrated_torque.
Get the (discrete) time integral over the torque.
- Parameters:
- data_dictdict
dictionary containing the trajectory data. expected dictionary keys:
“des_time”
“des_pos”
“des_vel”
“des_tau”
“meas_time”
“meas_pos”
“meas_vel”
“meas_tau”
“vel_filt”
- Returns:
- float
integrated torque
- simple_pendulum.analysis.leaderboard.get_max_tau(data_dict)
get_max_tau.
Get the maximum torque used in the trajectory.
- Parameters:
- data_dictdict
dictionary containing the trajectory data. expected dictionary keys:
“des_time”
“des_pos”
“des_vel”
“des_tau”
“meas_time”
“meas_pos”
“meas_vel”
“meas_tau”
“vel_filt”
- Returns:
- float
maximum torque
- simple_pendulum.analysis.leaderboard.get_swingup_time(data_dict, eps=[0.02, 0.2], has_to_stay=True)
get_swingup_time. get the swingup time from a data_dict.
- Parameters:
- data_dictdict
dictionary containing the trajectory data. expected dictionary keys:
“des_time”
“des_pos”
“des_vel”
“des_tau”
“meas_time”
“meas_pos”
“meas_vel”
“meas_tau”
“vel_filt”
- epslist
list with len(eps) = 2. The thresholds for the swingup to be successfull ([position, velocity]) default = [2e-2, 2e-1]
- has_to_staybool
whether the pendulum has to stay upright until the end of the trajectory default=True
- Returns:
- float
swingup time
- simple_pendulum.analysis.leaderboard.get_tau_smoothness(data_dict)
get_tau_smoothness.
Get the standard deviation of the changes in the torque signal.
- Parameters:
- data_dictdict
dictionary containing the trajectory data. expected dictionary keys:
“des_time”
“des_pos”
“des_vel”
“des_tau”
“meas_time”
“meas_pos”
“meas_vel”
“meas_tau”
“vel_filt”
- Returns:
- float
torque smoothness (std of changes)
- simple_pendulum.analysis.leaderboard.get_torque_cost(data_dict, R=1.0)
get_torque_cost.
Get the running cost torque with cost parameter R. The cost is normalized with the timestep.
- Parameters:
- data_dictdict
dictionary containing the trajectory data. expected dictionary keys:
“des_time”
“des_pos”
“des_vel”
“des_tau”
“meas_time”
“meas_pos”
“meas_vel”
“meas_tau”
“vel_filt”
- Rfloat
running cost weight
- Returns:
- float
torque cost
- simple_pendulum.analysis.leaderboard.leaderboard_scores(data_paths, save_to, 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})
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} 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} 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].
simple_pendulum.analysis.plot_policy
Policy Plots
- simple_pendulum.analysis.plot_policy.plot_policy(controller, position_range=[-3.141592653589793, 3.141592653589793], velocity_range=[-8, 8], samples_per_dim=100, plotstyle='2d', save_path=None)
Plot controller policy