-
Notifications
You must be signed in to change notification settings - Fork 501
/
interactive_play.py
776 lines (674 loc) · 25.9 KB
/
interactive_play.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
Manually control the articulated agent to interact with the environment. Run as
```
python examples/interative_play.py
```
To Run you need PyGame installed (to install run `pip install pygame==2.0.1`).
By default this controls with velocity control (which makes controlling the
agent hard). To use IK control instead add the `--add-ik` command line argument.
Controls:
- For velocity control
- 1-7 to increase the motor target for the articulated agent arm joints
- Q-U to decrease the motor target for the articulated agent arm joints
- For IK control
- W,S,A,D to move side to side
- E,Q to move up and down
- I,J,K,L to move the articulated agent base around
- PERIOD to print the current world coordinates of the articulated agent base.
- Z to toggle the camera to free movement mode. When in free camera mode:
- W,S,A,D,Q,E to translate the camera
- I,J,K,L,U,O to rotate the camera
- B to reset the camera position
- X to change the articulated agent that is being controlled (if there are multiple articulated agents).
Change the task with `--cfg benchmark/rearrange/close_cab.yaml` (choose any task under the `habitat-lab/habitat/config/task/rearrange/` folder).
Change the grip type:
- Suction gripper `task.actions.arm_action.grip_controller "SuctionGraspAction"`
To record a video: `--save-obs` This will save the video to file under `data/vids/` specified by `--save-obs-fname` (by default `vid.mp4`).
Record and play back trajectories:
- To record a trajectory add `--save-actions --save-actions-count 200` to
record a truncated episode length of 200.
- By default the trajectories are saved to data/interactive_play_replays/play_actions.txt
- Play the trajectories back with `--load-actions data/interactive_play_replays/play_actions.txt`
"""
import argparse
import os
import os.path as osp
import time
from collections import defaultdict
from typing import Any, Dict, List
import magnum as mn
import numpy as np
import habitat
import habitat.tasks.rearrange.rearrange_task
from habitat.articulated_agent_controllers import HumanoidRearrangeController
from habitat.config.default import get_agent_config
from habitat.config.default_structured_configs import (
GfxReplayMeasureMeasurementConfig,
PddlApplyActionConfig,
ThirdRGBSensorConfig,
)
from habitat.core.logging import logger
from habitat.tasks.rearrange.actions.actions import ArmEEAction
from habitat.tasks.rearrange.rearrange_sensors import GfxReplayMeasure
from habitat.tasks.rearrange.utils import euler_to_quat, write_gfx_replay
from habitat.utils.visualizations.utils import (
observations_to_image,
overlay_frame,
)
from habitat_sim.utils import viz_utils as vut
try:
import pygame
except ImportError:
pygame = None
# Please reach out to the paper authors to obtain this file
DEFAULT_POSE_PATH = "data/humanoids/humanoid_data/walking_motion_processed.pkl"
DEFAULT_CFG = "benchmark/rearrange/play.yaml"
DEFAULT_RENDER_STEPS_LIMIT = 60
SAVE_VIDEO_DIR = "./data/vids"
SAVE_ACTIONS_DIR = "./data/interactive_play_replays"
def step_env(env, action_name, action_args):
return env.step({"action": action_name, "action_args": action_args})
def get_input_vel_ctlr(
skip_pygame,
arm_action,
env,
not_block_input,
agent_to_control,
control_humanoid,
humanoid_controller,
):
if skip_pygame:
return step_env(env, "empty", {}), None, False
multi_agent = len(env._sim.agents_mgr) > 1
if multi_agent:
agent_k = f"agent_{agent_to_control}_"
else:
agent_k = ""
arm_action_name = f"{agent_k}arm_action"
if control_humanoid:
base_action_name = f"{agent_k}humanoidjoint_action"
base_key = "human_joints_trans"
else:
base_action_name = f"{agent_k}base_velocity"
arm_key = "arm_action"
grip_key = "grip_action"
base_key = "base_vel"
if arm_action_name in env.action_space.spaces:
arm_action_space = env.action_space.spaces[arm_action_name].spaces[
arm_key
]
arm_ctrlr = env.task.actions[arm_action_name].arm_ctrlr
base_action = None
elif "stretch" in DEFAULT_CFG:
arm_action_space = np.zeros(10)
arm_ctrlr = None
base_action = [0, 0]
else:
arm_action_space = np.zeros(7)
arm_ctrlr = None
base_action = [0, 0]
if arm_action is None:
arm_action = np.zeros(arm_action_space.shape[0])
given_arm_action = False
else:
given_arm_action = True
end_ep = False
magic_grasp = None
keys = pygame.key.get_pressed()
if keys[pygame.K_ESCAPE]:
return None, None, False
elif keys[pygame.K_m]:
end_ep = True
elif keys[pygame.K_n]:
env._sim.navmesh_visualization = not env._sim.navmesh_visualization
if not_block_input:
# Base control
if keys[pygame.K_j]:
# Left
base_action = [0, 1]
elif keys[pygame.K_l]:
# Right
base_action = [0, -1]
elif keys[pygame.K_k]:
# Back
base_action = [-1, 0]
elif keys[pygame.K_i]:
# Forward
base_action = [1, 0]
if arm_action_space.shape[0] == 7:
# Velocity control. A different key for each joint
if keys[pygame.K_q]:
arm_action[0] = 1.0
elif keys[pygame.K_1]:
arm_action[0] = -1.0
elif keys[pygame.K_w]:
arm_action[1] = 1.0
elif keys[pygame.K_2]:
arm_action[1] = -1.0
elif keys[pygame.K_e]:
arm_action[2] = 1.0
elif keys[pygame.K_3]:
arm_action[2] = -1.0
elif keys[pygame.K_r]:
arm_action[3] = 1.0
elif keys[pygame.K_4]:
arm_action[3] = -1.0
elif keys[pygame.K_t]:
arm_action[4] = 1.0
elif keys[pygame.K_5]:
arm_action[4] = -1.0
elif keys[pygame.K_y]:
arm_action[5] = 1.0
elif keys[pygame.K_6]:
arm_action[5] = -1.0
elif keys[pygame.K_u]:
arm_action[6] = 1.0
elif keys[pygame.K_7]:
arm_action[6] = -1.0
elif arm_action_space.shape[0] == 10:
# Velocity control. A different key for each joint
if keys[pygame.K_q]:
arm_action[0] = 1.0
elif keys[pygame.K_1]:
arm_action[0] = -1.0
elif keys[pygame.K_w]:
arm_action[4] = 1.0
elif keys[pygame.K_2]:
arm_action[4] = -1.0
elif keys[pygame.K_e]:
arm_action[5] = 1.0
elif keys[pygame.K_3]:
arm_action[5] = -1.0
elif keys[pygame.K_r]:
arm_action[6] = 1.0
elif keys[pygame.K_4]:
arm_action[6] = -1.0
elif keys[pygame.K_t]:
arm_action[7] = 1.0
elif keys[pygame.K_5]:
arm_action[7] = -1.0
elif keys[pygame.K_y]:
arm_action[8] = 1.0
elif keys[pygame.K_6]:
arm_action[8] = -1.0
elif keys[pygame.K_u]:
arm_action[9] = 1.0
elif keys[pygame.K_7]:
arm_action[9] = -1.0
elif isinstance(arm_ctrlr, ArmEEAction):
EE_FACTOR = 0.5
# End effector control
if keys[pygame.K_d]:
arm_action[1] -= EE_FACTOR
elif keys[pygame.K_a]:
arm_action[1] += EE_FACTOR
elif keys[pygame.K_w]:
arm_action[0] += EE_FACTOR
elif keys[pygame.K_s]:
arm_action[0] -= EE_FACTOR
elif keys[pygame.K_q]:
arm_action[2] += EE_FACTOR
elif keys[pygame.K_e]:
arm_action[2] -= EE_FACTOR
else:
raise ValueError("Unrecognized arm action space")
if keys[pygame.K_p]:
logger.info("[play.py]: Unsnapping")
# Unsnap
magic_grasp = -1
elif keys[pygame.K_o]:
# Snap
logger.info("[play.py]: Snapping")
magic_grasp = 1
if control_humanoid:
if humanoid_controller is None:
# Add random noise to human arms but keep global transform
(
joint_trans,
root_trans,
) = env._sim.articulated_agent.get_joint_transform()
# Divide joint_trans by 4 since joint_trans has flattened quaternions
# and the dimension of each quaternion is 4
num_joints = len(joint_trans) // 4
root_trans = np.array(root_trans)
index_arms_start = 10
joint_trans_quat = [
mn.Quaternion(
mn.Vector3(joint_trans[(4 * index) : (4 * index + 3)]),
joint_trans[4 * index + 3],
)
for index in range(num_joints)
]
rotated_joints_quat = []
for index, joint_quat in enumerate(joint_trans_quat):
random_vec = np.random.rand(3)
# We allow for maximum 10 angles per step
random_angle = np.random.rand() * 10
rotation_quat = mn.Quaternion.rotation(
mn.Rad(random_angle), mn.Vector3(random_vec).normalized()
)
if index > index_arms_start:
joint_quat *= rotation_quat
rotated_joints_quat.append(joint_quat)
joint_trans = np.concatenate(
[
np.array(list(quat.vector) + [quat.scalar])
for quat in rotated_joints_quat
]
)
base_action = np.concatenate(
[joint_trans.reshape(-1), root_trans.transpose().reshape(-1)]
)
else:
# Use the controller
relative_pos = mn.Vector3(base_action[0], 0, base_action[1])
humanoid_controller.calculate_walk_pose(relative_pos)
base_action = humanoid_controller.get_pose()
if keys[pygame.K_PERIOD]:
# Print the current position of the articulated agent, useful for debugging.
pos = [
float("%.3f" % x)
for x in env._sim.articulated_agent.sim_obj.translation
]
rot = env._sim.articulated_agent.sim_obj.rotation
ee_pos = env._sim.articulated_agent.ee_transform().translation
logger.info(
f"Agent state: pos = {pos}, rotation = {rot}, ee_pos = {ee_pos}"
)
elif keys[pygame.K_COMMA]:
# Print the current arm state of the articulated agent, useful for debugging.
joint_state = [
float("%.3f" % x) for x in env._sim.articulated_agent.arm_joint_pos
]
logger.info(f"Agent arm joint state: {joint_state}")
args: Dict[str, Any] = {}
if base_action is not None and base_action_name in env.action_space.spaces:
name = base_action_name
args = {base_key: base_action}
else:
name = arm_action_name
if given_arm_action:
# The grip is also contained in the provided action
args = {
arm_key: arm_action[:-1],
grip_key: arm_action[-1],
}
else:
args = {arm_key: arm_action, grip_key: magic_grasp}
if magic_grasp is None:
arm_action = [*arm_action, 0.0]
else:
arm_action = [*arm_action, magic_grasp]
return step_env(env, name, args), arm_action, end_ep
def get_wrapped_prop(venv, prop):
if hasattr(venv, prop):
return getattr(venv, prop)
elif hasattr(venv, "venv"):
return get_wrapped_prop(venv.venv, prop)
elif hasattr(venv, "env"):
return get_wrapped_prop(venv.env, prop)
return None
class FreeCamHelper:
def __init__(self):
self._is_free_cam_mode = False
self._last_pressed = 0
self._free_rpy = np.zeros(3)
self._free_xyz = np.zeros(3)
@property
def is_free_cam_mode(self):
return self._is_free_cam_mode
def update(self, env, step_result, update_idx):
keys = pygame.key.get_pressed()
if keys[pygame.K_z] and (update_idx - self._last_pressed) > 60:
self._is_free_cam_mode = not self._is_free_cam_mode
logger.info(f"Switching camera mode to {self._is_free_cam_mode}")
self._last_pressed = update_idx
if self._is_free_cam_mode:
offset_rpy = np.zeros(3)
if keys[pygame.K_u]:
offset_rpy[1] += 1
elif keys[pygame.K_o]:
offset_rpy[1] -= 1
elif keys[pygame.K_i]:
offset_rpy[2] += 1
elif keys[pygame.K_k]:
offset_rpy[2] -= 1
elif keys[pygame.K_j]:
offset_rpy[0] += 1
elif keys[pygame.K_l]:
offset_rpy[0] -= 1
offset_xyz = np.zeros(3)
if keys[pygame.K_q]:
offset_xyz[1] += 1
elif keys[pygame.K_e]:
offset_xyz[1] -= 1
elif keys[pygame.K_w]:
offset_xyz[2] += 1
elif keys[pygame.K_s]:
offset_xyz[2] -= 1
elif keys[pygame.K_a]:
offset_xyz[0] += 1
elif keys[pygame.K_d]:
offset_xyz[0] -= 1
offset_rpy *= 0.1
offset_xyz *= 0.1
self._free_rpy += offset_rpy
self._free_xyz += offset_xyz
if keys[pygame.K_b]:
self._free_rpy = np.zeros(3)
self._free_xyz = np.zeros(3)
quat = euler_to_quat(self._free_rpy)
trans = mn.Matrix4.from_(
quat.to_matrix(), mn.Vector3(*self._free_xyz)
)
env._sim._sensors[
"third_rgb"
]._sensor_object.node.transformation = trans
step_result = env._sim.get_sensor_observations()
return step_result
return step_result
def play_env(env, args, config):
render_steps_limit = None
if args.no_render:
render_steps_limit = DEFAULT_RENDER_STEPS_LIMIT
use_arm_actions = None
if args.load_actions is not None:
with open(args.load_actions, "rb") as f:
use_arm_actions = np.load(f)
logger.info("Loaded arm actions")
obs = env.reset()
if not args.no_render:
draw_obs = observations_to_image(obs, {})
pygame.init()
screen = pygame.display.set_mode(
[draw_obs.shape[1], draw_obs.shape[0]]
)
update_idx = 0
target_fps = 60.0
prev_time = time.time()
all_obs = []
total_reward = 0
all_arm_actions: List[float] = []
agent_to_control = 0
free_cam = FreeCamHelper()
gfx_measure = env.task.measurements.measures.get(
GfxReplayMeasure.cls_uuid, None
)
is_multi_agent = len(env._sim.agents_mgr) > 1
humanoid_controller = None
if args.use_humanoid_controller:
humanoid_controller = HumanoidRearrangeController(args.walk_pose_path)
humanoid_controller.reset(env._sim.articulated_agent.base_pos)
while True:
if (
args.save_actions
and len(all_arm_actions) > args.save_actions_count
):
# quit the application when the action recording queue is full
break
if render_steps_limit is not None and update_idx > render_steps_limit:
break
if args.no_render:
keys = defaultdict(lambda: False)
else:
keys = pygame.key.get_pressed()
if not args.no_render and is_multi_agent and keys[pygame.K_x]:
agent_to_control += 1
agent_to_control = agent_to_control % len(env._sim.agents_mgr)
logger.info(
f"Controlled agent changed. Controlling agent {agent_to_control}."
)
step_result, arm_action, end_ep = get_input_vel_ctlr(
args.no_render,
use_arm_actions[update_idx]
if use_arm_actions is not None
else None,
env,
not free_cam.is_free_cam_mode,
agent_to_control,
args.control_humanoid,
humanoid_controller=humanoid_controller,
)
if not args.no_render and keys[pygame.K_c]:
pddl_action = env.task.actions["pddl_apply_action"]
logger.info("Actions:")
actions = pddl_action._action_ordering
for i, action in enumerate(actions):
logger.info(f"{i}: {action}")
entities = pddl_action._entities_list
logger.info("Entities")
for i, entity in enumerate(entities):
logger.info(f"{i}: {entity}")
action_sel = input("Enter Action Selection: ")
entity_sel = input("Enter Entity Selection: ")
action_sel = int(action_sel)
entity_sel = [int(x) + 1 for x in entity_sel.split(",")]
ac = np.zeros(pddl_action.action_space["pddl_action"].shape[0])
ac_start = pddl_action.get_pddl_action_start(action_sel)
ac[ac_start : ac_start + len(entity_sel)] = entity_sel
step_env(env, "pddl_apply_action", {"pddl_action": ac})
if not args.no_render and keys[pygame.K_g]:
pred_list = env.task.sensor_suite.sensors[
"all_predicates"
]._predicates_list
pred_values = step_result["all_predicates"]
logger.info("\nPredicate Truth Values:")
for i, (pred, pred_value) in enumerate(
zip(pred_list, pred_values)
):
logger.info(f"{i}: {pred.compact_str} = {pred_value}")
if step_result is None:
break
if end_ep:
total_reward = 0
# Clear the saved keyframes.
if gfx_measure is not None:
gfx_measure.get_metric(force_get=True)
env.reset()
if not args.no_render:
step_result = free_cam.update(env, step_result, update_idx)
all_arm_actions.append(arm_action)
update_idx += 1
if use_arm_actions is not None and update_idx >= len(use_arm_actions):
break
obs = step_result
info = env.get_metrics()
reward_key = [k for k in info if "reward" in k]
if len(reward_key) > 0:
reward = info[reward_key[0]]
else:
reward = 0.0
total_reward += reward
info["Total Reward"] = total_reward
if free_cam.is_free_cam_mode:
cam = obs["third_rgb"]
use_ob = np.zeros(draw_obs.shape)
use_ob[:, : cam.shape[1]] = cam[:, :, :3]
else:
use_ob = observations_to_image(obs, info)
if not args.skip_render_text:
use_ob = overlay_frame(use_ob, info)
draw_ob = use_ob[:]
if not args.no_render:
draw_ob = np.transpose(draw_ob, (1, 0, 2))
draw_obuse_ob = pygame.surfarray.make_surface(draw_ob)
screen.blit(draw_obuse_ob, (0, 0))
pygame.display.update()
if args.save_obs:
all_obs.append(draw_ob) # type: ignore[assignment]
if not args.no_render:
pygame.event.pump()
if env.episode_over:
total_reward = 0
env.reset()
curr_time = time.time()
diff = curr_time - prev_time
delay = max(1.0 / target_fps - diff, 0)
time.sleep(delay)
prev_time = curr_time
if args.save_actions:
if len(all_arm_actions) < args.save_actions_count:
raise ValueError(
f"Only did {len(all_arm_actions)} actions but {args.save_actions_count} are required"
)
all_arm_actions = all_arm_actions[: args.save_actions_count]
os.makedirs(SAVE_ACTIONS_DIR, exist_ok=True)
save_path = osp.join(SAVE_ACTIONS_DIR, args.save_actions_fname)
with open(save_path, "wb") as f:
np.save(f, all_arm_actions)
logger.info(f"Saved actions to {save_path}")
pygame.quit()
return
if args.save_obs:
all_obs = np.array(all_obs) # type: ignore[assignment]
all_obs = np.transpose(all_obs, (0, 2, 1, 3)) # type: ignore[assignment]
os.makedirs(SAVE_VIDEO_DIR, exist_ok=True)
vut.make_video(
np.expand_dims(all_obs, 1),
0,
"color",
osp.join(SAVE_VIDEO_DIR, args.save_obs_fname),
)
if gfx_measure is not None:
gfx_str = gfx_measure.get_metric(force_get=True)
write_gfx_replay(
gfx_str, config.habitat.task, env.current_episode.episode_id
)
if not args.no_render:
pygame.quit()
def has_pygame():
return pygame is not None
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--no-render", action="store_true", default=False)
parser.add_argument("--save-obs", action="store_true", default=False)
parser.add_argument("--save-obs-fname", type=str, default="play.mp4")
parser.add_argument("--save-actions", action="store_true", default=False)
parser.add_argument(
"--save-actions-fname", type=str, default="play_actions.txt"
)
parser.add_argument(
"--save-actions-count",
type=int,
default=200,
help="""
The number of steps the saved action trajectory is clipped to. NOTE
the episode must be at least this long or it will terminate with
error.
""",
)
parser.add_argument("--play-cam-res", type=int, default=512)
parser.add_argument(
"--skip-render-text", action="store_true", default=False
)
parser.add_argument(
"--same-task",
action="store_true",
default=False,
help="If true, then do not add the render camera for better visualization",
)
parser.add_argument(
"--skip-task",
action="store_true",
default=False,
help="If true, then do not add the render camera for better visualization",
)
parser.add_argument(
"--never-end",
action="store_true",
default=False,
help="If true, make the task never end due to reaching max number of steps",
)
parser.add_argument(
"--disable-inverse-kinematics",
action="store_true",
help="If specified, does not add the inverse kinematics end-effector control.",
)
parser.add_argument(
"--control-humanoid",
action="store_true",
default=False,
help="Control humanoid agent.",
)
parser.add_argument(
"--use-humanoid-controller",
action="store_true",
default=False,
help="Control humanoid agent.",
)
parser.add_argument(
"--gfx",
action="store_true",
default=False,
help="Save a GFX replay file.",
)
parser.add_argument("--load-actions", type=str, default=None)
parser.add_argument("--cfg", type=str, default=DEFAULT_CFG)
parser.add_argument(
"opts",
default=None,
nargs=argparse.REMAINDER,
help="Modify config options from command line",
)
parser.add_argument(
"--walk-pose-path", type=str, default=DEFAULT_POSE_PATH
)
args = parser.parse_args()
if not has_pygame() and not args.no_render:
raise ImportError(
"Need to install PyGame (run `pip install pygame==2.0.1`)"
)
config = habitat.get_config(args.cfg, args.opts)
with habitat.config.read_write(config):
env_config = config.habitat.environment
sim_config = config.habitat.simulator
task_config = config.habitat.task
if not args.same_task:
sim_config.debug_render = True
agent_config = get_agent_config(sim_config=sim_config)
agent_config.sim_sensors.update(
{
"third_rgb_sensor": ThirdRGBSensorConfig(
height=args.play_cam_res, width=args.play_cam_res
)
}
)
if "composite_success" in task_config.measurements:
task_config.measurements.composite_success.must_call_stop = (
False
)
if "rearrange_nav_to_obj_success" in task_config.measurements:
task_config.measurements.rearrange_nav_to_obj_success.must_call_stop = (
False
)
if "force_terminate" in task_config.measurements:
task_config.measurements.force_terminate.max_accum_force = -1.0
task_config.measurements.force_terminate.max_instant_force = (
-1.0
)
if args.gfx:
sim_config.habitat_sim_v0.enable_gfx_replay_save = True
task_config.measurements.update(
{"gfx_replay_measure": GfxReplayMeasureMeasurementConfig()}
)
if args.never_end:
env_config.max_episode_steps = 0
if args.control_humanoid:
args.disable_inverse_kinematics = True
if not args.disable_inverse_kinematics:
if "arm_action" not in task_config.actions:
raise ValueError(
"Action space does not have any arm control so cannot add inverse kinematics. Specify the `--disable-inverse-kinematics` option"
)
sim_config.agents.main_agent.ik_arm_urdf = (
"./data/robots/hab_fetch/robots/fetch_onlyarm.urdf"
)
task_config.actions.arm_action.arm_controller = "ArmEEAction"
if task_config.type == "RearrangeCompositeTask-v0":
task_config.actions["pddl_apply_action"] = PddlApplyActionConfig()
with habitat.Env(config=config) as env:
play_env(env, args, config)