diff --git a/README.md b/README.md index 18840b1..9cbdc3f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The repository containing the code for **real** environment on a **real** DJI Te ![Cover Photo](/images/cover.png) - +![Cover Photo](/images/depth.gif) ![Cover Photo](/images/envs.png) diff --git a/aux_functions.py b/aux_functions.py index c5f1a16..f2672ef 100644 --- a/aux_functions.py +++ b/aux_functions.py @@ -2,7 +2,7 @@ # Created: 10/14/2019, 12:50 PM # Email: aqeel.anwar@gatech.edu import numpy as np -import os, subprocess +import os, subprocess, psutil import math import random import time @@ -11,6 +11,15 @@ import pygame from configs.read_cfg import read_cfg import matplotlib.pyplot as plt + +def close_env(env_process): + process = psutil.Process(env_process.pid) + for proc in process.children(recursive=True): + proc.kill() + process.kill() + + + def save_network_path(cfg): # Save the network to the directory network_path weights_type = 'Imagenet' @@ -28,17 +37,21 @@ def save_network_path(cfg): def start_environment(env_name): env_folder = os.path.dirname(os.path.abspath(__file__)) + "/unreal_envs/" + env_name + "/" path = env_folder + env_name + ".exe" - # print(path) env_process = subprocess.Popen(path) - time.sleep(6) + time.sleep(5) print("Successfully loaded environment: " + env_name) return env_process, env_folder def initialize_infer(env_cfg, client, env_folder): - c_z = (env_cfg.ceiling_z - env_cfg.player_start_z) / 100 - f_z = (env_cfg.floor_z - env_cfg.player_start_z) / 100 + + if not os.path.exists(env_folder+'results'): + os.makedirs(env_folder+'results') + + # Mapping floor to 0 height + c_z = (env_cfg.ceiling_z-env_cfg.floor_z)/100 + p_z = (env_cfg.player_start_z-env_cfg.floor_z)/100 plt.ion() fig_z = plt.figure() @@ -47,11 +60,11 @@ def initialize_infer(env_cfg, client, env_folder): ax_z.set_ylim(0, c_z) plt.title("Altitude variation") - start_posit = client.simGetVehiclePose() + # start_posit = client.simGetVehiclePose() fig_nav = plt.figure() ax_nav = fig_nav.add_subplot(111) - img = plt.imread(env_folder+ "floor.png") + img = plt.imread(env_folder+ env_cfg.floorplan) ax_nav.imshow(img) plt.axis('off') plt.title("Navigational map") @@ -59,7 +72,7 @@ def initialize_infer(env_cfg, client, env_folder): nav, = ax_nav.plot(env_cfg.o_x, env_cfg.o_y) - return f_z, fig_z, ax_z, line_z, fig_nav, ax_nav, nav + return p_z, fig_z, ax_z, line_z, fig_nav, ax_nav, nav def translate_action(action, num_actions): # action_word = ['Forward', 'Right', 'Left', 'Sharp Right', 'Sharp Left'] @@ -185,7 +198,7 @@ def connect_drone(ip_address='127.0.0.0', phase='infer'): old_posit = client.simGetVehiclePose() if phase == 'train': client.simSetVehiclePose( - airsim.Pose(airsim.Vector3r(0, 0, -2.2), old_posit.orientation), + airsim.Pose(airsim.Vector3r(0, 0, 0), old_posit.orientation), ignore_collison=True) elif phase == 'infer': client.enableApiControl(True) diff --git a/configs/config.cfg b/configs/config.cfg index b5c5dae..76c4e3c 100644 --- a/configs/config.cfg +++ b/configs/config.cfg @@ -3,7 +3,7 @@ run_name: Tello_indoor custom_load: True custom_load_path: models/trained/Indoor/indoor_cloud/Imagenet/e2e/e2e env_type: Indoor -env_name: indoor_cloud +env_name: indoor_frogeyes phase: infer diff --git a/configs/read_cfg.py b/configs/read_cfg.py index 287d27b..00489c9 100644 --- a/configs/read_cfg.py +++ b/configs/read_cfg.py @@ -13,7 +13,7 @@ def read_env_cfg(config_filename = 'configs/main.cfg'): config.read(config_filename) cfg.run_name = config.get('general_params', 'env_name') - cfg.custom_load_path = str(config.get('general_params', 'floorplan')) + cfg.floorplan = str(config.get('general_params', 'floorplan')) cfg.o_x = float(config.get('general_params', 'o_x').split(',')[0]) cfg.o_y = float(config.get('general_params', 'o_y').split(',')[0]) cfg.alpha = float(config.get('general_params', 'alpha').split(',')[0]) @@ -69,7 +69,7 @@ def read_cfg(config_filename = 'configs/main.cfg', verbose = False): cfg.update_target_interval = int(config.get('RL_params', 'update_target_interval').split(',')[0]) - if verbose: + if verbose and cfg.phase=='train': print('------------------------------ Config File ------------------------------') for param in cfg: spaces = ' '*(30-len(param)) diff --git a/environments/initial_positions.py b/environments/initial_positions.py index 9948785..fde3250 100644 --- a/environments/initial_positions.py +++ b/environments/initial_positions.py @@ -79,7 +79,7 @@ def indoor_complex(): ] level_name = ['Complex1', 'Complex2', 'Complex3', 'Complex4'] crash_threshold = 0.07 - initZ = -2 + initZ = 0 return orig_ip, level_name, crash_threshold, initZ # Test condo indoor initial positions @@ -115,7 +115,7 @@ def indoor_vanleer(): # The environment can be downloaded from # https://drive.google.com/drive/u/2/folders/1u5teth6l4JW2IXAkZAg1CbDGR6zE-v6Z orig_ip = [ - [-3080, -4280, 90], #Player Start + [-3100, -4530, 90], #Player Start [-1340, -2240, -90], [-3790, -5450, 180], [-3980, -1760, -90] diff --git a/images/depth.gif b/images/depth.gif new file mode 100644 index 0000000..8acab9c Binary files /dev/null and b/images/depth.gif differ diff --git a/main.py b/main.py index c213c1a..cbf47cf 100644 --- a/main.py +++ b/main.py @@ -46,7 +46,7 @@ elif cfg.phase == 'infer': nav_x=[] nav_y=[] altitude=[] - f_z, fig_z, ax_z, line_z, fig_nav, ax_nav, nav = initialize_infer(env_cfg=env_cfg, client=client, env_folder=env_folder) + p_z, fig_z, ax_z, line_z, fig_nav, ax_nav, nav = initialize_infer(env_cfg=env_cfg, client=client, env_folder=env_folder) nav_text = ax_nav.text(0, 0, '') # Initialize variables @@ -239,14 +239,14 @@ while active: client.moveByVelocityAsync(vx=0, vy=0, vz=0, duration=1).join() ax_nav.plot(nav_x.pop(), nav_y.pop(), 'r*', linewidth=20) file_path = env_folder + 'results/' - fig_z.savefig(file_path + 'altitude_variation.png', dpi=1000) - fig_nav.savefig(file_path + 'navigation.png', dpi=1000) - + fig_z.savefig(file_path + 'altitude_variation.png', dpi=500) + fig_nav.savefig(file_path + 'navigation.png', dpi=500) + close_env(env_process) print('Figures saved') else: posit = agent.client.simGetVehiclePose() distance = distance + np.linalg.norm(np.array([old_posit.position.x_val-posit.position.x_val,old_posit.position.y_val-posit.position.y_val])) - altitude.append(-posit.position.z_val-f_z) + altitude.append(-posit.position.z_val+p_z) x_val = posit.position.x_val y_val = posit.position.y_val