Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an entry for ActuatorDynamic to the FormatAction wrapper #1836

Merged
merged 3 commits into from
Feb 7, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions smarts/env/wrappers/format_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ class FormatAction(gym.ActionWrapper):

Note:

(a) Only ``ActionSpaceType.Continuous``, ``ActionSpaceType.Lane``, and
``ActionSpaceType.TargetPose`` are supported by this wrapper now.
(a) Only ``ActionSpaceType.Continuous``, ``ActionSpaceType.Lane``,
``ActionSpaceType.ActuatorDynamic``, and `ActionSpaceType.TargetPose``
are supported by this wrapper now.

(b) All agents should have the same action space.
"""
Expand All @@ -50,6 +51,7 @@ def __init__(self, env: gym.Env, space: ActionSpaceType):
space_map = {
"Continuous": _continuous,
"Lane": _lane,
"ActuatorDynamic": _actuator_dynamic,
"TargetPose": _target_pose,
}
self._wrapper, action_space = space_map.get(space.name)()
Expand Down Expand Up @@ -96,6 +98,17 @@ def wrapper(action: Dict[str, int]) -> Dict[str, str]:
return wrapper, space


def _actuator_dynamic() -> Tuple[Callable[[Dict[str, numpy.ndarray]], Dict[str, numpy.ndarray]], gym.Space]:
space = gym.spaces.Box(
low=np.array([0.0, 0.0, -1.0]), high=np.array([1.0, 1.0, 1.0]), dtype=np.float32
)

def wrapper(action: Dict[str, np.ndarray]) -> Dict[str, np.ndarray]:
return {k: v.astype(np.float32) for k, v in action.items()}

return wrapper, space


def _target_pose() -> Tuple[
Callable[[Dict[str, np.ndarray]], Dict[str, np.ndarray]], gym.Space
]:
Expand All @@ -108,4 +121,4 @@ def _target_pose() -> Tuple[
def wrapper(action: Dict[str, np.ndarray]) -> Dict[str, np.ndarray]:
return {k: v.astype(np.float32) for k, v in action.items()}

return wrapper, space
return wrapper, space