Skip to content

Commit 3896b94

Browse files
committed
Added readme and examples
1 parent aa4ea95 commit 3896b94

3 files changed

Lines changed: 111 additions & 0 deletions

File tree

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,67 @@ for _ in range(100):
122122
logger.info("Truncated or terminated!")
123123
exit()
124124
```
125+
126+
### Remote Procedure Call (RPC) Client and Server
127+
#### Server
128+
```python
129+
from rcs.envs.creators import SimEnvCreator
130+
from rcs.envs.utils import (
131+
default_mujoco_cameraset_cfg,
132+
default_sim_gripper_cfg,
133+
default_sim_robot_cfg,
134+
)
135+
from rcs.envs.base import ControlMode, RelativeTo
136+
from rcs.rpc.server import RcsServer
137+
138+
def run_server():
139+
env = SimEnvCreator()(
140+
control_mode=ControlMode.JOINTS,
141+
collision_guard=False,
142+
robot_cfg=default_sim_robot_cfg(),
143+
gripper_cfg=default_sim_gripper_cfg(),
144+
cameras=default_mujoco_cameraset_cfg(),
145+
max_relative_movement=0.1,
146+
relative_to=RelativeTo.LAST_STEP,
147+
)
148+
server = RcsServer(env, port=50051)
149+
server.start()
150+
151+
if __name__ == "__main__":
152+
run_server()
153+
```
154+
155+
#### Client
156+
```python
157+
import time
158+
from python.rcs.rpc.client import RcsClient
159+
160+
if __name__ == "__main__":
161+
# Create the client (adjust host/port if needed)
162+
client = RcsClient(host="localhost", port=50051)
163+
164+
try:
165+
print("Resetting environment...")
166+
obs = client.reset()
167+
print(f"Initial observation: {obs}")
168+
169+
for i in range(5):
170+
print(f"\nStep {i+1}")
171+
# Replace with a valid action for your environment
172+
action = 0
173+
obs, reward, terminated, truncated, info = client.step(action)
174+
print(f"Obs: {obs}, Reward: {reward}, Terminated: {terminated}, Truncated: {truncated}, Info: {info}")
175+
if terminated or truncated:
176+
print("Episode finished, resetting...")
177+
obs = client.reset()
178+
print(f"Reset observation: {obs}")
179+
time.sleep(0.5)
180+
finally:
181+
print("Closing client.")
182+
client.close()
183+
```
184+
185+
125186
### Examples
126187
Checkout the python examples in the [examples](examples) folder:
127188
- [fr3_direct_control.py](examples/fr3.py) shows direct robot control with RCS's python bindings

examples/rpc_run_client.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import time
2+
from python.rcs.rpc.client import RcsClient
3+
4+
if __name__ == "__main__":
5+
# Create the client (adjust host/port if needed)
6+
client = RcsClient(host="localhost", port=50051)
7+
8+
try:
9+
print("Resetting environment...")
10+
obs = client.reset()
11+
print(f"Initial observation: {obs}")
12+
13+
for i in range(5):
14+
print(f"\nStep {i+1}")
15+
# Replace with a valid action for your environment
16+
action = 0
17+
obs, reward, terminated, truncated, info = client.step(action)
18+
print(f"Obs: {obs}, Reward: {reward}, Terminated: {terminated}, Truncated: {truncated}, Info: {info}")
19+
if terminated or truncated:
20+
print("Episode finished, resetting...")
21+
obs = client.reset()
22+
print(f"Reset observation: {obs}")
23+
time.sleep(0.5)
24+
finally:
25+
print("Closing client.")
26+
client.close()

examples/rpc_run_server.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from rcs.envs.creators import SimEnvCreator
2+
from rcs.envs.utils import (
3+
default_mujoco_cameraset_cfg,
4+
default_sim_gripper_cfg,
5+
default_sim_robot_cfg,
6+
)
7+
from rcs.envs.base import ControlMode, RelativeTo
8+
from rcs.rpc.server import RcsServer
9+
10+
def run_server():
11+
env = SimEnvCreator()(
12+
control_mode=ControlMode.JOINTS,
13+
collision_guard=False,
14+
robot_cfg=default_sim_robot_cfg(),
15+
gripper_cfg=default_sim_gripper_cfg(),
16+
cameras=default_mujoco_cameraset_cfg(),
17+
max_relative_movement=0.1,
18+
relative_to=RelativeTo.LAST_STEP,
19+
)
20+
server = RcsServer(env, port=50051)
21+
server.start()
22+
23+
if __name__ == "__main__":
24+
run_server()

0 commit comments

Comments
 (0)