From 473f1454226832ef8f8ca7f03167f9d9344bc194 Mon Sep 17 00:00:00 2001 From: Sanjana Srivastava Date: Sat, 17 Oct 2020 21:44:09 -0500 Subject: [PATCH 1/2] task folder + minor --- examples/demo/igsdf_example.py | 2 +- gibson2/objects/visual_marker.py | 2 +- gibson2/render/viewer.py | 5 ++++ gibson2/scenes/igibson_indoor_scene.py | 1 + gibson2/task/task_base.py | 40 ++++++++++++++++++++++++++ gibson2/utils/assets_utils.py | 1 + 6 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 gibson2/task/task_base.py diff --git a/examples/demo/igsdf_example.py b/examples/demo/igsdf_example.py index 65d9424b2..017d53b65 100644 --- a/examples/demo/igsdf_example.py +++ b/examples/demo/igsdf_example.py @@ -12,7 +12,7 @@ def main(): settings = MeshRendererSettings(enable_shadow=True, msaa=False) s = Simulator(mode='gui', image_width=256, image_height=256, rendering_settings=settings) - scene = iGSDFScene(args.scene) + scene = InteractiveIndoorScene(args.scene) s.import_ig_scene(scene) for i in range(10000): diff --git a/gibson2/objects/visual_marker.py b/gibson2/objects/visual_marker.py index efebab86d..11bef2510 100644 --- a/gibson2/objects/visual_marker.py +++ b/gibson2/objects/visual_marker.py @@ -51,4 +51,4 @@ def _load(self): return body_id def set_color(self, color): - p.changeVisualShape(self.body_id, -1, rgbaColor=color) \ No newline at end of file + p.changeVisualShape(self.body_id, -1, rgbaColor=color) diff --git a/gibson2/render/viewer.py b/gibson2/render/viewer.py index 651260638..96ab942b8 100644 --- a/gibson2/render/viewer.py +++ b/gibson2/render/viewer.py @@ -74,6 +74,11 @@ def create_visual_object(self): self.simulator.import_object( self.constraint_marker2, use_pbr=False) self.simulator.import_object(self.constraint_marker, use_pbr=False) + + ###### TODO this is probably not the right fix + self.constraint_marker.load() + self.constraint_marker2.load() + ###### self.constraint_marker.set_position([0, 0, -1]) self.constraint_marker2.set_position([0, 0, -1]) diff --git a/gibson2/scenes/igibson_indoor_scene.py b/gibson2/scenes/igibson_indoor_scene.py index 23ab1f613..fcf96495c 100644 --- a/gibson2/scenes/igibson_indoor_scene.py +++ b/gibson2/scenes/igibson_indoor_scene.py @@ -14,6 +14,7 @@ from IPython import embed +# class InteractiveIndoorScene(StaticIndoorScene): class InteractiveIndoorScene(StaticIndoorScene): """ Create an interactive scene defined with iGibson Scene Description Format (iGSDF). diff --git a/gibson2/task/task_base.py b/gibson2/task/task_base.py new file mode 100644 index 000000000..eeb42a553 --- /dev/null +++ b/gibson2/task/task_base.py @@ -0,0 +1,40 @@ +import tasknet as tn +from tasknet.task_base import TaskNetTask +from gibson2.simulator import Simulator +from gibson2.scenes.igibson_indoor_scene import InteractiveIndoorScene +from gibson2.render.mesh_renderer.mesh_renderer_cpu import MeshRendererSettings + + +scene_path = 'd:\\gibson2_assets\\gibson_v2_selected\\' # TODO where to source this from? +scene_path = 'd:\\ig_dataset\\scenes' + + +class iGTNTaskInstance(TaskNetTask): + def __init__(self, atus_activity, simulator): + super().__init__(atus_activity) + self.simulator = simulator + + def initialize_scene(self): # NOTE can't have the same method name right + ''' + Get scene populated with objects such that scene satisfies initial conditions + ''' + self.scene = self.initialize(scene_path, InteractiveIndoorScene) + self.simulator.import_scene(self.scene) + + +def main(): + settings = MeshRendererSettings(enable_shadow=True, msaa=False) + sim = Simulator(mode='gui', image_width=1000, image_height=1000, device_idx=0, rendering_settings=settings) + igtn_task_instance = iGTNTaskInstance('demo1', sim) + igtn_task_instance.initialize_scene() + for i in range(30): + sim.step() + print('TASK SUCCESS:', igtn_task_instance.check_success()) + sim.disconnect() + + +if __name__ == '__main__': + main() + + + diff --git a/gibson2/utils/assets_utils.py b/gibson2/utils/assets_utils.py index 38b73bf24..8cb4ca161 100644 --- a/gibson2/utils/assets_utils.py +++ b/gibson2/utils/assets_utils.py @@ -9,6 +9,7 @@ def get_ig_scene_path(scene_name): ig_dataset_path = gibson2.ig_dataset_path ig_scenes_path = ig_dataset_path + "/scenes" + print('SCENE NAME:', scene_name) assert scene_name in os.listdir( ig_scenes_path), "Scene {} does not exist".format(scene_name) return os.path.join(ig_scenes_path, scene_name) From a3ba844e0f2acc342fe2fca649ef4eb2b6c2146f Mon Sep 17 00:00:00 2001 From: Sanjana Srivastava Date: Sun, 18 Oct 2020 23:07:01 -0500 Subject: [PATCH 2/2] tasknet demo1 updated for iGv1 --- examples/demo/mouse_interaction.py | 2 +- .../demo/mouse_interaction_placesetting.py | 60 +++++++++++++++++++ gibson2/render/viewer.py | 1 + gibson2/simulator.py | 9 ++- gibson2/task/task_base.py | 47 ++++++++++----- 5 files changed, 98 insertions(+), 21 deletions(-) create mode 100644 examples/demo/mouse_interaction_placesetting.py diff --git a/examples/demo/mouse_interaction.py b/examples/demo/mouse_interaction.py index 8bfddb106..ea140fbfa 100644 --- a/examples/demo/mouse_interaction.py +++ b/examples/demo/mouse_interaction.py @@ -24,7 +24,7 @@ def test_import_igsdf(): scene = InteractiveIndoorScene( 'Rs_int', texture_randomization=False, object_randomization=False) - # scene._set_first_n_objects(10) + scene._set_first_n_objects(5) settings = MeshRendererSettings(env_texture_filename=hdr_texture, env_texture_filename2=hdr_texture2, env_texture_filename3=background_texture, diff --git a/examples/demo/mouse_interaction_placesetting.py b/examples/demo/mouse_interaction_placesetting.py new file mode 100644 index 000000000..c212868bc --- /dev/null +++ b/examples/demo/mouse_interaction_placesetting.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +from gibson2.simulator import Simulator +from gibson2.scenes.igibson_indoor_scene import InteractiveIndoorScene +from gibson2.utils.utils import parse_config +from gibson2.render.mesh_renderer.mesh_renderer_cpu import MeshRendererSettings +from gibson2.objects.ycb_object import YCBObject +import os +import gibson2 +import time +import random +import sys + +# human interaction demo + + +def test_import_igsdf(): + hdr_texture = os.path.join( + gibson2.ig_dataset_path, 'scenes', 'background', 'probe_02.hdr') + hdr_texture2 = os.path.join( + gibson2.ig_dataset_path, 'scenes', 'background', 'probe_03.hdr') + light_modulation_map_filename = os.path.join( + gibson2.ig_dataset_path, 'scenes', 'Rs_int', 'layout', 'floor_lighttype_0.png') + background_texture = os.path.join( + gibson2.ig_dataset_path, 'scenes', 'background', 'urban_street_01.jpg') + + scene = InteractiveIndoorScene( + 'Rs_int', texture_randomization=False, object_randomization=False) + # scene._set_first_n_objects(10) + settings = MeshRendererSettings(env_texture_filename=hdr_texture, + env_texture_filename2=hdr_texture2, + env_texture_filename3=background_texture, + light_modulation_map_filename=light_modulation_map_filename, + enable_shadow=True, msaa=True, + light_dimming_factor=1.0) + s = Simulator(mode='iggui', image_width=960, + image_height=720, device_idx=0, rendering_settings=settings) + + s.viewer.min_cam_z = 1.0 + + s.import_ig_scene(scene) + + # Add objects + # obj1 = YCBObject(filename= + + while True: + start = time.time() + s.step() + end = time.time() + print("Elapsed time: ", end - start) + print("Frequency: ", 1 / (end - start)) + s.disconnect() + print("end") + + +def main(): + test_import_igsdf() + + +if __name__ == "__main__": + main() diff --git a/gibson2/render/viewer.py b/gibson2/render/viewer.py index 2b7526a90..8fd0dfea5 100644 --- a/gibson2/render/viewer.py +++ b/gibson2/render/viewer.py @@ -70,6 +70,7 @@ def create_visual_object(self): radius=0.04, rgba_color=[0, 0, 1, 1]) self.constraint_marker2 = VisualMarker(visual_shape=p.GEOM_CAPSULE, radius=0.01, length=3, initial_offset=[0, 0, -1.5], rgba_color=[0, 0, 1, 1]) + print('SIMULATOR:', self.simulator) if self.simulator is not None: self.simulator.import_object( self.constraint_marker2, use_pbr=False) diff --git a/gibson2/simulator.py b/gibson2/simulator.py index 448aef80b..4a4882a6b 100644 --- a/gibson2/simulator.py +++ b/gibson2/simulator.py @@ -109,7 +109,8 @@ def add_viewer(self): if self.use_vr_renderer: self.viewer = ViewerVR() else: - self.viewer = Viewer() + # self.viewer = Viewer() + self.viewer = Viewer(simulator=self, renderer=self.renderer) self.viewer.renderer = self.renderer def reload(self): @@ -151,17 +152,15 @@ def load(self): p.setPhysicsEngineParameter(enableFileCaching=0) print("PyBullet Logging Information******************") - if (self.use_ig_renderer or self.use_vr_renderer) and not self.render_to_tensor: - self.add_viewer() self.visual_objects = {} self.robots = [] self.scene = None self.next_class_id = 0 - - if self.use_ig_renderer and not self.render_to_tensor: + if (self.use_ig_renderer or self.use_vr_renderer) and not self.render_to_tensor: self.add_viewer() + def optimize_vertex_and_texture(self): self.renderer.optimize_vertex_and_texture() diff --git a/gibson2/task/task_base.py b/gibson2/task/task_base.py index eeb42a553..602e81499 100644 --- a/gibson2/task/task_base.py +++ b/gibson2/task/task_base.py @@ -1,37 +1,54 @@ +import os + import tasknet as tn from tasknet.task_base import TaskNetTask +import gibson2 from gibson2.simulator import Simulator from gibson2.scenes.igibson_indoor_scene import InteractiveIndoorScene from gibson2.render.mesh_renderer.mesh_renderer_cpu import MeshRendererSettings - - -scene_path = 'd:\\gibson2_assets\\gibson_v2_selected\\' # TODO where to source this from? -scene_path = 'd:\\ig_dataset\\scenes' +from gibson2.objects.articulated_object import URDFObject class iGTNTaskInstance(TaskNetTask): - def __init__(self, atus_activity, simulator): + def __init__(self, atus_activity): super().__init__(atus_activity) - self.simulator = simulator def initialize_scene(self): # NOTE can't have the same method name right ''' Get scene populated with objects such that scene satisfies initial conditions ''' - self.scene = self.initialize(scene_path, InteractiveIndoorScene) - self.simulator.import_scene(self.scene) + self.scene_name, self.scene = self.initialize(InteractiveIndoorScene, URDFObject) + + hdr_texture = os.path.join( + gibson2.ig_dataset_path, 'scenes', 'background', 'probe_02.hdr') + hdr_texture2 = os.path.join( + gibson2.ig_dataset_path, 'scenes', 'background', 'probe_03.hdr') + light_modulation_map_filename = os.path.join( + gibson2.ig_dataset_path, 'scenes', self.scene_name, 'layout', 'floor_lighttype_0.png') + background_texture = os.path.join( + gibson2.ig_dataset_path, 'scenes', 'background', 'urban_street_01.jpg') + + settings = MeshRendererSettings(env_texture_filename=hdr_texture, + env_texture_filename2=hdr_texture2, + env_texture_filename3=background_texture, + light_modulation_map_filename=light_modulation_map_filename, + enable_shadow=True, msaa=True, + light_dimming_factor=1.0) + self.simulator = Simulator(mode='iggui', image_width=960, image_height=720, device_idx=0, rendering_settings=settings) + + self.simulator.viewer.min_cam_z = 1.0 + self.simulator.import_ig_scene(self.scene) def main(): - settings = MeshRendererSettings(enable_shadow=True, msaa=False) - sim = Simulator(mode='gui', image_width=1000, image_height=1000, device_idx=0, rendering_settings=settings) - igtn_task_instance = iGTNTaskInstance('demo1', sim) + igtn_task_instance = iGTNTaskInstance('demo1') igtn_task_instance.initialize_scene() - for i in range(30): - sim.step() - print('TASK SUCCESS:', igtn_task_instance.check_success()) - sim.disconnect() + for i in range(100): + igtn_task_instance.simulator.step() + print('TASK SUCCESS:', igtn_task_instance.check_success()) + igtn_task_instance.simulator.disconnect() + if __name__ == '__main__': main()