async def client_plotly(): uname=document.getElementById("uname").value psw=document.getElementById("psw").value credentials={"password":RR.RobotRaconteurVarValue(psw,"string")} try: inst=await RRN.AsyncConnectService('rr+ws://128.113.224.144:52222/?service=SmartCam',uname,credentials,None,None) Sawyer=await RRN.AsyncConnectService('rr+ws://128.113.224.144:58653?service=sawyer',None,None,None,None) UR=await RRN.AsyncConnectService('rr+tcp://128.113.224.144:58652?service=ur_robot',None,None,None,None) c_host=await RRN.AsyncConnectService('rr+ws://128.113.224.144:2366?service=Webcam',uname,credentials,None,None) c= await c_host.async_get_Webcams(0,None) p= await c.FrameStream.AsyncConnect(-1,None) global canvas, ctx canvas = document.getElementById("image") ctx = canvas.getContext("2d") print_div("Running!") p.PacketReceivedEvent+=new_frame c.async_StartStreaming(None) #robot state flag robot_const = RRN.GetConstants("com.robotraconteur.robotics.robot", Sawyer) state_flags_enum = robot_const['RobotStateFlags'] while True: await plot(UR,Sawyer, inst, state_flags_enum) # await RRN.AsyncSleep(0.01,None) except: print_div(traceback.format_exc()) raise
async def async_select_available_robot_url(robot_urls): print_div("Selecting the robot URL.. <br>") # Read the selected robot index from the browser element_id = "available_robots" available_robots_list = document.getElementById(element_id) index = available_robots_list.selectedIndex return robot_urls[index]
async def client_webcam(): # rr+ws : WebSocket connection without encryption # url ='rr+ws://localhost:2355?service=Webcam' # url ='rr+ws://192.168.1.128:2355?service=Webcam' # url ='rr+ws://192.168.43.241:2355?service=Webcam' url = 'rr+ws://192.168.50.152:2355?service=Webcam' try: c_host = await RRN.AsyncConnectService(url, None, None, None, None) c = await c_host.async_get_Webcams(0, None) p = await c.FrameStream.AsyncConnect(-1, None) global canvas, ctx canvas = document.getElementById("camera_image") ctx = canvas.getContext("2d") print_div("Camera is Running!<br>") finish_time = 0 # while True: p.PacketReceivedEvent += new_frame c.async_StartStreaming(None) await RRN.AsyncSleep(0.01, None) except: import traceback print_div(traceback.format_exc()) raise
async def client_matplotlib(): uname = document.getElementById("uname").value psw = document.getElementById("psw").value credentials = {"password": RR.RobotRaconteurVarValue(psw, "string")} try: c_host = await RRN.AsyncConnectService( 'rr+ws://128.113.224.144:2366?service=Webcam', uname, credentials, None, None) c = await c_host.async_get_Webcams(0, None) p = await c.FrameStream.AsyncConnect(-1, None) global canvas, ctx canvas = document.getElementById("image") ctx = canvas.getContext("2d") print_div("Running!") while True: p.PacketReceivedEvent += new_frame c.async_StartStreaming(None) await RRN.AsyncSleep(0.01, None) except: import traceback print_div(traceback.format_exc()) raise
def jog_joints2(q_i, degree_diff, is_relative): global is_jogging if (not is_jogging): is_jogging = True loop.call_soon(async_jog_joints2(q_i, degree_diff, is_relative)) else: print_div("Jogging has not finished yet..<br>")
def playback_poses_func(self): print_div("Playing Back Poses..<br>") global is_jogging if (not is_jogging): is_jogging = True loop.call_soon(async_playback_poses_func()) else: print_div("Jogging has not finished yet..<br>")
def go_sel_pose_func(self): print_div("Moving to selected pose..<br>") global is_jogging if (not is_jogging): is_jogging = True loop.call_soon(async_go_sel_pose_func()) else: print_div("Jogging has not finished yet..<br>")
def stop_func(self): print_div('STOP button pressed<br>') global plugin_jogJointSpace plugin_jogJointSpace.async_jog_joints_zeros(None) global is_jogging is_jogging = False
def stop_func(self): print_div('STOP button pressed<br>') global d, num_joints, joint_vel_limits d.async_jog_joint(np.zeros((num_joints, )), joint_vel_limits, False, True, None) global is_jogging is_jogging = False
def move_to_angles_func(self): print_div('Move to angles button pressed<br>') global is_jogging if (not is_jogging): is_jogging = True loop.call_soon(async_move_to_angles_func()) else: print_div("Jogging has not finished yet..<br>")
def jog_joints_gamepad(joint_speed_constants): joint_speed_constants = np.array(joint_speed_constants,dtype="f") # print_div(str(joint_speed_constants)+"<br>") global is_jogging if (not is_jogging): is_jogging = True loop.call_soon(async_jog_joints_gamepad(joint_speed_constants)) else: print_div("Jogging has not finished yet..<br>")
def jog_joints(q_i, sign): global is_mousedown is_mousedown = True global is_jogging if (not is_jogging): is_jogging = True loop.call_soon(async_jog_joints(q_i, sign)) else: print_div("Jogging has not finished yet..<br>")
def timer_cb(ev): if ev.stopped: return print_div("Got timer callback!") global i i += 1 if i > 10: timer.Stop() print_div("Stopped")
def jog_cartesian(P_axis, R_axis): global is_mousedown is_mousedown = True global is_jogging if (not is_jogging): is_jogging = True loop.call_soon(async_jog_cartesian(P_axis, R_axis)) else: print_div("Jogging has not finished yet..<br>")
async def client_discovery(): # ip_plugins = 'localhost' ip_plugins = '192.168.50.152' try: # Run the client as a class to access client data in a more convenient way cli_discovery = ClientDiscovery(ip_plugins) except: import traceback print_div(traceback.format_exc()) raise
async def test_wire_func(): c = await RRN.AsyncConnectService( "rr+ws://localhost:2222?service=RobotRaconteurTestService", None, None, None, None) w = await c.broadcastwire.AsyncConnect(None) await RRN.AsyncSleep(1, None) for _ in range(50): print_div(w.InValue) await RRN.AsyncSleep(0.01, None) print_div("Done!")
async def async_show_selected_cam_feedback(self): # Get ref to the html element index = self.available_cams_list.selectedIndex # Dictionary Key of the camera print_div("selected index: " + str(index) + "<br>") # Connects to WebcamImage struct pipe if self.selCamInd is None: # Start new one self.selCamInd = index # thisdict[sorted(thisdict)[1]] key = sorted(self.webcam_names)[self.selCamInd] print_div("selected key: " + str(key) + "<br>") # Selects index th Webcam object from Array of Webcam objects self.c = await self.c_host.async_get_Webcams(key, None) self.p = await self.c.FrameStream.AsyncConnect(-1, None) print_div("Camera '" + str(self.webcam_names[key]) + "' is Selected!<br>") self.p.PacketReceivedEvent += self.new_frame self.c.async_StartStreaming(None) await RRN.AsyncSleep(0.01, None) elif self.selCamInd != index: # Shut down the previous cam feedback # await self.p.AsyncClose(None) # await self.c.FrameStream.AsyncClose(-1,None) await self.c.async_StopStreaming(None) # Start new one self.selCamInd = index # thisdict[sorted(thisdict)[1]] key = sorted(self.webcam_names)[self.selCamInd] print_div("selected key: " + str(key) + "<br>") # Selects index th Webcam object from Array of Webcam objects self.c = await self.c_host.async_get_Webcams(key, None) self.p = await self.c.FrameStream.AsyncConnect(-1, None) print_div("Camera '" + str(self.webcam_names[key]) + "' is Selected!<br>") self.p.PacketReceivedEvent += self.new_frame self.c.async_StartStreaming(None) await RRN.AsyncSleep(0.01, None)
async def async_create_available_robots_list(self): print_div("Auto discovering..") await self.plugin_discovery.async_autodiscover(None) try: # print_div("Clearing the previous available robot options..") length = self.available_robots_list.options.length i = length-1 while i >= 0: self.available_robots_list.options[i] = None i -= 1 print_div('Creating available robots options..<br>') self.robot_nodeNames = await self.plugin_discovery.async_available_robot_NodeNames(None) print_div(str(self.robot_nodeNames) + "<br>") i = 0 for nodeName in self.robot_nodeNames: # print_div(str(self.robot_nodeNames[key]) + "<br>") # --> Right # Add the available robot nodeName to the available_robots list option = document.createElement("option") option.text = str(i) + ": " + str(nodeName) self.available_robots_list.add(option) i += 1 except: import traceback print_div(traceback.format_exc())
async def test_await_func(): c = await RRN.AsyncConnectService("rr+ws://localhost:2222?service=RobotRaconteurTestService", None, None, None, None) print_div("d1: " + str(await c.async_get_d1(None))) print_div("i32_huge: " + str(await c.async_get_i32_huge(None))) try: await c.async_set_d1(5,None) except GeneratorExit: raise except Exception as exp: print_div("Caught exception: " + str(exp)) print_div("d1: " + str(await c.async_get_d1(None))) await c.async_set_d1(3.456,None) print_div("Done!")
async def async_del_sel_pose_func(): # Read the selected pose index from the browser element_id = "saved_poses_list" poses_list = document.getElementById(element_id) index = poses_list.selectedIndex try: if index == -1: print_div("Please select a pose from Saved Poses.<br>") else: global plugin_savePlayback await plugin_savePlayback.async_del_sel_pose(index,None) # Delete from UI too. poses_list.remove(index); except: pass
async def client_vision(): # ip_cam = 'localhost' ip_cam = '192.168.50.152' # ip_cam = '192.168.50.40' # ip_plugins = 'localhost' ip_plugins = '192.168.50.152' try: # Run the client as a class to access client data in a more convenient way cli_vision = ClientVision(ip_cam, ip_plugins) except: import traceback print_div(traceback.format_exc()) raise
def save_cur_pose_func(self): print_div('Saving to "Saved Poses" list..<br>') global d_q # Get the current joint angles in rad ndarray # Convert them into degrees for text view joints_text = "" for i in d_q: joints_text += "%.2f," % (np.rad2deg(i)) joints_text = joints_text[:-1] # Delete the last comma # Add the current joint angles to the saved poses list element_id = "saved_poses_list" poses_list = document.getElementById(element_id) option = document.createElement("option") option.text = joints_text poses_list.add(option)
async def test_subscriber_func(): sub = RRN.SubscribeService( "rr+ws://localhost:2222?service=RobotRaconteurTestService") #await RRN.AsyncSleep(0.5, None) c = await sub.AsyncGetDefaultClient(None) print_div("d1: " + str(await c.async_get_d1(None))) print_div("i32_huge: " + str(await c.async_get_i32_huge(None))) try: await c.async_set_d1(5, None) except GeneratorExit: raise except Exception as exp: print_div("Caught exception: " + str(exp)) print_div("d1: " + str(await c.async_get_d1(None))) await c.async_set_d1(3.456, None) print_div("Done!")
async def async_create_available_cams_list(self): print_div('Creating available cameras options..<br>') # # Get ref to the html element # element_id = "available_cams" # self.available_cams_list = document.getElementById(element_id) self.webcam_names = await self.c_host.async_get_WebcamNames( None ) # string{int32} i.e. a map (dictionary) of strings keyed by an integer. print_div(str(self.webcam_names) + "<br>") # str(self.webcam_names) --> {0:'Right'} for key in self.webcam_names: # print_div(str(self.webcam_names[key]) + "<br>") # --> Right # Add the current joint angles to the available_cams list option = document.createElement("option") option.text = str(key) + ":" + str(self.webcam_names[key]) self.available_cams_list.add(option)
async def async_down_sel_pose_func(): # Read the selected pose index from the browser element_id = "saved_poses_list" poses_list = document.getElementById(element_id) index = poses_list.selectedIndex try: if index == -1: print_div("Please select a pose from Saved Poses.<br>") else: global plugin_savePlayback await plugin_savePlayback.async_down_sel_pose(index,None) # Down it from UI too. if index < poses_list.length-1: option = poses_list.options[index]; poses_list.remove(index); poses_list.add(option,index+1) except: pass
async def async_playback_poses_func(): # Get elements, poses and paramaters from web interface poses_list = document.getElementById("saved_poses_list") num_loops_elem = document.getElementById("num_loops_in") num_loops = int(num_loops_elem.value) joint_vel_range = document.getElementById("joint_vel_range") joint_vel_ratio = float(joint_vel_range.value)/100.0 # Time to complete the playback time_loops_elem = document.getElementById("time_loops_in") t_complete = float(time_loops_elem.value) #seconds if poses_list.length >= 4: global plugin_savePlayback await plugin_savePlayback.async_playback_poses(num_loops, joint_vel_ratio, t_complete, None) else: print_div("You need at least 4 different points. Add some poses to Saved Poses and try again<br>") global is_jogging is_jogging = False
async def async_move_to_angles_func(): global is_jogging global plugin_jogJointSpace joint_angles = np.zeros((7,)) element_id = "j1_angle_in" for j in range(1,7+1): element_id = "j" + str(j) + "_angle_in" text_container_angle = document.getElementById(element_id) angle = text_container_angle.value # str and in degrees try: # if not angle == None or not angle == "": joint_angles[j-1] = float(angle)* np.deg2rad(1) except: # else: print_div("Please specify angle of each joint!<br>") is_jogging = False return await plugin_jogJointSpace.async_jog_joints_to_angles(joint_angles,None) is_jogging = False
async def async_jog_joints(q_i, sign): degree_diff = 1 global d, d_q, num_joints, joint_lower_limits, joint_upper_limits, joint_vel_limits global is_mousedown while (is_mousedown): # Update joint angles d_q = await update_joint_info() # Joint angles in radian ndarray # UPdate the end effector pose info pose = await update_end_info() await update_state_flags() if (num_joints < q_i): print_div("Currently Controlled Robot only have " + str(num_joints) + " joints..<br>") else: joint_diff = np.zeros((num_joints, )) joint_diff[q_i - 1] = sign * np.deg2rad(degree_diff) if not ((d_q + joint_diff) < joint_upper_limits).all() or not ( (d_q + joint_diff) > joint_lower_limits).all(): print_div("Specified joints might be out of range<br>") else: try: await d.async_jog_joint(joint_diff, joint_vel_limits, True, True, None) except: print_div("Specified joints might be out of range222<br>") global is_jogging is_jogging = False
async def async_move_to_angles_func(): global d, num_joints, joint_lower_limits, joint_upper_limits, joint_vel_limits global is_jogging joint_angles = np.zeros((num_joints, )) element_id = "j1_angle_in" for j in range(1, num_joints + 1): element_id = "j" + str(j) + "_angle_in" text_container_angle = document.getElementById(element_id) angle = text_container_angle.value # str and in degrees try: # if not angle == None or not angle == "": joint_angles[j - 1] = float(angle) * np.deg2rad(1) except: # else: print_div("Please specify angle of each joint!<br>") is_jogging = False return if not (joint_angles < joint_upper_limits).all() or not ( joint_angles > joint_lower_limits).all(): print_div("Specified joints are out of range<br>") is_jogging = False return else: try: await d.async_jog_joint(joint_angles, joint_vel_limits, False, True, None) except: print_div("Specified joints might be out of range<br>") is_jogging = False
async def async_go_sel_pose_func(): global d, num_joints, joint_lower_limits, joint_upper_limits, joint_vel_limits global is_jogging # Read the selected pose from the browser element_id = "saved_poses_list" poses_list = document.getElementById(element_id) index = poses_list.selectedIndex try: if index == -1: print_div("Please select a pose from Saved Poses.<br>") raise else: sel_pose = poses_list.options[index].value # angles as str joint_angles = np.fromstring(sel_pose, dtype=float, sep=',') * np.deg2rad(1) # in rad if not (joint_angles < joint_upper_limits).all() or not ( joint_angles > joint_lower_limits).all(): print_div("Specified joints are out of range<br>") raise else: try: await d.async_jog_joint(joint_angles, joint_vel_limits, False, True, None) except: print_div("Specified joints might be out of range<br>") raise except: is_jogging = False is_jogging = False