FlightGoggles : Moving objects in the scene

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

Users can add object models such as gate, uav, or car in FlightGoggles environments. Check out Python Parameters to how to add objects model in the environments. The objects' position and attitude can be manually changed by set_state_object and the current position and attitude can be obtained by get_state_object.

 - set_state_objects(object_id, position, attitude)
 - get_state_object(object_id)

This is the example configuration of moving objects:

state:
    sceneFilename: "Stata_GroundFloor"
    camWidth: 640
    camHeight: 480
    camFOV: 70.0
    camDepthScale: 0.20

renderer:
    0:
        inputPort: "10253"
        outputPort: "10254"

objects:
    0:
         ID: uav1
         prefabID: "BlackEagle"
         size_x: 5
         size_y: 5
         size_z: 5
    1:
         ID: gate1
         prefabID: "gate"
         size_x: 200
         size_y: 200
         size_z: 200
        
camera_model:
    0:
        ID: cam1
        channels: 3
        renderer: 0
        freq: 30
        outputShaderType: -1
        hasCollisionCheck: False
        initialPose: [-8.5, -18.5, -2, 1.0, 0, 0, 0]

vehicle_model:
    uav1:
        type: "uav"
        initialPose: [-6.5, -18.5, -1, 1.0, 0, 0, 0]
        imu_freq: 200
        objectsInfo:
            uav1:
                relativePose: [0, 0, 0, 0.707, 0, 0, -0.707]

In this configuration, we add two objects (uav and gate). The uav object is attached to the vehicle model uav1.

This is the sample code for simulation:

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

if __name__ == "__main__":
    env = flightgoggles_env()
    
    env.set_state_vehicle(vehicle_id="uav1", attitude_euler_angle=np.array([0.,0.,-np.pi/2]))
    target_pose = np.zeros(4)
    target_pose[:3] = env.get_state("uav1")["position"] + np.array([9.,-1.,0.])
    target_pose[3] = env.get_state("uav1")["attitude_euler_angle"][2] + np.pi/2
    
    # Set gate position
    env.set_state_object("gate1", 
        np.array([-2.5,-18.,-0.2]), 
        Euler2quat(np.array([0,-np.pi/2,0])))
    
    for j in range(200):
        env.proceed_waypoint(vehicle_id="uav1", 
            waypoint_command=target_pose, duration=0.01)

    ani_set = env.plot_state_video(flag_save=False, filename="uav", dpi=400)
    if "cam1" in ani_set.keys():
        display(HTML(ani_set["cam1"].to_html5_video()))
    env.close()

Fig 1. The result of the example code

Attachments:

python_api_uav.mp4 (video/mp4)
python_api_car.mp4 (video/mp4)
python_api_car.mp4 (video/mp4)
python_api_uav.mp4 (video/mp4)
moving_objects.mp4 (video/mp4)