enable continuous action space for racecarZEDGymEnv
disable SHARED_MEMORY connection (it was just some debug test)
This commit is contained in:
@@ -8,7 +8,7 @@ class BulletClient(object):
|
|||||||
|
|
||||||
def __init__(self, connection_mode=pybullet.DIRECT):
|
def __init__(self, connection_mode=pybullet.DIRECT):
|
||||||
"""Create a simulation and connect to it."""
|
"""Create a simulation and connect to it."""
|
||||||
self._client = pybullet.connect(pybullet.SHARED_MEMORY)
|
self._client = -1 #pybullet.connect(pybullet.SHARED_MEMORY)
|
||||||
if(self._client<0):
|
if(self._client<0):
|
||||||
self._client = pybullet.connect(connection_mode)
|
self._client = pybullet.connect(connection_mode)
|
||||||
self._shapes = {}
|
self._shapes = {}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class KukaGymEnv(gym.Env):
|
|||||||
self.terminated = 0
|
self.terminated = 0
|
||||||
self._p = p
|
self._p = p
|
||||||
if self._renders:
|
if self._renders:
|
||||||
cid = p.connect(p.SHARED_MEMORY)
|
cid = -1 #p.connect(p.SHARED_MEMORY)
|
||||||
if (cid<0):
|
if (cid<0):
|
||||||
cid = p.connect(p.GUI)
|
cid = p.connect(p.GUI)
|
||||||
p.resetDebugVisualizerCamera(1.3,180,-41,[0.52,-0.2,-0.33])
|
p.resetDebugVisualizerCamera(1.3,180,-41,[0.52,-0.2,-0.33])
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class RacecarZEDGymEnv(gym.Env):
|
|||||||
urdfRoot=pybullet_data.getDataPath(),
|
urdfRoot=pybullet_data.getDataPath(),
|
||||||
actionRepeat=10,
|
actionRepeat=10,
|
||||||
isEnableSelfCollision=True,
|
isEnableSelfCollision=True,
|
||||||
isDiscrete=True,
|
isDiscrete=False,
|
||||||
renders=True):
|
renders=True):
|
||||||
print("init")
|
print("init")
|
||||||
self._timeStep = 0.01
|
self._timeStep = 0.01
|
||||||
@@ -52,7 +52,13 @@ class RacecarZEDGymEnv(gym.Env):
|
|||||||
#print(observationDim)
|
#print(observationDim)
|
||||||
|
|
||||||
observation_high = np.array([np.finfo(np.float32).max] * observationDim)
|
observation_high = np.array([np.finfo(np.float32).max] * observationDim)
|
||||||
self.action_space = spaces.Discrete(9)
|
if (isDiscrete):
|
||||||
|
self.action_space = spaces.Discrete(9)
|
||||||
|
else:
|
||||||
|
action_dim = 2
|
||||||
|
self._action_bound = 1
|
||||||
|
action_high = np.array([self._action_bound] * action_dim)
|
||||||
|
self.action_space = spaces.Box(-action_high, action_high)
|
||||||
self.observation_space = spaces.Box(low=0, high=255, shape=(self._height, self._width, 4))
|
self.observation_space = spaces.Box(low=0, high=255, shape=(self._height, self._width, 4))
|
||||||
|
|
||||||
self.viewer = None
|
self.viewer = None
|
||||||
@@ -119,11 +125,14 @@ class RacecarZEDGymEnv(gym.Env):
|
|||||||
basePos,orn = self._p.getBasePositionAndOrientation(self._racecar.racecarUniqueId)
|
basePos,orn = self._p.getBasePositionAndOrientation(self._racecar.racecarUniqueId)
|
||||||
#self._p.resetDebugVisualizerCamera(1, 30, -40, basePos)
|
#self._p.resetDebugVisualizerCamera(1, 30, -40, basePos)
|
||||||
|
|
||||||
fwd = [-1,-1,-1,0,0,0,1,1,1]
|
if (self._isDiscrete):
|
||||||
steerings = [-0.6,0,0.6,-0.6,0,0.6,-0.6,0,0.6]
|
fwd = [-1,-1,-1,0,0,0,1,1,1]
|
||||||
forward = fwd[action]
|
steerings = [-0.6,0,0.6,-0.6,0,0.6,-0.6,0,0.6]
|
||||||
steer = steerings[action]
|
forward = fwd[action]
|
||||||
realaction = [forward,steer]
|
steer = steerings[action]
|
||||||
|
realaction = [forward,steer]
|
||||||
|
else:
|
||||||
|
realaction = action
|
||||||
|
|
||||||
self._racecar.applyAction(realaction)
|
self._racecar.applyAction(realaction)
|
||||||
for i in range(self._actionRepeat):
|
for i in range(self._actionRepeat):
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class MJCFBaseBulletEnv(gym.Env):
|
|||||||
|
|
||||||
def _reset(self):
|
def _reset(self):
|
||||||
if (self.physicsClientId<0):
|
if (self.physicsClientId<0):
|
||||||
self.physicsClientId = p.connect(p.SHARED_MEMORY)
|
self.physicsClientId = -1 #p.connect(p.SHARED_MEMORY)
|
||||||
if (self.physicsClientId<0):
|
if (self.physicsClientId<0):
|
||||||
if (self.isRender):
|
if (self.isRender):
|
||||||
self.physicsClientId = p.connect(p.GUI)
|
self.physicsClientId = p.connect(p.GUI)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from pybullet_envs.bullet.racecarZEDGymEnv import RacecarZEDGymEnv
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
environment = RacecarZEDGymEnv(renders=True)
|
environment = RacecarZEDGymEnv(renders=True, isDiscrete=True)
|
||||||
|
|
||||||
targetVelocitySlider = environment._p.addUserDebugParameter("wheelVelocity",-1,1,0)
|
targetVelocitySlider = environment._p.addUserDebugParameter("wheelVelocity",-1,1,0)
|
||||||
steeringSlider = environment._p.addUserDebugParameter("steering",-1,1,0)
|
steeringSlider = environment._p.addUserDebugParameter("steering",-1,1,0)
|
||||||
@@ -37,4 +37,4 @@ def main():
|
|||||||
print(obs)
|
print(obs)
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user