Skip to content
You are reading the Flare Live 2.x (old) documentation. View 3.0 docs →

Sample Scenes ​

UAV Scene (Amovlab P600) ​

The original 2.x scene download is no longer provided. For the current 3.0 scene and controller, see the P600 tutorial.

Example control script:

python
import flcpy
import numpy as np

sim = flcpy.connect()
px4 = sim.get_object('p600/core/px4')
sensor = sim.get_object('p600/core/info')

control_frequency = 30.0
duration = 20.0

sim.start()
t = 0.0

while (t < duration):
    # Set control input (e.g. run a controller)
    px4_input = (0.0, 0.0, 0.0, 1.0, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.sin(t), np.nan) # This is the input vector

    t += 1.0 / control_frequency
    reply = sim.simulate_until(t,  {px4: px4_input}, [sensor])

    if reply.is_failed():
        print('Simulation failed!')
        break
    else:
        body_state = reply.get_output_of(sensor)

        # Run controller, log or record...
        p_x = body_state[0]
        p_y = body_state[1]
        p_z = body_state[2]
        print(f'x: {p_x:.2f}, y: {p_y:.2f}, z: {p_z:.2f}')

sim.clear()
sim.close()
print("Done.")

Robotic Fish Scene (Koi) ​

The original 2.x scene download is no longer provided. For the current 3.0 scene and controller, see the KOI tutorial.

Example control script:

python
import flcpy
import numpy as np

c = flcpy.connect()

joint0 = c.get_object('head/spine/servo')
joint1 = c.get_object('head/spine/spine01/servo')
joint2 = c.get_object('head/spine/spine01/spine02/servo')
joint3 = c.get_object('head/spine/spine01/spine02/spine03/servo')
joint4 = c.get_object('head/spine/spine01/spine02/spine03/tail_start/servo')

duration = 20.0  # s
control_dt = 0.02  # s

c.start()

print('Simulation Started.')

amp = np.deg2rad(20)  # rad
freq = 1.0  # Hz
phase_offset = np.deg2rad(60)  # rad
bias = np.deg2rad(0)  # rad

t = 0.0
while t < duration:
    input = {}
    input[joint0] = 0.2 * amp * np.sin(2 * np.pi * freq * t + phase_offset * 1.0) + 0.2 * bias
    input[joint1] = 0.4 * amp * np.sin(2 * np.pi * freq * t + phase_offset * 0.8) + 0.4 * bias
    input[joint2] = 0.6 * amp * np.sin(2 * np.pi * freq * t + phase_offset * 0.6) + 0.6 * bias
    input[joint3] = 0.8 * amp * np.sin(2 * np.pi * freq * t + phase_offset * 0.4) + 0.8 * bias
    input[joint4] = 1.0 * amp * np.sin(2 * np.pi * freq * t + phase_offset * 0.2) + 1.0 * bias
    
    reply = c.simulate_until(t + control_dt, input)
    t += control_dt
    
    print(f't={round(t, 3)}')

    if reply.is_failed():
        print('Simulation Failed.')
        break

print('Simulation Finished.')

c.close()