コード例 #1
0
def test_create_static_html():
    # derive simple system
    mass, stiffness, damping, gravity = symbols('m, k, c, g')
    position, speed = me.dynamicsymbols('x v')
    positiond = me.dynamicsymbols('x', 1)
    ceiling = me.ReferenceFrame('N')
    origin = me.Point('origin')
    origin.set_vel(ceiling, 0)
    center = origin.locatenew('center', position * ceiling.x)
    center.set_vel(ceiling, speed * ceiling.x)
    block = me.Particle('block', center, mass)
    kinematic_equations = [speed - positiond]
    total_force = mass * gravity - stiffness * position - damping * speed
    forces = [(center, total_force * ceiling.x)]
    particles = [block]
    kane = me.KanesMethod(ceiling,
                          q_ind=[position],
                          u_ind=[speed],
                          kd_eqs=kinematic_equations)
    kane.kanes_equations(forces, particles)
    mass_matrix = kane.mass_matrix_full
    forcing_vector = kane.forcing_full
    constants = (mass, stiffness, damping, gravity)
    coordinates = (position, )
    speeds = (speed, )
    system = (mass_matrix, forcing_vector, constants, coordinates, speeds)

    # integrate eoms
    evaluate_ode = generate_ode_function(*system)
    x0 = array([0.1, -1.0])
    args = {'constants': array([1.0, 1.0, 0.2, 9.8])}
    t = linspace(0.0, 10.0, 100)
    y = odeint(evaluate_ode, x0, t, args=(args, ))

    # create visualization
    sphere = Sphere()
    viz_frame = VisualizationFrame(ceiling, block, sphere)
    scene = Scene(ceiling, origin, viz_frame)
    scene.generate_visualization_json([position, speed], list(constants), y,
                                      args['constants'])

    # test static dir creation
    scene.create_static_html(overwrite=True)
    assert os.path.exists('static')
    assert os.path.exists('static/index.html')
    assert os.path.exists('static/data.json')

    # test static dir deletion
    scene.remove_static_html(force=True)
    assert not os.path.exists('static')
コード例 #2
0
ファイル: test_scene.py プロジェクト: nouiz/pydy
def test_create_static_html():
    # derive simple system
    mass, stiffness, damping, gravity = symbols('m, k, c, g')
    position, speed = me.dynamicsymbols('x v')
    positiond = me.dynamicsymbols('x', 1)
    ceiling = me.ReferenceFrame('N')
    origin = me.Point('origin')
    origin.set_vel(ceiling, 0)
    center = origin.locatenew('center', position * ceiling.x)
    center.set_vel(ceiling, speed * ceiling.x)
    block = me.Particle('block', center, mass)
    kinematic_equations = [speed - positiond]
    total_force = mass * gravity - stiffness * position - damping * speed
    forces = [(center, total_force * ceiling.x)]
    particles = [block]
    kane = me.KanesMethod(ceiling, q_ind=[position], u_ind=[speed],
                          kd_eqs=kinematic_equations)
    kane.kanes_equations(forces, particles)
    mass_matrix = kane.mass_matrix_full
    forcing_vector = kane.forcing_full
    constants = (mass, stiffness, damping, gravity)
    coordinates = (position,)
    speeds = (speed,)
    system = (mass_matrix, forcing_vector, constants, coordinates, speeds)

    # integrate eoms
    evaluate_ode = generate_ode_function(*system)
    x0 = array([0.1, -1.0])
    args = {'constants': array([1.0, 1.0, 0.2, 9.8])}
    t = linspace(0.0, 10.0, 100)
    y = odeint(evaluate_ode, x0, t, args=(args,))

    # create visualization
    sphere = Sphere()
    viz_frame = VisualizationFrame(ceiling, block, sphere)
    scene = Scene(ceiling, origin, viz_frame)
    scene.generate_visualization_json([position, speed], list(constants), y,
                                      args['constants'])

    # test static dir creation
    scene.create_static_html(overwrite=True)
    assert os.path.exists('static')
    assert os.path.exists('static/index.html')
    assert os.path.exists('static/data.json')

    # test static dir deletion
    scene.remove_static_html(force=True)
    assert not os.path.exists('static')
コード例 #3
0
ファイル: run.py プロジェクト: csu-hmc/gait2d
from pydy.viz import Scene

from pygait2d import derive, simulate

(mass_matrix, forcing_vector, kane, constants, coordinates, speeds,
 specified, visualization_frames, ground, origin) = derive.derive_equations_of_motion()

rhs = generate_ode_function(mass_matrix, forcing_vector,
                            constants, coordinates, speeds,
                            specified=specified, generator='cython')

constant_values = simulate.load_constants(constants,
                                          'data/example_constants.yml')

args = {'constants': np.array(constant_values.values()),
        'specified': np.zeros(9)}

time_vector = np.linspace(0.0, 10.0, num=1000)
initial_conditions = np.zeros(18)
initial_conditions[1] = 1.0  # set hip above ground
initial_conditions[3] = np.deg2rad(5.0)  # right hip angle
initial_conditions[6] = -np.deg2rad(5.0)  # left hip angle
trajectories = odeint(rhs, initial_conditions, time_vector, args=(args,))

scene = Scene(ground, origin, *visualization_frames)

scene.generate_visualization_json(coordinates + speeds, constants,
                                  trajectories, args['constants'])

scene.display()
コード例 #4
0
initial_conditions[6] = mean_of_gait_cycles['Left.Hip.Flexion.Angle'][0]
initial_conditions[7] = -mean_of_gait_cycles['Left.Knee.Flexion.Angle'][0]
initial_conditions[8] = -mean_of_gait_cycles['Left.Ankle.PlantarFlexion.Angle'][0] - np.pi / 2.0

initial_conditions[9] = mean_of_gait_cycles['RightBeltSpeed'][0]
initial_conditions[10] = mean_of_gait_cycles['RGTRO.VelY'][0]

initial_conditions[11] = mean_of_gait_cycles['Trunk.Somersault.Rate'][0]

initial_conditions[12] = mean_of_gait_cycles['Right.Hip.Flexion.Rate'][0]
initial_conditions[13] = -mean_of_gait_cycles['Right.Knee.Flexion.Rate'][0]
initial_conditions[14] = -mean_of_gait_cycles['Right.Ankle.PlantarFlexion.Rate'][0]

initial_conditions[15] = mean_of_gait_cycles['Left.Hip.Flexion.Rate'][0]
initial_conditions[16] = -mean_of_gait_cycles['Left.Knee.Flexion.Rate'][0]
initial_conditions[17] = -mean_of_gait_cycles['Left.Ankle.PlantarFlexion.Rate'][0]

initial_conditions = open_loop_states[:, 0]

# Integrate the equations of motion
trajectories = odeint(rhs, initial_conditions, time_vector, args=(args,))

# Visualize
scene = Scene(ground, origin, *visualization_frames)

scene.generate_visualization_json(coordinates + speeds, constants,
                                  trajectories, args['constants'])

scene.display()