-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hab3_merge] Add Skills for the robot to move forward/backward and tu…
…rn (#1508) * Add Skills to move forward/backward and turn * update skills * fix pytest
- Loading branch information
1 parent
a9027fc
commit f5b29e6
Showing
4 changed files
with
74 additions
and
0 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
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
41 changes: 41 additions & 0 deletions
41
habitat-baselines/habitat_baselines/rl/hrl/skills/ll_nav.py
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,41 @@ | ||
import torch | ||
|
||
from habitat_baselines.rl.hrl.skills.skill import SkillPolicy | ||
from habitat_baselines.rl.hrl.utils import find_action_range | ||
from habitat_baselines.rl.ppo.policy import PolicyActionData | ||
|
||
|
||
class MoveSkillPolicy(SkillPolicy): | ||
def __init__( | ||
self, | ||
config, | ||
action_space, | ||
batch_size, | ||
): | ||
super().__init__(config, action_space, batch_size, True) | ||
self._turn_power_fwd = config.turn_power_x | ||
self._turn_power_side = config.turn_power_y | ||
self._nav_ac_start, _ = find_action_range( | ||
action_space, "base_velocity" | ||
) | ||
|
||
def _internal_act( | ||
self, | ||
observations, | ||
rnn_hidden_states, | ||
prev_actions, | ||
masks, | ||
cur_batch_idx, | ||
full_action, | ||
deterministic=False, | ||
): | ||
full_action = torch.zeros( | ||
(masks.shape[0], self._full_ac_size), device=masks.device | ||
) | ||
if self._turn_power_fwd != 0: | ||
full_action[:, self._nav_ac_start] = self._turn_power_fwd | ||
if self._turn_power_side != 0: | ||
full_action[:, self._nav_ac_start + 1] = self._turn_power_side | ||
return PolicyActionData( | ||
actions=full_action, rnn_hidden_states=rnn_hidden_states | ||
) |