Skip to main content

UAV dynamics simulation

Before using the Python API, execute FlightGoggles binary as described in Using the FlightGoggles Renderer

Users can provide input to the UAV in three different ways: directly command motor speeds, control the vehicle with angular rate controller, and control with waypoints controller.

PY
 - proceed_motor_speed(vehicle_id, motor_speed_command, duration)
 - proceed_angular_rate(vehicle_id, angular_rate_command, thrust_command, duration)
 - proceed_waypoint(vehicle_id, waypoint_command, duration)

Vehicle’s states are composed of timestamppositionvelocityacceleration_rawaccelerationattitude_euler_angleattitudegyro_rawangular_velocityangular_accelerationmotor_speed_rawmotor_speedand motor_acceleration.

PY
 - set_state_vehicle(vehicle_id, **kwargs)
 - get_state(vehicle_id)

The camera’s position and attitude can be manually changed by set_state_camera and the latest camera image can be obtained by get_camera_image.

CODE
 - set_state_camera(camera_id, position, attitude)
 - get_camera_image(camera_id)

This is the example code to run UAV simulation:

PY
import numpy as np
from IPython.display import HTML, display
from flightgoggles.env import flightgoggles_env

if __name__ == "__main__":
    env = flightgoggles_env()
    env.set_state_vehicle(vehicle_id="uav1", attitude_euler_angle=np.array([0.,0.,-np.pi/2]))
    current_pos = env.get_state("uav1")["position"]
    current_att = env.get_state("uav1")["attitude_euler_angle"]
    target_pose = np.zeros(4)
    target_pose[:3] = current_pos + np.array([9.0,0.0,0.0])
    target_pose[3] = current_att[2] + np.pi/2
    
    for j in range(400):
        env.proceed_waypoint("uav1", target_pose, 0.01)

    ani_set = env.plot_state_video(flag_save=False, filename="uav")
    display(HTML(ani_set["cam1"].to_html5_video()))
    env.close()

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.