Skip to content

Commit

Permalink
Rename RemoteGuiInput to RemoteClientState.
Browse files Browse the repository at this point in the history
  • Loading branch information
0mdc committed Mar 11, 2024
1 parent 1ec8590 commit 7a216bc
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 33 deletions.
24 changes: 12 additions & 12 deletions examples/hitl/pick_throw_vr/pick_throw_vr.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ def _try_grasp_remote(self):
assert not self._held_target_obj_idx
self._recent_reach_pos = None
self._recent_hand_idx = None
remote_gui_input = self._app_service.remote_gui_input
remote_client_state = self._app_service.remote_client_state

hand_positions = []
num_hands = 2
for i in range(num_hands):
hand_pos, _ = remote_gui_input.get_hand_pose(i)
hand_pos, _ = remote_client_state.get_hand_pose(i)
if hand_pos:
hand_positions.append(hand_pos)
if len(hand_positions) == 0:
Expand All @@ -170,7 +170,7 @@ def _try_grasp_remote(self):

grasped_objects_idxs = get_grasped_objects_idxs(self.get_sim())

remote_button_input = remote_gui_input.get_gui_input()
remote_button_input = remote_client_state.get_gui_input()

found_obj_idx = None
found_hand_idx = None
Expand Down Expand Up @@ -229,8 +229,8 @@ def _update_held_and_try_throw_remote(self):
assert self._held_target_obj_idx is not None
assert self._remote_held_hand_idx is not None

remote_gui_input = self._app_service.remote_gui_input
remote_button_input = remote_gui_input.get_gui_input()
remote_client_state = self._app_service.remote_client_state
remote_button_input = remote_client_state.get_gui_input()

do_throw = False
for key in self.get_grasp_keys_by_hand(self._remote_held_hand_idx):
Expand All @@ -244,18 +244,18 @@ def _update_held_and_try_throw_remote(self):
rom_obj.collidable = True

