-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from BerkeleyAutomation/action_spaces
Action spaces
- Loading branch information
Showing
17 changed files
with
154 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Actions | ||
============= | ||
|
||
Velocity Action | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
.. autoclass:: gym_urbandriving.actions.velocity_action.VelocityAction | ||
:members: get_value,sample | ||
|
||
Steering Action | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
.. autoclass:: gym_urbandriving.actions.steering_action.SteeringAction | ||
:members: get_value,sample | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from gym_urbandriving.actions.steering_action import SteeringAction | ||
from gym_urbandriving.actions.velocity_action import VelocityAction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from gym.spaces import Box | ||
import numpy as np | ||
|
||
|
||
|
||
class SteeringAction: | ||
""" | ||
This class is a wrapper for the action space at the lowest level of the heirarchy | ||
it represents the steering and acceleration applied directly to the car. | ||
""" | ||
|
||
def __init__(self,steering =0.0, acceleration = 0.0): | ||
""" | ||
Initializes the SteeringAction Class | ||
Parameters | ||
---------- | ||
steering: float | ||
the change in steering angle | ||
acceleration: float | ||
the acceleration applied to the car | ||
""" | ||
|
||
|
||
self.box = Box(low=np.array([-1,-5.0]),high=np.array([3,5.0])) | ||
|
||
self.controls = np.array([steering,acceleration]) | ||
|
||
|
||
|
||
def get_value(self): | ||
""" | ||
Gets the numpy array of the class | ||
Returns | ||
---------- | ||
steering and acceleration in numpy array shape (2,) | ||
""" | ||
return self.controls | ||
|
||
def sample(self): | ||
""" | ||
Samples a random control in this class using the OpenAI Box class | ||
Returns | ||
---------- | ||
steering and acceleration in numpy array shape (2,) | ||
""" | ||
|
||
return self.box.sample() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from gym.spaces import Box | ||
import numpy as np | ||
|
||
|
||
|
||
class VelocityAction: | ||
""" | ||
This class is a wrapper for the velocity control in the hierarchy | ||
it represents the target velocity for the car to drive at | ||
""" | ||
|
||
def __init__(self,velocity=0.0): | ||
""" | ||
Initializes the VelocityAction Class | ||
Parameters | ||
---------- | ||
velocity: float | ||
the desired velocity | ||
""" | ||
|
||
self.box = Box(low=0.0,high=5.0,shape=(1,)) | ||
|
||
self.velocity = np.array([velocity]) | ||
|
||
if not self.box.contains(self.velocity): | ||
raise Exception('Velocity is Out of Bounds') | ||
|
||
|
||
def get_value(self): | ||
""" | ||
Gets the value of the current velocity | ||
Returns | ||
---------- | ||
float | ||
""" | ||
return self.velocity[0] | ||
|
||
def sample(self): | ||
""" | ||
Samples a random control in this class using the OpenAI Box class | ||
Returns | ||
---------- | ||
velocity in numpy array shape (1,) | ||
""" | ||
return self.box.sample() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters