def __init__(self, loop: "RobotRaconteur.WebLoop", config: Dict[str, Any]): self._loop = loop self._config = config self._layout = PyriGoldenLayout(self) self._seqno = 0 self._device_manager = DeviceManagerClient(fill_rr_url_template( config["device_manager_url"]), autoconnect=False, tcp_ipv4_only=True) self._devices_states_obj_sub = None self._devices_states_wire_sub = None self._devices_states_value = None self._device_infos = dict() self._device_infos_update_running = False def set_devices_states(state, devices_states): state.devices_states = devices_states def set_active_device_names(state, device_names): current_devices = [] current_devices_js = state.active_device_names for i in range(current_devices_js.length): current_devices.append(current_devices_js[i]) if set(current_devices) != set(device_names): state.active_device_names = device_names def set_device_infos(state, device_infos): state.device_infos = device_infos
from pyri.device_manager_client import DeviceManagerClient from RobotRaconteur.Client import * import time d = DeviceManagerClient('rr+tcp://localhost:59902?service=device_manager', autoconnect=False) d.refresh_devices(1) d.connect_device('jog_joint') jog_service = d.get_device_client("jog_joint", 1) print(jog_service.device_info.device.name) tool = jog_service.get_tool("tool") while (True): tool.open() time.sleep(0.5) tool.close() time.sleep(0.5)
from pyri.device_manager_client import DeviceManagerClient from RobotRaconteur.Client import * from RobotRaconteurCompanion.Util.ImageUtil import ImageUtil import time import cv2 d = DeviceManagerClient('rr+tcp://localhost:59902?service=device_manager', autoconnect=False) d.refresh_devices(1) d.connect_device("vision_camera_calibration") calibration_service = d.get_device_client("vision_camera_calibration", 1) ret = calibration_service.calibrate_camera_intrinsic( "camera", "intrinsic_calib_dataset0", "chessboard", "camera_intrinsic_calibration") #"camera_intrinsic_calibration") image_util = ImageUtil(client_obj=calibration_service) i = 0 for c_img in ret.display_images: img = image_util.compressed_image_to_array(c_img) cv2.imshow(f"img {i}", img) cv2.waitKey() i += 1 cv2.destroyAllWindows()
img_name_prefix = "images" img_name_ext = ".png" img_count = 50 imgs = [] for i in range(img_count): p = source_dir.joinpath(f"{img_name_prefix}{i}{img_name_ext}") imgs.append(cv2.imread(str(p))) # for img in imgs: # cv2.imshow("",img) # cv2.waitKey(250) d = DeviceManagerClient('rr+tcp://localhost:59902?service=device_manager', autoconnect=False) d.refresh_devices(1) d.connect_device("variable_storage") var_storage = d.get_device_client("variable_storage", 1) image_util = ImageUtil(client_obj=var_storage) var_consts = var_storage.RRGetNode().GetConstants('tech.pyri.variable_storage', var_storage) variable_persistence = var_consts["VariablePersistence"] variable_protection_level = var_consts["VariableProtectionLevel"]
from pyri.device_manager_client import DeviceManagerClient from RobotRaconteur.Client import * d = DeviceManagerClient('rr+tcp://localhost:59902?service=device_manager', autoconnect=False) d.refresh_devices(1) d.connect_device("sandbox") c = d.get_device_client("sandbox",1) gen = c.getf_output() while True: try: ret = gen.Next() print([l.output for l in ret.output_list]) except RR.StopIterationException: break # gen = c.execute_procedure("test_print_many", []) # while True: # try: # print(gen.Next().printed) # except RR.StopIterationException: # break
def __init__(self, node_name, tcp_port, flags = PyriService_NodeSetup_Default_Flags, \ allowed_overrides = PyriService_NodeSetup_Default_AllowedOverride, \ node = None, argv = None, rr_config = None, \ extra_service_defs = [], device_info_type = "com.robotraconteur.device.DeviceInfo", \ device_info_arg = None, default_info = None, \ arg_parser = None, \ display_description="PyRI Generic Service", no_standard_robdef = False, no_device_manager = False, device_manager_autoconnect = True, register_plugin_robdef = False, distribution_name = None, version = None ): # Initialize node setup superclass super().__init__(node_name, tcp_port, flags, allowed_overrides, node, argv, rr_config) # If passed node is None, assume default node if node is None: node = RR.RobotRaconteurNode.s # Set up and parse arguments if arg_parser is None: arg_parser = argparse.ArgumentParser( description=display_description) if device_info_arg is None: arg_parser.add_argument("--device-info-file", type=argparse.FileType('r'), default=None, required=False, help="Info file for service") arg_parser.add_argument( '--device-manager-url', type=str, default=None, required=False, help="Robot Raconteur URL for device manager service") arg_parser.add_argument( '--device-manager-identifier', type=str, default=None, required=False, help="Robot Raconteur identifier for device manager service") arg_parser.add_argument( "--pyri-webui-server-port", type=int, default=8000, help="The PyRI WebUI port for websocket origin (default 8000)") if version is not None: arg_parser.add_argument('-V', '--version', action='version', version=f'%(prog)s {version}') elif distribution_name is not None: version1 = importlib.metadata.version(distribution_name) arg_parser.add_argument('-V', '--version', action='version', version=f'%(prog)s {version1}') args, _ = arg_parser.parse_known_args() self._argparse_results = args if not no_standard_robdef: # Register standard service types RRC.RegisterStdRobDefServiceTypes(node) if register_plugin_robdef: # Register all plugin robdef if requested robdef_plugins.register_all_plugin_robdefs(node) # Register additional passed service types extra_defs = [] for d in extra_service_defs: if isinstance(d, tuple): packg, res = d extra_defs.append(importlib_resources.read_text(packg, res)) elif isinstance(d, io.TextIOBase): extra_defs.append(d.read()) else: extra_defs.append(d) if len(extra_defs) > 0: node.RegisterServiceTypes(extra_defs) if device_info_arg is None: device_info_arg = "device-info-file" device_info_arg_res = getattr(args, device_info_arg.replace("-", "_")) if device_info_arg_res is None: if isinstance(default_info, tuple): info_packg, info_res = default_info device_info_text = importlib_resources.read_text( info_packg, info_res) elif isinstance(d, io.TextIOBase): device_info_text = default_info.read() else: device_info_text = default_info else: with device_info_arg_res: device_info_text = device_info_arg_res.read() info_loader = InfoFileLoader(node) any_device_info, device_ident_fd = info_loader.LoadInfoFileFromString( device_info_text, device_info_type, "device") if device_info_type == "com.robotraconteur.device.DeviceInfo": device_info = any_device_info else: device_info = any_device_info.device_info attributes_util = AttributesUtil(node) device_attributes = attributes_util.GetDefaultServiceAttributesFromDeviceInfo( device_info) add_default_ws_origins(self.tcp_transport, args.pyri_webui_server_port) if not no_device_manager: self._device_manager = DeviceManagerClient(device_manager_url = args.device_manager_url, device_manager_identifier=args.device_manager_identifier, \ node = node, autoconnect = device_manager_autoconnect) else: self._device_manager = None self._device_info = device_info self._any_device_info = any_device_info self._device_ident_fd = device_ident_fd self._device_attributes = device_attributes self.node = node
from pyri.device_manager_client import DeviceManagerClient from RobotRaconteur.Client import * import time d = DeviceManagerClient('rr+tcp://localhost:59902?service=device_manager') d.refresh_devices(1) viewer = d.get_device_client("vision_camera_viewer", 1) cam = viewer.get_camera_viewer("camera") cam.capture_frame_preview()
class PyriWebUIBrowser: def __init__(self, loop: "RobotRaconteur.WebLoop", config: Dict[str, Any]): self._loop = loop self._config = config self._layout = PyriGoldenLayout(self) self._seqno = 0 self._device_manager = DeviceManagerClient(fill_rr_url_template( config["device_manager_url"]), autoconnect=False, tcp_ipv4_only=True) self._devices_states_obj_sub = None self._devices_states_wire_sub = None self._devices_states_value = None self._device_infos = dict() self._device_infos_update_running = False def set_devices_states(state, devices_states): state.devices_states = devices_states def set_active_device_names(state, device_names): current_devices = [] current_devices_js = state.active_device_names for i in range(current_devices_js.length): current_devices.append(current_devices_js[i]) if set(current_devices) != set(device_names): state.active_device_names = device_names def set_device_infos(state, device_infos): state.device_infos = device_infos @property def loop(self): return self._loop def create_task(self, task): async def create_task_w(): await task self._loop.create_task(create_task_w()) @property def layout(self): return self._layout @property def seqno(self): return self._seqno @property def device_manager(self): return self._device_manager async def load_plugin_panels(self): all_panels_u = get_all_webui_browser_panels_infos() all_panels = dict() for u in all_panels_u.values(): all_panels.update(u) all_panels_sorted = sorted(all_panels.values(), key=lambda x: x.priority) for p in all_panels_sorted: await add_webui_browser_panel(p.panel_type, self, self._layout.layout_container) async def run(self): try: print("Running PyRI WebUI Browser") self._layout.init_golden_layout() js.jQuery.find("#menuContainer")[0].removeAttribute('hidden') await self.load_plugin_panels() for i in range(100): if i > 50: js.window.alert( "Could not connect to devices states service") return if "devices_states" in self._device_manager.get_device_names(): break await RRN.AsyncSleep(0.1, None) await self.update_devices() self._device_manager.connect_device("variable_storage") self._device_manager.connect_device("devices_states") self._device_manager.connect_device("sandbox") self._device_manager.connect_device("program_master") self._devices_states_obj_sub = self._device_manager.get_device_subscription( "devices_states") # Run infinite update loop self._layout.select_panel("welcome") while True: await RRN.AsyncSleep(0.1, None) await self.update() except: traceback.print_exc() async def update(self): try: self._seqno += 1 if self._seqno % 150 == 0: self.create_task(self.update_devices()) res, devices_states_obj = self._devices_states_obj_sub.TryGetDefaultClient( ) #print(f"devices states TryGetDefaultClient res: {res} {devices_states_obj}") if res: try: devices_states, _ = await devices_states_obj.devices_states.AsyncPeekInValue( None) except: traceback.print_exc() res = False if res: self._devices_states_value = devices_states self._update_device_infos(devices_states) else: self._devices_states_value = None except: traceback.print_exc() async def update_devices(self): try: await RRN.AsyncSleep(0.02, None) await self._device_manager.async_refresh_devices(1) except: traceback.print_exc() @property def devices_states(self): return self._devices_states_value @property def active_device_names(self): try: return list(self._devices_states_value.devices_states.keys()) except AttributeError: return [] @property def device_infos(self): return self._device_infos def _update_device_infos(self, devices_states): try: if self._device_infos_update_running: return update_devices = [] for d in devices_states.devices_states.keys(): if d not in self._device_infos: self._device_infos[d] = dict() if len(self._device_infos[d]) != 3: update_devices.append(d) if len(update_devices) > 0: self.create_task(self._do_update_device_infos(update_devices)) except: traceback.print_exc() async def _do_update_device_infos(self, local_device_names): try: self._device_infos_update_running = True states_connected, states = self._devices_states_obj_sub.TryGetDefaultClient( ) for d in local_device_names: if not "device_info" in self._device_infos[d]: self._device_infos[d][ "device_info"] = self._device_manager.get_device_info( d) if self._devices_states_value.devices_states[ d].connected and states_connected: if not "standard_info" in self._device_infos[d]: try: self._device_infos[d][ "standard_info"] = await states.async_getf_standard_device_info( d, None) except: traceback.print_exc() if not "extended_info" in self._device_infos[d]: try: self._device_infos[d][ "extended_info"] = await states.async_getf_extended_device_info( d, None) except: traceback.print_exc() finally: self._device_infos_update_running = False
from pyri.device_manager_client import DeviceManagerClient from RobotRaconteur.Client import * import time import traceback import os print(os.getpid()) input() d = DeviceManagerClient('rr+tcp://localhost:59902?service=device_manager', autoconnect=False) d.refresh_devices(1) d.connect_device('devices_states') dev_states_sub = d.get_device_subscription("devices_states") dev_states_wire_sub = dev_states_sub.SubscribeWire('devices_states') while True: try: print(dev_states_wire_sub.InValue.seqno) except: traceback.print_exc() time.sleep(0.1)
from pyri.device_manager_client import DeviceManagerClient from RobotRaconteur.Client import * d = DeviceManagerClient() #d = DeviceManagerClient() d.refresh_devices(1) for dev in d.get_device_names(): print(dev) print(d.get_device_info(dev).urls) try: print(d.get_device_client(dev, 1).device_info.manufacturer.name) except: pass
from pyri.device_manager_client import DeviceManagerClient from RobotRaconteur.Client import * d = DeviceManagerClient('rr+tcp://localhost:59902?service=device_manager', autoconnect=False) d.refresh_devices(1) d.connect_device_type("tech.pyri.robotics.jog.RoboticsJogService") d.get_device_client("robotics_jog", 1) # for dev in d.get_device_names(): # print (dev) # print(d.get_device_info(dev).urls) # print(d.get_device_client(dev,1).device_info.manufacturer.name)
from pyri.device_manager_client import DeviceManagerClient from RobotRaconteur.Client import * from RobotRaconteurCompanion.Util.GeometryUtil import GeometryUtil import numpy as np import general_robotics_toolbox as rox d = DeviceManagerClient('rr+tcp://localhost:59902?service=device_manager', autoconnect=False) d.refresh_devices(1) d.connect_device("robotics_motion") d.connect_device("robot") c = d.get_device_client("robotics_motion", 1) #p_target = np.array([-np.random.uniform(0.4,0.8),np.random.uniform(-0.1,0.1),np.random.uniform(0.0,0.4)]) p_target = np.array([ -np.random.uniform(-0.1, 0.1), np.random.uniform(-0.1, 0.1), np.random.uniform(0.0, 0.4) ]) rpy_target = np.random.randn(3) * 0.5 rpy_target[0] += np.pi R_target = rox.rpy2R(rpy_target) # p_target = np.array([-0.6, 0.0, 0.1]) # R_target = np.array([[0,1,0],[1,0,0],[0,0,-1]]) T_target = rox.Transform(R_target, p_target)
from pyri.device_manager_client import DeviceManagerClient from RobotRaconteur.Client import * import time import traceback import os print(os.getpid()) input() d = DeviceManagerClient('rr+tcp://localhost:59902?service=device_manager', autoconnect=False) d.refresh_devices(1) d.connect_device('joint_jog') jog_sub = d.get_device_subscription("jog_joint") i = 0 dir = 0 while True: i += 1 if i > 20: i = 0 elif i > 10: dir = -1 else: dir = 1
from pyri.device_manager_client import DeviceManagerClient from RobotRaconteur.Client import * import general_robotics_toolbox as rox from RobotRaconteurCompanion.Util.RobotUtil import RobotUtil from RobotRaconteurCompanion.Util.GeometryUtil import GeometryUtil import copy import numpy as np d = DeviceManagerClient('rr+tcp://localhost:59902?service=device_manager', autoconnect=False) d.refresh_devices(1) d.connect_device('robotics_jog') d.connect_device('robot') jog_service = d.get_device_client("robotics_jog", 1) print(jog_service.device_info.device.name) jog = jog_service.get_jog("robot") jog.setf_jog_mode() #for x in range(100): #jog.jog_joints3(1,1) #jog.setf_halt_mode() robot = d.get_device_client("robot", 1) robot_state, _ = robot.robot_state.PeekInValue()
from pyri.device_manager_client import DeviceManagerClient from RobotRaconteur.Client import * import time d = DeviceManagerClient('rr+tcp://localhost:59902?service=device_manager') d.refresh_devices(1) jog_service = d.get_device_client("jog_cartesian", 1) print(jog_service.device_info.device.name) jog = jog_service.get_jog("robot") #jog.setf_jog_mode() #for x in range(100): #jog.jog_joints3(1,1) #jog.setf_halt_mode() jog.prepare_jog() while True: for i in range(20): jog.jog_cartesian3([0, 0, 1], [0, 0, 0]) time.sleep(0.005) jog.stop_joints() for i in range(20):