diff --git a/agents/burger/hyperparameters.json b/agents/burger/hyperparameters.json index 318fbfd..292e105 100644 --- a/agents/burger/hyperparameters.json +++ b/agents/burger/hyperparameters.json @@ -1,24 +1,25 @@ { - "agent_name": "AGENT_24_2022_01_27__20_31", - "robot": "burger", - "actions_in_observationspace": true, - "batch_size": 19200, - "gamma": 0.99, - "n_steps": 1200, - "ent_coef": 0.005, - "learning_rate": 0.0003, - "vf_coef": 0.22, - "max_grad_norm": 0.5, - "gae_lambda": 0.95, - "m_batch_size": 15, - "n_epochs": 3, - "clip_range": 0.22, - "train_max_steps_per_episode": 250, - "eval_max_steps_per_episode": 400, - "goal_radius": 0.25, - "reward_fnc": "rule_05", - "discrete_action_space": false, - "normalize": false, - "task_mode": "staged", - "curr_stage": 6 + "agent_name": "AGENT_24_2022_01_27__20_31", + "robot": "burger", + "actions_in_observationspace": true, + "batch_size": 19200, + "gamma": 0.99, + "n_steps": 1200, + "ent_coef": 0.005, + "learning_rate": 0.0003, + "vf_coef": 0.22, + "max_grad_norm": 0.5, + "gae_lambda": 0.95, + "m_batch_size": 15, + "n_epochs": 3, + "clip_range": 0.22, + "train_max_steps_per_episode": 250, + "eval_max_steps_per_episode": 400, + "goal_radius": 0.25, + "reward_fnc": "rule_05", + "discrete_action_space": false, + "normalize": false, + "task_mode": "staged", + "curr_stage": 6, + "observation_space": ["laser_scan", "goal_in_robot_frame", "last_action"] } diff --git a/agents/jackal/hyperparameters.json b/agents/jackal/hyperparameters.json index 865f4e9..8efe6f7 100644 --- a/agents/jackal/hyperparameters.json +++ b/agents/jackal/hyperparameters.json @@ -1,24 +1,25 @@ { - "agent_name": "AGENT_24_2022_02_04__11_28", - "robot": "jackal", - "actions_in_observationspace": true, - "reward_fnc": "rule_05", - "discrete_action_space": false, - "normalize": false, - "task_mode": "staged", - "train_max_steps_per_episode": 150, - "eval_max_steps_per_episode": 200, - "goal_radius": 0.7, - "curr_stage": 11, - "batch_size": 19200, - "gamma": 0.99, - "n_steps": 1600, - "ent_coef": 0.005, - "learning_rate": 0.0003, - "vf_coef": 0.22, - "max_grad_norm": 0.5, - "gae_lambda": 0.95, - "m_batch_size": 15, - "n_epochs": 3, - "clip_range": 0.22 -} \ No newline at end of file + "agent_name": "AGENT_24_2022_02_04__11_28", + "robot": "jackal", + "actions_in_observationspace": true, + "reward_fnc": "rule_05", + "discrete_action_space": false, + "normalize": false, + "task_mode": "staged", + "train_max_steps_per_episode": 150, + "eval_max_steps_per_episode": 200, + "goal_radius": 0.7, + "curr_stage": 11, + "batch_size": 19200, + "gamma": 0.99, + "n_steps": 1600, + "ent_coef": 0.005, + "learning_rate": 0.0003, + "vf_coef": 0.22, + "max_grad_norm": 0.5, + "gae_lambda": 0.95, + "m_batch_size": 15, + "n_epochs": 3, + "clip_range": 0.22, + "observation_space": ["laser_scan", "goal_in_robot_frame", "last_action"] +} diff --git a/agents/jackal_barn/best_model.zip b/agents/jackal_barn/best_model.zip deleted file mode 100644 index 31520ba..0000000 Binary files a/agents/jackal_barn/best_model.zip and /dev/null differ diff --git a/agents/jackal_barn/hyperparameters.json b/agents/jackal_barn/hyperparameters.json deleted file mode 100644 index 649252c..0000000 --- a/agents/jackal_barn/hyperparameters.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "agent_name": "AGENT_24_2022_02_04__11_28", - "robot": "jackal", - "actions_in_observationspace": true, - "reward_fnc": "barn", - "discrete_action_space": false, - "normalize": false, - "task_mode": "staged", - "train_max_steps_per_episode": 200, - "eval_max_steps_per_episode": 300, - "goal_radius": 0.7, - "curr_stage": 3, - "batch_size": 19200, - "gamma": 0.99, - "n_steps": 19200, - "ent_coef": 0.005, - "learning_rate": 0.0003, - "vf_coef": 0.22, - "max_grad_norm": 0.5, - "gae_lambda": 0.95, - "m_batch_size": 15, - "n_epochs": 3, - "clip_range": 0.22 -} diff --git a/agents/jackal_barn/hyperparameters.json.lock b/agents/jackal_barn/hyperparameters.json.lock deleted file mode 100755 index e69de29..0000000 diff --git a/agents/jackal_marl/best_model.zip b/agents/jackal_marl/best_model.zip deleted file mode 100755 index d973051..0000000 Binary files a/agents/jackal_marl/best_model.zip and /dev/null differ diff --git a/agents/jackal_marl/hyperparameters.json b/agents/jackal_marl/hyperparameters.json deleted file mode 100755 index c121f0a..0000000 --- a/agents/jackal_marl/hyperparameters.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "agent_name": "AGENT_24_2022_02_04__11_28", - "robot": "jackal", - "actions_in_observationspace": true, - "reward_fnc": "rule_06", - "discrete_action_space": false, - "normalize": false, - "task_mode": "staged", - "train_max_steps_per_episode": 400, - "eval_max_steps_per_episode": 1100, - "goal_radius": 0.7, - "curr_stage": 1, - "batch_size": 38400, - "gamma": 0.99, - "n_steps": 3200, - "ent_coef": 0.005, - "learning_rate": 0.0003, - "vf_coef": 0.22, - "max_grad_norm": 0.5, - "gae_lambda": 0.95, - "m_batch_size": 15, - "n_epochs": 3, - "clip_range": 0.22, - "observation_space": ["laser_scan", "goal_in_robot_frame", "last_action"] -} diff --git a/agents/ridgeback/hyperparameters.json b/agents/ridgeback/hyperparameters.json index fdfb6c1..77399e0 100644 --- a/agents/ridgeback/hyperparameters.json +++ b/agents/ridgeback/hyperparameters.json @@ -1,23 +1,24 @@ { - "agent_name": "AGENT_21_2021_12_27__00_06", - "robot": "ridgeback", - "batch_size": 19200, - "gamma": 0.99, - "n_steps": 19200, - "ent_coef": 0.005, - "learning_rate": 0.0003, - "vf_coef": 0.22, - "max_grad_norm": 0.5, - "gae_lambda": 0.95, - "m_batch_size": 15, - "n_epochs": 3, - "clip_range": 0.22, - "train_max_steps_per_episode": 150, - "eval_max_steps_per_episode": 250, - "goal_radius": 0.25, - "reward_fnc": "rule_03", - "discrete_action_space": false, - "normalize": false, - "task_mode": "staged", - "curr_stage": 9 -} \ No newline at end of file + "agent_name": "AGENT_21_2021_12_27__00_06", + "robot": "ridgeback", + "batch_size": 19200, + "gamma": 0.99, + "n_steps": 19200, + "ent_coef": 0.005, + "learning_rate": 0.0003, + "vf_coef": 0.22, + "max_grad_norm": 0.5, + "gae_lambda": 0.95, + "m_batch_size": 15, + "n_epochs": 3, + "clip_range": 0.22, + "train_max_steps_per_episode": 150, + "eval_max_steps_per_episode": 250, + "goal_radius": 0.25, + "reward_fnc": "rule_03", + "discrete_action_space": false, + "normalize": false, + "task_mode": "staged", + "curr_stage": 9, + "observation_space": ["laser_scan", "goal_in_robot_frame", "last_action"] +} diff --git a/agents/ridgeback_marl/best_model.zip b/agents/ridgeback_marl/best_model.zip deleted file mode 100755 index ebb8719..0000000 Binary files a/agents/ridgeback_marl/best_model.zip and /dev/null differ diff --git a/agents/ridgeback_marl/hyperparameters.json b/agents/ridgeback_marl/hyperparameters.json deleted file mode 100755 index 8d29362..0000000 --- a/agents/ridgeback_marl/hyperparameters.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "agent_name": "ridgeback_2022_09_20__15_37", - "robot": "myrobot", - "actions_in_observationspace": true, - "reward_fnc": "rule_06", - "discrete_action_space": false, - "normalize": false, - "task_mode": "staged", - "train_max_steps_per_episode": 800, - "eval_max_steps_per_episode": 1100, - "goal_radius": 0.7, - "curr_stage": 1, - "batch_size": 57600, - "gamma": 0.99, - "n_steps": 4800, - "ent_coef": 0.005, - "learning_rate": 0.0003, - "vf_coef": 0.22, - "max_grad_norm": 0.5, - "gae_lambda": 0.95, - "m_batch_size": 16, - "n_epochs": 3, - "clip_range": 0.22, - "observation_space": ["laser_scan", "goal_in_robot_frame", "last_action"] -} diff --git a/agents/rto_tlabs_marl/best_model.zip b/agents/rto_tlabs_marl/best_model.zip deleted file mode 100755 index 86ed9a4..0000000 Binary files a/agents/rto_tlabs_marl/best_model.zip and /dev/null differ diff --git a/agents/rto_tlabs_marl/hyperparameters.json b/agents/rto_tlabs_marl/hyperparameters.json deleted file mode 100755 index 1088706..0000000 --- a/agents/rto_tlabs_marl/hyperparameters.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "agent_name": "AGENT_24_2022_02_04__11_36", - "robot": "rto_real", - "actions_in_observationspace": true, - "reward_fnc": "rule_06", - "discrete_action_space": false, - "normalize": false, - "task_mode": "staged", - "train_max_steps_per_episode": 400, - "eval_max_steps_per_episode": 1100, - "goal_radius": 0.7, - "curr_stage": 1, - "batch_size": 38400, - "gamma": 0.99, - "n_steps": 3200, - "ent_coef": 0.005, - "learning_rate": 0.0003, - "vf_coef": 0.22, - "max_grad_norm": 0.5, - "gae_lambda": 0.95, - "m_batch_size": 15, - "n_epochs": 3, - "clip_range": 0.22, - "observation_space": ["laser_scan", "goal_in_robot_frame", "last_action"] -} diff --git a/rosnav/model/feature_extractors.py b/rosnav/model/feature_extractors.py index 8adc5ae..0244993 100644 --- a/rosnav/model/feature_extractors.py +++ b/rosnav/model/feature_extractors.py @@ -32,6 +32,7 @@ def __init__( robot_model: str = None, features_dim: int = 128, ): + self._l, self._rs = get_observation_space_from_file(robot_model) super(EXTRACTOR_1, self).__init__(observation_space, features_dim + self._rs) diff --git a/rosnav/rosnav_space_manager/robot_specific_encoder.py b/rosnav/rosnav_space_manager/default_encoder.py similarity index 97% rename from rosnav/rosnav_space_manager/robot_specific_encoder.py rename to rosnav/rosnav_space_manager/default_encoder.py index 1688626..c3fa400 100644 --- a/rosnav/rosnav_space_manager/robot_specific_encoder.py +++ b/rosnav/rosnav_space_manager/default_encoder.py @@ -14,8 +14,8 @@ Action space: X Vel, (Y Vel), Angular Vel """ -@BaseSpaceEncoderFactory.register("RobotSpecificEncoder") -class RobotSpecificEncoder(BaseSpaceEncoder): +@BaseSpaceEncoderFactory.register("DefaultEncoder") +class DefaultEncoder(BaseSpaceEncoder): def __init__(self, *args): super().__init__(*args) diff --git a/rosnav/rosnav_space_manager/reduced_encoder.py b/rosnav/rosnav_space_manager/reduced_encoder.py new file mode 100644 index 0000000..3485aca --- /dev/null +++ b/rosnav/rosnav_space_manager/reduced_encoder.py @@ -0,0 +1,140 @@ +from gym import spaces +import numpy as np +import math + +from ..utils.utils import stack_spaces +from .encoder_factory import BaseSpaceEncoderFactory +from .base_space_encoder import BaseSpaceEncoder + +from ..utils.constants import REDUCTION_FACTOR, RosnavEncoder + +""" + + TODO + This encoder offers a robot specific observation and action space + Different actions spaces for holonomic and non holonomic robots + + Observation space: Laser Scan, Goal, Current Vel + Action space: X Vel, (Y Vel), Angular Vel + +""" + + +@BaseSpaceEncoderFactory.register("ReducedEncoder") +class ReducedEncoder(BaseSpaceEncoder): + def __init__(self, *args): + super().__init__(*args) + + rest = self._laser_num_beams % REDUCTION_FACTOR + self._laser_append_amount = 0 if rest == 0 else REDUCTION_FACTOR - rest + + def decode_action(self, action): + if self._is_action_space_discrete: + return self._translate_disc_action(action) + return self._extend_action_array(action) + + def _extend_action_array(self, action: np.ndarray) -> np.ndarray: + if self._is_holonomic: + assert ( + self._is_holonomic and len(action) == 3 + ), "Robot is holonomic but action with only two freedoms of movement provided" + + return action + else: + assert ( + not self._is_holonomic and len(action) == 2 + ), "Robot is non-holonomic but action with more than two freedoms of movement provided" + return np.array([action[0], 0, action[1]]) + + def _translate_disc_action(self, action): + assert not self._is_holonomic, "Discrete action space currently not supported for holonomic robots" + + return np.array([ + self._actions[action]["linear"], + self._actions[action]["linear"] + ]) + + def encode_observation(self, observation, structure): + # rho, theta = observation["goal_in_robot_frame"] + # scan = observation["laser_scan"] + # last_action = observation["last_action"] + + new_obs_space = [] + + for name in structure: + data = observation[name] + + if name == "laser_scan": + data = np.pad(data, [(0, self._laser_append_amount)], constant_values=self._laser_max_range) + + data = np.array_split(data, len(data) / REDUCTION_FACTOR) + data = [min(d) for d in data] + + new_obs_space.append(data) + + return np.hstack(new_obs_space) + + def get_observation_space(self): + return stack_spaces( + spaces.Box( + low=0, + high=self._laser_max_range, + shape=(math.floor(self._laser_num_beams / REDUCTION_FACTOR),), + dtype=np.float32, + ), + spaces.Box(low=0, high=15, shape=(1,), dtype=np.float32), + spaces.Box( + low=-np.pi, high=np.pi, shape=(1,), dtype=np.float32 + ), + spaces.Box( + low=-2.0, + high=2.0, + shape=(2,), + dtype=np.float32, # linear vel + ), + spaces.Box( + low=-4.0, + high=4.0, + shape=(1,), + dtype=np.float32, # angular vel + ), + ) + + def get_action_space(self): + if self._is_action_space_discrete: + # self._discrete_actions is a list, each element is a dict with the keys ["name", 'linear','angular'] + return spaces.Discrete(len(self._actions)) + + linear_range = self._actions["linear_range"] + angular_range = self._actions["angular_range"] + + if not self._is_holonomic: + return spaces.Box( + low=np.array([linear_range[0], angular_range[0]]), + high=np.array([linear_range[1], angular_range[1]]), + dtype=np.float32, + ) + + linear_range_x, linear_range_y = ( + linear_range["x"], + linear_range["y"], + ) + + return spaces.Box( + low=np.array( + [ + linear_range_x[0], + linear_range_y[0], + angular_range[0], + ] + ), + high=np.array( + [ + linear_range_x[1], + linear_range_y[1], + angular_range[1], + ] + ), + dtype=np.float32, + ) + diff --git a/rosnav/rosnav_space_manager/rosnav_space_manager.py b/rosnav/rosnav_space_manager/rosnav_space_manager.py index 0762c5a..d049d6e 100644 --- a/rosnav/rosnav_space_manager/rosnav_space_manager.py +++ b/rosnav/rosnav_space_manager/rosnav_space_manager.py @@ -1,6 +1,6 @@ from .encoder_factory import BaseSpaceEncoderFactory -from .robot_specific_encoder import * -from .uniform_encoder import * +from .default_encoder import * +from .reduced_encoder import * import rospy @@ -19,7 +19,7 @@ def __init__(self): self._radius = rospy.get_param("robot_radius") self._is_holonomic = rospy.get_param("is_holonomic") - encoder_name = rospy.get_param("space_encoder", "RobotSpecificEncoder") + encoder_name = rospy.get_param("space_encoder", "DefaultEncoder") is_action_space_discrete = rospy.get_param("is_action_space_discrete", False) actions = rospy.get_param("actions/discrete") if is_action_space_discrete else rospy.get_param("actions/continuous") diff --git a/rosnav/utils/constants.py b/rosnav/utils/constants.py index 6e8f7df..4f67f92 100644 --- a/rosnav/utils/constants.py +++ b/rosnav/utils/constants.py @@ -1,10 +1,20 @@ import rospy +import math +import os +REDUCTION_FACTOR = 3 + RosnavEncoder = { - "RobotSpecificEncoder": { - "lasers": rospy.get_param("laser/num_beams"), - "meta": 2 + 3 # Goal + Vel + "DefaultEncoder": { + "lasers": rospy.get_param(os.path.join(rospy.get_namespace(), "laser/num_beams")), + "meta": 2 + 3, # Goal + Vel, + "lasers_to_adapted": lambda x: x + }, + "ReducedEncoder": { + "lasers": math.ceil(rospy.get_param("laser/num_beams") / REDUCTION_FACTOR), + "meta": 2 + 3, # Goal + Vel + "lasers_to_adapted": lambda x: math.ceil(x / REDUCTION_FACTOR) }, "UniformEncoder": { "lasers": 1200, diff --git a/rosnav/utils/utils.py b/rosnav/utils/utils.py index cf159d1..db8bd87 100644 --- a/rosnav/utils/utils.py +++ b/rosnav/utils/utils.py @@ -10,8 +10,7 @@ def get_robot_yaml_path(robot_model: str = None) -> str: - if not robot_model: - robot_model = rospy.get_param("robot_model") + robot_model = rospy.get_param(os.path.join(rospy.get_namespace(), "robot_model")) simulation_setup_path = rospkg.RosPack().get_path("arena-simulation-setup") return os.path.join( @@ -26,7 +25,11 @@ def get_laser_from_robot_yaml(robot_model: str = None) -> Tuple[int, int, int, i robot_data = yaml.safe_load(fd) laser_data = robot_data["laser"] - rospy.set_param("laser/num_beams", laser_data["num_beams"]) + rospy.set_param( + os.path.join( + rospy.get_namespace(), "laser/num_beams" + ), laser_data["num_beams"] + ) return ( laser_data["num_beams"], @@ -40,11 +43,13 @@ def get_observation_space_from_file(robot_model: str = None) -> Tuple[int, int]: robot_state_size, action_state_size = 2, rospy.get_param(rospy.get_namespace() + "action_state_size", 3) num_beams, _, _, _ = get_laser_from_robot_yaml(robot_model) + num_beams = RosnavEncoder[get_robot_space_encoder()]["lasers_to_adapted"](num_beams) + return num_beams, action_state_size + robot_state_size def get_robot_space_encoder() -> str: - return rospy.get_param("space_encoder", "RobotSpecificEncoder") + return rospy.get_param("space_encoder", "DefaultEncoder") def get_observation_space() -> Tuple[int, int]: