from resonance.linear_systems import SimplePendulumSystem
sys = SimplePendulumSystem()
sys.constants
{'pendulum_mass': 0.0, 'pendulum_length': 0.0, 'acc_due_to_gravity': 0.0}
sys.coordinates
_SingleDoFCoordinatesDict([('angle', 0.0)])
sys.speeds
_SingleDoFCoordinatesDict([('angle_vel', 0.0)])
sys.coordinates['angle']
0.0
sys.constants['pendulum_mass'] = 1.0 # kg
sys.constants['pendulum_length'] = 1.0 # m
sys.constants['acc_due_to_gravity'] = 9.81 # m/s**2
import numpy as np
sys.coordinates['angle'] = np.deg2rad(10.0)
sys.constants
{'pendulum_mass': 1.0, 'pendulum_length': 1.0, 'acc_due_to_gravity': 9.81}
sys.coordinates
_SingleDoFCoordinatesDict([('angle', 0.17453292519943295)])
def calc_x(pendulum_length, angle):
return pendulum_length * np.sin(angle)
def calc_y(pendulum_length, angle):
return pendulum_length * np.cos(angle)
sys.measurements
{}
sys.add_measurement('x', calc_x)
sys.measurements
{'x': 0.17364817766693033}
sys.add_measurement('y', calc_y)
sys.measurements
{'x': 0.17364817766693033, 'y': 0.984807753012208}
sys.measurements['x']
0.17364817766693033
sys.coordinates['angle'] = np.deg2rad(20.0)
sys.measurements
{'x': 0.3420201433256687, 'y': 0.9396926207859084}
traj = sys.free_response(2.0)
traj
angle | angle_acc | angle_vel | x | y | |
---|---|---|---|---|---|
time | |||||
0.00 | 0.349066 | -3.424336 | 0.000000 | 0.342020 | 0.939693 |
0.01 | 0.348895 | -3.422656 | -0.034238 | 0.341859 | 0.939751 |
0.02 | 0.348381 | -3.417620 | -0.068442 | 0.341377 | 0.939927 |
0.03 | 0.347526 | -3.409230 | -0.102579 | 0.340573 | 0.940218 |
0.04 | 0.346330 | -3.397497 | -0.136615 | 0.339448 | 0.940625 |
... | ... | ... | ... | ... | ... |
1.96 | 0.345439 | -3.388754 | 0.157201 | 0.338609 | 0.940927 |
1.97 | 0.346841 | -3.402510 | 0.123242 | 0.339929 | 0.940451 |
1.98 | 0.347903 | -3.412930 | 0.089162 | 0.340927 | 0.940090 |
1.99 | 0.348624 | -3.420001 | 0.054994 | 0.341605 | 0.939844 |
2.00 | 0.349003 | -3.423718 | 0.020773 | 0.341961 | 0.939714 |
201 rows × 5 columns
%matplotlib widget
traj.plot(subplots=True)
Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …
array([<matplotlib.axes._subplots.AxesSubplot object at 0x7f29060c0b70>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f2906034048>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f2905fe4400>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f2905f97860>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f2905fcacc0>], dtype=object)
sys.free_response?
Signature: sys.free_response(final_time, initial_time=0.0, sample_rate=100, **kwargs) Docstring: Returns a data frame with monotonic time values as the index and columns for each coordinate and measurement at the time value for that row. Note that this data frame is stored on the system as the variable ``result`` until this method is called again, which will overwrite it. Parameters ========== final_time : float A value of time in seconds corresponding to the end of the simulation. initial_time : float, optional A value of time in seconds corresponding to the start of the simulation. sample_rate : integer, optional The sample rate of the simulation in Hertz (samples per second). The time values will be reported at the initial time and final time, i.e. inclusive, along with times space equally based on the sample rate. Returns ======= df : pandas.DataFrame A data frame indexed by time with all of the coordinates and measurements as columns. File: /opt/conda/lib/python3.6/site-packages/resonance/system.py Type: method