hand_idx = self._remote_held_hand_idx
history_len = remote_gui_input.get_history_length()
history_len = remote_client_state.get_history_length()
assert history_len >= 2
history_offset = 1
pos1, _ = remote_gui_input.get_hand_pose(
pos1, _ = remote_client_state.get_hand_pose(
hand_idx, history_index=history_offset
)
pos0, _ = remote_gui_input.get_hand_pose(
pos0, _ = remote_client_state.get_hand_pose(
hand_idx, history_index=history_len - 1
)
if pos0 and pos1:
vel = (pos1 - pos0) / (
remote_gui_input.get_history_timestep()
remote_client_state.get_history_timestep()
* (history_len - history_offset)
)
rom_obj.linear_velocity = vel
Expand All @@ -266,7 +266,7 @@ def _update_held_and_try_throw_remote(self):
self._remote_held_hand_idx = None
else:
# snap to hand
hand_pos, hand_rotation = remote_gui_input.get_hand_pose(
hand_pos, hand_rotation = remote_client_state.get_hand_pose(
self._remote_held_hand_idx
)
assert hand_pos is not None
Expand All @@ -287,7 +287,7 @@ def _update_grasping_and_set_act_hints_remote(self):
walk_dir,
distance_multiplier,
forward_dir,
) = self._nav_helper.get_humanoid_walk_hints_from_remote_gui_input(
) = self._nav_helper.get_humanoid_walk_hints_from_remote_client_state(
visualize_path=False
)

Expand Down Expand Up @@ -651,7 +651,7 @@ def sim_update(self, dt, post_sim_update_dict):
self._app_service.gui_input.get_key_down(GuiInput.KeyNS.T)
or (
not self._is_remote_active_toggle
and self._app_service.remote_gui_input.get_gui_input().get_any_key_down()
and self._app_service.remote_client_state.get_gui_input().get_any_key_down()
)
)
):
Expand Down
18 changes: 9 additions & 9 deletions habitat-hitl/habitat_hitl/_internal/hitl_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from habitat_hitl.app_states.app_state_abc import AppState
from habitat_hitl.core.client_message_manager import ClientMessageManager
from habitat_hitl.core.hydra_utils import omegaconf_to_object
from habitat_hitl.core.remote_gui_input import RemoteGuiInput
from habitat_hitl.core.remote_client_state import RemoteClientState
from habitat_hitl.core.serialize_utils import (
BaseRecorder,
NullRecorder,
Expand Down Expand Up @@ -195,7 +195,7 @@ def local_end_episode(do_reset=False):
config=config,
hitl_config=self._hitl_config,
gui_input=gui_input,
remote_gui_input=self._remote_gui_input,
remote_client_state=self._remote_client_state,
line_render=line_render,
text_drawer=text_drawer,
get_anim_fraction=lambda: self._viz_anim_fraction,
Expand Down Expand Up @@ -231,7 +231,7 @@ def network_server_enabled(self) -> bool:
return self._hitl_config.networking.enable

def _check_init_server(self, line_render):
self._remote_gui_input = None
self._remote_client_state = None
self._interprocess_record = None
if self.network_server_enabled:
# How many frames we can simulate "ahead" of what keyframes have been sent.
Expand All @@ -243,7 +243,7 @@ def _check_init_server(self, line_render):
self._hitl_config.networking, max_steps_ahead
)
launch_networking_process(self._interprocess_record)
self._remote_gui_input = RemoteGuiInput(
self._remote_client_state = RemoteClientState(
self._interprocess_record, line_render
)

Expand Down Expand Up @@ -360,7 +360,7 @@ def _reset_environment(self):
self._obs, self._metrics = self.gym_habitat_env.reset(return_info=True)

if self.network_server_enabled:
self._remote_gui_input.clear_history()
self._remote_client_state.clear_history()

# todo: fix duplicate calls to self.ctrl_helper.on_environment_reset() here
if self.ctrl_helper:
Expand Down Expand Up @@ -457,8 +457,8 @@ def _set_cursor_style(self, cursor_style):
def sim_update(self, dt):
post_sim_update_dict: Dict[str, Any] = {}

if self._remote_gui_input:
self._remote_gui_input.update()
if self._remote_client_state:
self._remote_client_state.update()

# _viz_anim_fraction goes from 0 to 1 over time and then resets to 0
self._viz_anim_fraction = (
Expand Down Expand Up @@ -516,8 +516,8 @@ def depth_to_rgb(obs):
np.flipud(image) for image in debug_images
]

if self._remote_gui_input:
self._remote_gui_input.on_frame_end()
if self._remote_client_state:
self._remote_client_state.on_frame_end()

if self.network_server_enabled:
if (
Expand Down
10 changes: 5 additions & 5 deletions habitat-hitl/habitat_hitl/app_states/app_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from habitat.tasks.rearrange.rearrange_sim import RearrangeSim
from habitat_hitl.core.client_message_manager import ClientMessageManager
from habitat_hitl.core.gui_input import GuiInput
from habitat_hitl.core.remote_gui_input import RemoteGuiInput
from habitat_hitl.core.remote_client_state import RemoteClientState
from habitat_hitl.core.serialize_utils import BaseRecorder
from habitat_hitl.core.text_drawer import AbstractTextDrawer
from habitat_hitl.environment.controllers.controller_abc import GuiController
Expand All @@ -28,7 +28,7 @@ def __init__(
config,
hitl_config,
gui_input: GuiInput,
remote_gui_input: RemoteGuiInput,
remote_client_state: RemoteClientState,
line_render: DebugLineRender,
text_drawer: AbstractTextDrawer,
get_anim_fraction: Callable,
Expand All @@ -46,7 +46,7 @@ def __init__(
self._config = config
self._hitl_config = hitl_config
self._gui_input = gui_input
self._remote_gui_input = remote_gui_input
self._remote_client_state = remote_client_state
self._line_render = line_render
self._text_drawer = text_drawer
self._get_anim_fraction = get_anim_fraction
Expand Down Expand Up @@ -74,8 +74,8 @@ def gui_input(self) -> GuiInput:
return self._gui_input

@property
def remote_gui_input(self) -> RemoteGuiInput:
return self._remote_gui_input
def remote_client_state(self) -> RemoteClientState:
return self._remote_client_state

@property
def line_render(self) -> DebugLineRender:
Expand Down
4 changes: 2 additions & 2 deletions habitat-hitl/habitat_hitl/core/client_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _update_idle_kick(self, is_user_idle_this_frame):
self._show_idle_kick_warning = False

connection_records = (
self._app_service.remote_gui_input.get_new_connection_records()
self._app_service.remote_client_state.get_new_connection_records()
)
if len(connection_records):
assert (
Expand Down Expand Up @@ -76,7 +76,7 @@ def _update_idle_kick(self, is_user_idle_this_frame):

def _update_frame_counter_and_display_latency(self, server_sps):
recent_server_keyframe_id = (
self._app_service.remote_gui_input.pop_recent_server_keyframe_id()
self._app_service.remote_client_state.pop_recent_server_keyframe_id()
)
if recent_server_keyframe_id is not None:
new_avg = self._client_frame_latency_avg_helper.add(
Expand Down
2 changes: 1 addition & 1 deletion habitat-hitl/habitat_hitl/core/client_message_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def signal_app_ready(self):

def signal_kick_client(self, connection_id):
r"""
Signal NetworkManager to kick a client identified by connection_id. See also RemoteGuiInput.get_new_connection_records()[i]["connectionId"]. Sloppy: this is a message to NetworkManager, not the client.
Signal NetworkManager to kick a client identified by connection_id. See also RemoteClientState.get_new_connection_records()[i]["connectionId"]. Sloppy: this is a message to NetworkManager, not the client.
"""
self._message["kickClient"] = connection_id

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from habitat_hitl.core.gui_input import GuiInput


# todo: rename to RemoteClientState
class RemoteGuiInput:
class RemoteClientState:
def __init__(self, interprocess_record, debug_line_render):
self._recent_client_states = []
self._interprocess_record = interprocess_record
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _viz_humanoid_walk_path(self, path):
path_points, path_endpoint_radius, path_color
)

def get_humanoid_walk_hints_from_remote_gui_input(
def get_humanoid_walk_hints_from_remote_client_state(
self, visualize_path=True
):
walk_dir = None
Expand All @@ -101,7 +101,7 @@ def get_humanoid_walk_hints_from_remote_gui_input(
(
target_pos,
target_rot_quat,
) = self._app_service.remote_gui_input.get_head_pose()
) = self._app_service.remote_client_state.get_head_pose()

forward_dir = None
if target_pos and target_rot_quat:
Expand Down

0 comments on commit 7a216bc

Please sign in to comment.