Skip to content

Commit

Permalink
bug fix and documentation update
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzh26252 committed Mar 5, 2024
1 parent d6499da commit f1c03bb
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
1 change: 0 additions & 1 deletion MultiPhysics/envs/franka_robotics_env.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pyrfuniverse.envs.gym_goal_wrapper_env import RFUniverseGymGoalWrapper
import numpy as np
from gym import spaces
from gym.utils import seeding
Expand Down
4 changes: 1 addition & 3 deletions Test/test_load_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
position=[0, 1, 0],
rotation=[random.random() * 360, random.random() * 360, random.random() * 360],
)

while 1:
env.step()
env.Pend()
4 changes: 2 additions & 2 deletions Test/test_point_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

image_rgb = camera1.data["rgb"]
image_depth_exr = camera1.data["depth_exr"]
fov = camera1.data["fov"]
fov = 60
local_to_world_matrix = camera1.data["local_to_world_matrix"]
point1 = dp.image_bytes_to_point_cloud(
image_rgb, image_depth_exr, fov, local_to_world_matrix
Expand All @@ -34,7 +34,7 @@

image_rgb = camera2.data["rgb"]
image_depth_exr = camera2.data["depth_exr"]
fov = camera2.data["fov"]
fov = 60
local_to_world_matrix = camera2.data["local_to_world_matrix"]
point2 = dp.image_bytes_to_point_cloud(
image_rgb, image_depth_exr, fov, local_to_world_matrix
Expand Down
2 changes: 1 addition & 1 deletion pyrfuniverse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Version of the library that will be used to upload to pypi
__version__ = "0.12.3.3"
__version__ = "0.12.4"

import os.path
import json
Expand Down
8 changes: 8 additions & 0 deletions pyrfuniverse/envs/base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class RFUniverseBaseEnv(ABC):
scene_file: Str, the absolute path of Unity scene JSON file. All JSON files locate at `StraemingAssets/SceneData` by default.
assets: List, the list of pre-load assets. All assets in the list will be pre-loaded in Unity when the environment is initialized, which will save time during instanciating.
graphics: Bool, True for showing GUI and False for headless mode.
port: Int, the port for communication.
proc_id: Int, the process id for the Unity environment. 0 for the first process, 1 for the second process, and so on.
log_level: Int, the log level for Unity environment. 0 for no log, 1 for errors logs, 2 for warnings and errors, 3 for all only.
ext_attr: List, the list of extended attributes. All extended attributes will be added to the environment.
check_version: Bool, True for checking the version of the Unity environment and the pyrfuniverse library. False for not checking the version.
"""

metadata = {"render.modes": ["human", "rgb_array"]}
Expand Down Expand Up @@ -82,6 +87,9 @@ def __init__(
if scene_file is not None:
self.LoadSceneAsync(scene_file, True)

def __del__(self):
self.close()

def _get_port(self) -> int:
executable_port = self.port + 1
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand Down
14 changes: 14 additions & 0 deletions pyrfuniverse/envs/gym_wrapper_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@


class RFUniverseGymWrapper(RFUniverseBaseEnv, gym.Env):
"""
RFUniverse base environment with Gym class.
Args:
executable_file: Str, the absolute path of Unity executable file. None for last used executable file; "@editor" for using Unity Editor.
scene_file: Str, the absolute path of Unity scene JSON file. All JSON files locate at `StraemingAssets/SceneData` by default.
assets: List, the list of pre-load assets. All assets in the list will be pre-loaded in Unity when the environment is initialized, which will save time during instanciating.
graphics: Bool, True for showing GUI and False for headless mode.
port: Int, the port for communication.
proc_id: Int, the process id for the Unity environment. 0 for the first process, 1 for the second process, and so on.
log_level: Int, the log level for Unity environment. 0 for no log, 1 for errors logs, 2 for warnings and errors, 3 for all only.
ext_attr: List, the list of extended attributes. All extended attributes will be added to the environment.
check_version: Bool, True for checking the version of the Unity environment and the pyrfuniverse library. False for not checking the version.
"""
def __init__(
self,
executable_file: str = None,
Expand Down
10 changes: 6 additions & 4 deletions pyrfuniverse/utils/rfuniverse_communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,20 @@ def receive_step(self):
self.on_receive_data(objs)

def receive_bytes(self):
# data = self.client.recv(4)
# assert len(data) == 4
data = bytearray()
while len(data) < 4:
data.extend(self.client.recv(4 - len(data)))
temp_data = self.client.recv(4 - len(data))
assert len(temp_data) != 0
data.extend(temp_data)
assert len(data) == 4
length = int.from_bytes(data, byteorder="little", signed=False)
if length == 0:
return None
buffer = bytearray()
while len(buffer) < length:
buffer.extend(self.client.recv(length - len(buffer)))
temp_data = self.client.recv(length - len(buffer))
assert len(temp_data) != 0
buffer.extend(temp_data)
assert len(buffer) == length
return buffer, length

Expand Down

0 comments on commit f1c03bb

Please sign in to comment.