From efb1def66a0867ee87cf1c8d065467be2e44b46f Mon Sep 17 00:00:00 2001 From: Spencer Teetaert Date: Thu, 9 Jun 2022 16:58:29 -0400 Subject: [PATCH] Changed package asset imports to use plg_resources library --- build_project.sh | 1 + gym_pybullet_drones/control/BaseControl.py | 4 +++- gym_pybullet_drones/envs/BaseAviary.py | 6 ++++-- .../envs/single_agent_rl/FlyThruGateAviary.py | 3 ++- gym_pybullet_drones/examples/compare.py | 3 ++- setup.py | 2 +- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/build_project.sh b/build_project.sh index 56a08fafc..f6acda8c6 100755 --- a/build_project.sh +++ b/build_project.sh @@ -4,4 +4,5 @@ poetry build pip install dist/gym_pybullet_drones-1.0.0-py3-none-any.whl cd tests python test_build.py +rm -rf results cd .. \ No newline at end of file diff --git a/gym_pybullet_drones/control/BaseControl.py b/gym_pybullet_drones/control/BaseControl.py index 44ae6f7ef..24b43163e 100644 --- a/gym_pybullet_drones/control/BaseControl.py +++ b/gym_pybullet_drones/control/BaseControl.py @@ -1,6 +1,7 @@ import os import numpy as np import xml.etree.ElementTree as etxml +import pkg_resources from gym_pybullet_drones.utils.enums import DroneModel @@ -198,7 +199,8 @@ def _getURDFParameter(self, """ #### Get the XML tree of the drone model to control ######## URDF = self.DRONE_MODEL.value + ".urdf" - URDF_TREE = etxml.parse(os.path.dirname(os.path.abspath(__file__))+"/../assets/"+URDF).getroot() + path = pkg_resources.resource_filename('gym_pybullet_drones', 'assets/'+URDF) + URDF_TREE = etxml.parse(path).getroot() #### Find and return the desired parameter ################# if parameter_name == 'm': return float(URDF_TREE[1][0][1].attrib['value']) diff --git a/gym_pybullet_drones/envs/BaseAviary.py b/gym_pybullet_drones/envs/BaseAviary.py index 711eacfc7..10793ec13 100644 --- a/gym_pybullet_drones/envs/BaseAviary.py +++ b/gym_pybullet_drones/envs/BaseAviary.py @@ -4,6 +4,7 @@ import collections from datetime import datetime import xml.etree.ElementTree as etxml +import pkg_resources from PIL import Image # import pkgutil # egl = pkgutil.get_loader('eglRenderer') @@ -453,7 +454,8 @@ def _housekeeping(self): p.setAdditionalSearchPath(pybullet_data.getDataPath(), physicsClientId=self.CLIENT) #### Load ground plane, drone and obstacles models ######### self.PLANE_ID = p.loadURDF("plane.urdf", physicsClientId=self.CLIENT) - self.DRONE_IDS = np.array([p.loadURDF(os.path.dirname(os.path.abspath(__file__))+"/../assets/"+self.URDF, + + self.DRONE_IDS = np.array([p.loadURDF(pkg_resources.resource_filename('gym_pybullet_drones', 'assets/'+self.URDF), self.INIT_XYZS[i,:], p.getQuaternionFromEuler(self.INIT_RPYS[i,:]), flags = p.URDF_USE_INERTIA_FROM_FILE, @@ -962,7 +964,7 @@ def _parseURDFParameters(self): files in folder `assets/`. """ - URDF_TREE = etxml.parse(os.path.dirname(os.path.abspath(__file__))+"/../assets/"+self.URDF).getroot() + URDF_TREE = etxml.parse(pkg_resources.resource_filename('gym_pybullet_drones', 'assets/'+self.URDF)).getroot() M = float(URDF_TREE[1][0][1].attrib['value']) L = float(URDF_TREE[0].attrib['arm']) THRUST2WEIGHT_RATIO = float(URDF_TREE[0].attrib['thrust2weight']) diff --git a/gym_pybullet_drones/envs/single_agent_rl/FlyThruGateAviary.py b/gym_pybullet_drones/envs/single_agent_rl/FlyThruGateAviary.py index ad0173424..ed37f4302 100644 --- a/gym_pybullet_drones/envs/single_agent_rl/FlyThruGateAviary.py +++ b/gym_pybullet_drones/envs/single_agent_rl/FlyThruGateAviary.py @@ -1,6 +1,7 @@ import os import numpy as np import pybullet as p +import pkg_resources from gym_pybullet_drones.utils.enums import DroneModel, Physics from gym_pybullet_drones.envs.single_agent_rl.BaseSingleAgentAviary import ActionType, ObservationType, BaseSingleAgentAviary @@ -72,7 +73,7 @@ def _addObstacles(self): """ super()._addObstacles() - p.loadURDF(os.path.dirname(os.path.abspath(__file__))+"/../../assets/architrave.urdf", + p.loadURDF(pkg_resources.resource_filename('gym_pybullet_drones', 'assets/architrave.urdf'), [0, -1, .55], p.getQuaternionFromEuler([0, 0, 0]), physicsClientId=self.CLIENT diff --git a/gym_pybullet_drones/examples/compare.py b/gym_pybullet_drones/examples/compare.py index cf3625324..991eadcfe 100644 --- a/gym_pybullet_drones/examples/compare.py +++ b/gym_pybullet_drones/examples/compare.py @@ -19,6 +19,7 @@ import argparse import pickle import numpy as np +import pkg_resources from gym_pybullet_drones.utils.utils import sync, str2bool from gym_pybullet_drones.utils.enums import DroneModel, Physics @@ -29,7 +30,7 @@ DEFAULT_PHYICS = Physics('pyb') DEFAULT_GUI = False DEFAULT_RECORD_VIDEO = False -DEFAULT_TRACE_FILE = os.path.dirname(os.path.abspath(__file__))+"/../assets/example_trace.pkl" +DEFAULT_TRACE_FILE = pkg_resources.resource_filename('gym_pybullet_drones', 'assets/example_trace.pkl') DEFAULT_OUTPUT_FOLDER = 'results' def run( diff --git a/setup.py b/setup.py index f62fef191..99f395bba 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ 'stable_baselines3', 'ray[rllib]' ], - packages=setuptools.find_packages(where="gym_pybullet_drones") + packages=setuptools.find_packages(where="gym_pybullet_drones"), package_dir={'':'gym_pybullet_drones'}, package_data={'gym_pybullet_drones': ['assets/*.*']}, long_description=long_description,