07-19-2023, 09:14 AM
(07-14-2023, 08:21 AM)Albert Wrote:You can have multiple instances of the API connection running in parallel. But one instance of RoboDK can process only one request at a time.Same RoboDK item number despite being members of different instances
To speed up processing on RoboDK's end you can open multiple instances of RoboDK, using different API ports, and have different connections from the RoboDK API.
(here '94825226266192') is it normal? I want to assign one camera to each of Conveying1, Conveying2 and Conveying3, but all cameras are assigned to Conveying1.
Code:
class RoboDKEnv(gym.Env):
def __init__(self, config):
self.env_no = config.worker_index
self.api_port = 20500 + self.env_no
try:
self.controller = RoboController.remote(env_no=self.env_no, api_port=self.api_port)
except Exception as e:
raise Exception(f"Failed to create controller: {e}")
self.controller_initialized = True
print(f"Controller initialized for worker {self.env_no} on port {self.api_port}")
ray.get(self.controller.initialize_camera.remote())
class RoboController:
def initialize_camera(self):
self.RDK.Cam2D_Close()
self.camref = self.RDK.Item(project_info["camera_ref_name"], ITEM_TYPE_FRAME)
print("---self.camref:", self.camref)
self.cam_item = self.RDK.Cam2D_Add(self.camref, 'FOCAL_LENGHT=6 FOV=32 FAR_LENGHT=1000 SIZE=640x480 BG_COLOR=black LIGHT_AMBIENT=white LIGHT_DIFFUSE=black LIGHT_SPECULAR=white')
print("---self.cam_item:", self.cam_item)
self.cam_item.setParam('Open', 1)
---------------------------------
- output
(RoboController pid=3651698) ---self.camref: RoboDK item (94825226266192) of type 3(a member of Conveying2)
(RoboController pid=3651695) ---self.camref: RoboDK item (94825226266192) of type 3(a member of Conveying3)
(RoboController pid=3651713) ---self.camref: RoboDK item (94825226266192) of type 3(a member of Conveying1)
(RoboController pid=3651698) ---self.cam_item: RoboDK item (94825140747968) of type 19(Conveying1 on RoboDK project)
(RoboController pid=3651695) ---self.cam_item: RoboDK item (94825131911184) of type 19(Conveying1 on RoboDK project)
(RoboController pid=3651713) ---self.cam_item: RoboDK item (94825132525520) of type 19(Conveying1 on RoboDK project)