Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base Env test cases #188

Merged
merged 19 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
cd ../

python3 -m pip install https://github.com/ompl/ompl/releases/download/prerelease/ompl-1.6.0-cp310-cp310-manylinux_2_28_x86_64.whl
sudo apt-get install libminizip1

- name: Run unit tests
run: |
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ If you have an NVIDIA GPU, install an NVIDIA Driver from the official [NVIDIA Dr
Install the necessary libraries:
```
sudo apt-get update
sudo apt-get install libminizip1
sudo apt-get install libassimp-dev libopenblas-dev liblapack-dev
```

Expand Down
80 changes: 44 additions & 36 deletions pyrcareworld/pyrcareworld/demo/examples/example_custom_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,59 @@
import os
import sys
import pyrcareworld.attributes as attr

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))

import argparse
from pyrcareworld.demo import executable_path
from pyrcareworld.envs.base_env import RCareWorld

# Initialize the environment with the specified scene file
player_path = os.path.join(executable_path, "../executable/Player/Player.x86_64")

# Initialize the environment with a custom asset
env = RCareWorld(assets=["CustomAttr"], executable_file=player_path)
def _main(dev):
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))

# Initialize the environment with the specified scene file
player_path = os.path.join(executable_path, "../executable/Player/Player.x86_64")

# Initialize the environment with a custom asset
env = RCareWorld(executable_file="@editor" if dev else player_path, assets=["CustomAttr"])

# Create an instance of a custom attribute and send a custom message
custom = env.InstanceObject(name="CustomAttr", id=1, attr_type=attr.CustomAttr)
custom.CustomMessage(message="this is instance channel custom message")

# Create an instance of a custom attribute and send a custom message
custom = env.InstanceObject(name="CustomAttr", id=123456, attr_type=attr.CustomAttr)
custom.CustomMessage(message="this is instance channel custom message")
# Perform a simulation step to process the custom message
env.step()

# Perform a simulation step to process the custom message
env.step()
# Print the custom message data
print(custom.data["custom_message"])

# Print the custom message data
print(custom.data["custom_message"])
# Callback function to handle dynamic object messages
def dynamic_object_callback(args):
for i, arg in enumerate(args):
print(f"Arg {i}: {arg}", type(arg))

# Callback function to handle dynamic object messages
def dynamic_object_callback(args):
for i, arg in enumerate(args):
print(f"Arg {i}: {arg}")
# Add a listener for dynamic object messages
env.AddListenerObject("DynamicObject", dynamic_object_callback)

# Add a listener for dynamic object messages
env.AddListenerObject("DynamicObject", dynamic_object_callback)
# Send a dynamic object message with various data types
env.SendObject(
"DynamicObject",
"string:", "this is dynamic object",
"int:", 1,
"bool:", True,
"float:", 4849.6564,
"list:", [616445.085, 9489984.0, 65419596.0, 9849849.0],
"dict:", {"1": 1, "2": 2, "3": 3},
"tuple:", ("1", 1, 0.562)
)

# Send a dynamic object message with various data types
env.SendObject(
"DynamicObject",
"string:", "this is dynamic object",
"int:", 123456,
"bool:", True,
"float:", 4849.6564,
"list:", [616445.085, 9489984.0, 65419596.0, 9849849.0],
"dict:", {"1": 1, "2": 2, "3": 3},
"tuple:", ("1", 1, 0.562)
)
# Perform a simulation step to process the dynamic object message
env.step()

# Perform a simulation step to process the dynamic object message
env.step()
# Close the environment
env.Pend()
env.close()

# Close the environment
env.Pend()
env.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Run RCareWorld bathing environment simulation for sponge forces.')
parser.add_argument('-d', '--dev', action='store_true', help='Run in developer mode')
args = parser.parse_args()
_main(args.dev)
63 changes: 63 additions & 0 deletions pyrcareworld/pyrcareworld/demo/examples/example_save_scene.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from pyrcareworld.envs.base_env import RCareWorld
import pyrcareworld.attributes as attr

import os
import sys
import argparse
import pytest
from pyrcareworld.demo import executable_path

def _main(dev):
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
# Initialize the environment with the specified scene file
player_path = os.path.join(executable_path, "../executable/Player/Player.x86_64")

env = RCareWorld(assets=["Collider_Box", "Rigidbody_Sphere"], executable_file="@editor" if dev else player_path)

box1 = env.InstanceObject(name="Collider_Box", attr_type=attr.ColliderAttr, id=1)
box1.SetTransform(position=[-0.5, 0.5, 0], scale=[0.1, 1, 1])
box2 = env.InstanceObject(name="Collider_Box", attr_type=attr.ColliderAttr, id=2)
box2.SetTransform(position=[0.5, 0.5, 0], scale=[0.1, 1, 1])
box3 = env.InstanceObject(name="Collider_Box", attr_type=attr.ColliderAttr, id=3)
box3.SetTransform(position=[0, 0.5, 0.5], scale=[1, 1, 0.1])
box4 = env.InstanceObject(name="Collider_Box", attr_type=attr.ColliderAttr, id=4)
box4.SetTransform(position=[0, 0.5, -0.5], scale=[1, 1, 0.1])
sphere = env.InstanceObject(name="Rigidbody_Sphere", attr_type=attr.RigidbodyAttr, id=5)
sphere.SetTransform(position=[0, 0.5, 0], scale=[0.5, 0.5, 0.5])
env.Pend()

env.SaveScene("test_scene.json")
env.ClearScene()
env.Pend()

with pytest.raises(AssertionError):
env.GetAttr(1)

with pytest.raises(AssertionError):
env.GetAttr(2)

with pytest.raises(AssertionError):
env.GetAttr(3)

with pytest.raises(AssertionError):
env.GetAttr(4)

with pytest.raises(AssertionError):
env.GetAttr(5)

env.LoadSceneAsync("test_scene.json")
env.Pend()

assert env.GetAttr(1).data["name"] == "Collider_Box"
assert env.GetAttr(2).data["name"] == "Collider_Box"
assert env.GetAttr(3).data["name"] == "Collider_Box"
assert env.GetAttr(4).data["name"] == "Collider_Box"
assert env.GetAttr(5).data["name"] == "Rigidbody_Sphere"

env.close()

if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Run RCareWorld bathing environment simulation for sponge forces.')
parser.add_argument('-d', '--dev', action='store_true', help='Run in developer mode')
args = parser.parse_args()
_main(args.dev)
31 changes: 0 additions & 31 deletions pyrcareworld/pyrcareworld/demo/examples/test_scene.py

This file was deleted.

Binary file not shown.
Binary file not shown.
Loading
Loading