Skip to content

Commit

Permalink
fixing tests and old pursuit env
Browse files Browse the repository at this point in the history
  • Loading branch information
rallen10 committed Feb 24, 2023
1 parent 8f3eb1a commit 30c92d0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ conda activate kspdg
pytest tests/ksp_ingame_tests/test_pe1_e1_i3.py

# for additional tests, load a different mission in KSP:
# ESC > Quit to Main Menu > Exit to Main Menu > Play Missions > `lbg1_i2` > Continue
pytest tests/ksp_ingame_tests/test_lbg1_lg0_i2.py

# ESC > Quit to Main Menu > Exit to Main Menu > Play Missions > 20220516_PursuitEvade > Continue
pytest tests/ksp_ingame_tests/test_pursuit_v20220516.py
```
Expand Down
35 changes: 20 additions & 15 deletions src/kspdg/pe20220516/pursuit_v20220516.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022, MASSACHUSETTS INSTITUTE OF TECHNOLOGY
# Copyright (c) 2023, MASSACHUSETTS INSTITUTE OF TECHNOLOGY
# Subject to FAR 52.227-11 – Patent Rights – Ownership by the Contractor (May 2014).
# SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -104,10 +104,7 @@ def __init__(self):
self.reset()


def reset(self):

# connect to KRPC server and load mission save file
self.connect_and_load_on_reset()
def _reset_vessels(self) -> None:

# get vessel objects
self.vesReferee, self.vesEvade, self.vesPursue = self.conn.space_center.vessels[:3]
Expand Down Expand Up @@ -136,18 +133,23 @@ def reset(self):
self.vesEvade.control.rcs = True
self.vesPursue.control.rcs = True

# start process for evader maneuvers
def _reset_episode_metrics(self) -> None:
pass

def _start_bot_threads(self) -> None:
""" Start parallel thread to execute Evader's evasive maneuvers
"""

self.stop_evade_thread = False
self.evade_thread = Thread(target=self.evasive_maneuvers)
self.evade_thread.start()

# start process for checking episode termination
self.is_episode_done = False
self.stop_episode_termination_thread = False
self.episode_termination_thread = Thread(target=self.check_episode_termination)
self.episode_termination_thread.start()
# check that thread does not exist or is not running
if hasattr(self, "evade_thread"):
if self.evade_thread.is_alive():
raise ConnectionError("evade_thread is already running."+
" Close and join evade_thread before restarting")

return self.get_observation()
self.evade_thread = Thread(target=self.evasive_maneuvers)
self.evade_thread.start()

def step(self, action):
''' Apply thrust and torque actuation for speciefied time
Expand Down Expand Up @@ -187,6 +189,9 @@ def step(self, action):
info = {}

return obs, rew, self.is_episode_done, info

def get_info(self, observation: List, done: bool):
return {}

def convert_rhntw_to_rhpbody(self, v__rhntw: List[float]) -> List[float]:
'''Converts vector in right-handed NTW frame to pursuer vessel right-oriented body frame
Expand Down Expand Up @@ -272,7 +277,7 @@ def pursue_evade_relative_distance(self):
p_vesE_vesP__lhpbody = self.vesEvade.position(self.vesPursue.reference_frame)
return np.linalg.norm(p_vesE_vesP__lhpbody)

def check_episode_termination(self) -> bool:
def enforce_episode_termination(self) -> bool:
'''determine if episode termination conditions are met
Returns:
Expand Down
6 changes: 3 additions & 3 deletions tests/ksp_ingame_tests/test_pe1_e1_i3.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import numpy as np

import kspdg.utils.constants as C
from kspdg.pe1.pe1_e1_i3 import PursuitEnv_ePassive_i3_v0
from kspdg.pe1.e1_envs import PE1_E1_I3_Env

@pytest.fixture
def pe1_e1_i3_env():
'''setup and teardown of the PursuitEnvV20220516 object connected to kRPC server'''
env = PursuitEnv_ePassive_i3_v0()
env = PE1_E1_I3_Env()
env.reset()
yield env
env.close()
Expand Down Expand Up @@ -47,7 +47,7 @@ def test_get_info_0(pe1_e1_i3_env):
# ~~ ARRANGE ~~

if pe1_e1_i3_env is None:
env = PursuitEnv_ePassive_i3_v0()
env = PE1_E1_I3_Env()
env.reset()
else:
env = pe1_e1_i3_env
Expand Down
4 changes: 2 additions & 2 deletions tests/serverless_tests/test_serverless_pe1_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import numpy as np

import kspdg.utils.constants as C
from kspdg.pe1.base import PursuitEnv
from kspdg.pe1.pe1_base import PursuitEvadeGroup1Env


@pytest.fixture
def pe1_base_env():
"""setup and teardown of the PursuitEnvV20220516 object connected to kRPC server"""
env = PursuitEnv(None)
env = PursuitEvadeGroup1Env(None)
yield env

0 comments on commit 30c92d0

Please sign in to comment.