Skip to content

Commit

Permalink
add env
Browse files Browse the repository at this point in the history
  • Loading branch information
AOS55 committed Oct 2, 2023
1 parent e1d8b47 commit 428a32e
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions flyer_env/envs/flyer_env.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import Dict, Text
import sys
import os
import numpy as np

from flyer_env import utils
from flyer_env.aircraft import ControlledAircraft
from flyer_env.envs.common.abstract import AbstractEnv
from flyer_env.envs.common.action import Action
from pyflyer import World, Aircraft
Expand Down Expand Up @@ -42,29 +44,42 @@ def default_config(cls) -> dict:
return config

def _reset(self, seed) -> None:
# TODO: Setup all the reset attributes
if not seed: seed = 1 # set seed to 1 if None
print(f'self.seed: {seed}')
if not seed: seed = 1 # set seed to 1 if None TODO: set to be random on None, look @ HighwayEnv
self._create_world(seed)
self._create_aircraft()
self._create_goal(seed)

def _create_world(self, seed) -> None:
"""Create the world map"""
self.world = World()
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "assets")
self.world.assets_dir = path
self.world.create_map(seed)
return

def _create_aircraft(self) -> None:
"""Create an aircraft to fly around the world"""
aircraft = Aircraft()
aircraft.reset(
pos=[0.0, 0.0, -1000.0],
heading=0.0,
airspeed=100.0
)
self.world.add_aircraft(aircraft)
self.controlled_vehicles = self.world.vehicles
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data/")
start_pos = [0.0, 0.0, -1000.0]
heading = 0.0
airspeed = 100.0

if self.config["action"]["type"] == "ContinuousAction":
vehicle = Aircraft(data_path=path)
vehicle.reset(
pos=start_pos,
heading=heading,
airspeed=airspeed
)
self.world.add_aircraft(vehicle)
else:
vehicle = ControlledAircraft(
position=start_pos,
heading=heading,
speed=airspeed
)
self.world.add_aircraft(vehicle.aircraft)
self.controlled_vehicles = vehicle

def _create_goal(self, seed) -> None:
"""Create a random goal in 3D space to navigate to, based on the aircraft's initial starting position"""
Expand All @@ -83,8 +98,6 @@ def get_goal():

g_pos = get_goal()
self.goal = g_pos

print(f'self.goal: {self.goal}')
return

def _reward(self, action: Action) -> float:
Expand Down

0 comments on commit 428a32e

Please sign in to comment.