@@ -120,8 +120,69 @@ for _ in range(100):
120120 print (obs)
121121 if truncated or terminated:
122122 logger.info(" Truncated or terminated!" )
123- return
123+ 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 " \n Step { 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
126187Checkout 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
0 commit comments