def hold(self, joint_id=[1]):
		cmd =  "\"{"
		cmd += "\\\"action\\\":\\\"hold\\\","
		cmd += "\\\"joint_ids\\\":"+str(joint_id)
		cmd += "}\""
		SockJSClient.send(self,cmd)
		return 1
	def delete_script(self, script_id=1):
		cmd =  "\"{"
		cmd += "\\\"action\\\":\\\"delete_script\\\","
		cmd += "\\\"script_id\\\":\\\""+str(script_id)+"\\\""
		cmd += "}\""
		SockJSClient.send(self,cmd)
		return 1
	def test_script(self, script_code=""): 
		cmd =  "\"{" 
		cmd += "\\\"action\\\":\\\"test_script\\\"," 
		cmd += "\\\"script_id\\\":\\\"0\\\"," 
		cmd += "\\\"script_code\\\":\\\""+script_code+"\\\"" 
		cmd += "}\"" 
		SockJSClient.send(self, cmd) 
		return 1 
	def save_script(self, script_name="", script_code=""):
		cmd =  "\"{"
		cmd += "\\\"action\\\":\\\"save_script\\\","
		cmd += "\\\"script_name\\\":\\\""+script_name+"\\\","
		cmd += "\\\"script_code\\\":\\\""+script_code+"\\\""
		cmd += "}\""
		SockJSClient.send(self,cmd)
		return 1
	def calibrate(self, use_existing=True):
		if self.get_connection_info() == 2:
			cmd =  "\"{"
			cmd += "\\\"action\\\":\\\"calibrate\\\","
			cmd += "\\\"use_existing\\\":"+str(use_existing).lower()
			cmd += "}\""
			SockJSClient.send(self, cmd)
			return 1 
		return 0 
	def get_script(self, script_id=1):
		SockJSClient.remove_status(self, "one_script")
		self.request_script(script_id)
		script = SockJSClient.get_status(self, "one_script")
		counter = 0
		while (script == 0):
		    time.sleep(0.001) 
		    script = SockJSClient.get_status(slef, "one_script")
	        counter += 1
	        if (counter > 100):
	            return 0
		return script
	def initialize(self, model="PRob1R", kind='no_robot', channel_name="1", channel_type="PEAK_SYS_PCAN_USB", protocol="TMLCAN", host_id="10", baudrate="500000"):
		if self.get_connection_info() == 0:
			cmd =  "\"{"
			cmd += "\\\"action\\\":\\\"initialize\\\","
			cmd += "\\\"model\\\":\\\""+model+"\\\","
			cmd += "\\\"robot_kind\\\":\\\""+kind+"\\\""
			if kind == 'real':
				cmd += ","
				cmd += "\\\"channel_name\\\":\\\""+channel_name+"\\\","
				cmd += "\\\"channel_type\\\":\\\""+channel_type+"\\\","
				cmd += "\\\"protocol\\\":\\\""+protocol+"\\\","
				cmd += "\\\"host_id\\\":\\\""+host_id+"\\\","
				cmd += "\\\"baudrate\\\":\\\""+baudrate+"\\\""
			cmd += "}\""
			SockJSClient.send(self, cmd)
			return 1
		return 0
def start_server(ip):
	global myp
	
	try:
		rospy.init_node('MyP')
		
		# ROS service
		srv_move_joint = rospy.Service('move_joint', MoveJoint, handle_move_joint)
		srv_move_tool = rospy.Service('move_tool', MoveTool, handle_move_tool)
		srv_move_to_point = rospy.Service('move_to_point', MoveToPoint, handle_move_to_point)
		srv_move_wait_joint = rospy.Service('wait_joint', WaitJoint, handle_wait_joint)
		srv_move_wait = rospy.Service('wait', Wait, handle_wait)
		srv_get_scripts = rospy.Service('get_scripts', GetScripts, handle_get_scripts)
		
		## Connection to myP XMLRPC server
		#robot_arm = ServerProxy("http://"+ip+":8000", verbose=False, allow_none=True)
		## calibrate robot
		#robot_arm.calibrate()
		

		myp = SockJSClient('/socket', ip, 8888)
		myp.connect()
			
		myp_get_connection_info()
		myp_initialize()
		time.sleep(2)
		myp_calibrate()
		time.sleep(0.5)
		print("Connected to PRob. Ready...")
		rate = rospy.Rate(1)
		while not rospy.is_shutdown():

			#rospy.spin()
			print 'this is prob_server_lenli speaking...'
			rate.sleep()
			

		myp.disconnect()
	
	except Exception as ex:
		print("ERROR: ", ex)
		sys.exit(1)
	def get_actuator_release_state(self):
		state = SockJSClient.get_status(self, "actuator_release_state")
		print("Actuator Release State: ", state)
		return state
	def get_application_info(self):
		message = SockJSClient.get_status(self, "application_info")
		print("Application Info: ", message)
		return message
	def get_message_info(self):
		message = SockJSClient.get_status(self, "message_info")
		print("Message Info: ", message)
		return message
	def get_status_info(self):
		status = SockJSClient.get_status(self, "status_info")
		print("Status Info: ", status)
		return status
	def get_paths(self):
		paths = SockJSClient.get_status(self, "paths")
		print("Paths: ", paths)
		return paths
	def recover(self):
		cmd =  "\"{"
		cmd += "\\\"action\\\":\\\"recover\\\""
		cmd += "}\""
		SockJSClient.send(self,cmd)
		return 1
	def get_current(self):
		current = SockJSClient.get_status(self, "current")
		print("Current: ", current)
		return current
Esempio n. 16
0
        rospy.spin()

    except Exception as ex:
        print("ERROR: ", ex)
        sys.exit(1)


def usage():
    return "%s [PRob ip address]" % sys.argv[0]


if __name__ == "__main__":
    if len(sys.argv) == 2:
        ip = sys.argv[1]
    else:
        print(usage())
        sys.exit(1)
    try:
        myp = SockJSClient('/socket', ip, 8888)
        myp.connect()
        start_server()

    except:
        print("Could not connect to myP at: ", ip)
        # traceback.print_exc()
        # raise

    finally:
        myp.disconnect()
        print("Server closed")
	def finalize(self):
		cmd =  "\"{"
		cmd += "\\\"action\\\":\\\"finalize\\\""
		cmd += "}\""
		SockJSClient.send(self, cmd)
		return 1
	def get_scripts(self):
		scripts = SockJSClient.get_status(self, "scripts")
		#res.scripts = "hello py service"#str(scripts)
		print('service called')
		#print(str(scripts))
		return GetScriptsResponse(str(scripts))
	def get_connection_info(self):
		connection = SockJSClient.get_status(self, "connection_info")
		print("Connection Info: ", connection)
		return connection
	def stop(self):
		cmd =  "\"{"
		cmd += "\\\"action\\\":\\\"stop\\\""
		cmd += "}\""
		SockJSClient.send(self,cmd) 
		return 1
	def get_position(self):
		position = SockJSClient.get_status(self, "position")
		print("Position: ", position)
		return position
Esempio n. 22
0
    print "Status: ", robot_arm.get_status_info()
    start_new_thread(robot_arm.publisher,())
    rospy.spin()

  except Exception as ex:
    print("ERROR: ", ex)
    sys.exit(1)

def usage():
    return "%s [PRob ip address]"%sys.argv[0]

if __name__ == "__main__":
  if len(sys.argv) == 2:
    ip = sys.argv[1] 
  else:
    print( usage() )
    sys.exit(1)
  try:
    myp = SockJSClient('/socket', ip, 8888)
    myp.connect()
    start_server()

  except:
    print("Could not connect to myP at: ", ip)
    # traceback.print_exc()
    # raise

  finally:
    myp.disconnect()
    print("Server closed")
	def get_euler_position(self):
		position = SockJSClient.get_status(self, "euler_position")
		print("Euler Position: ", position)
		return position
	def get_poses(self):
		poses = SockJSClient.get_status(self, "poses")
		print("Poses: ", poses)
		return poses
	def get_script_id(self, name):
		scripts = SockJSClient.get_status(slef, "scripts")
		for script in scripts:
		    if script[1] == name:
		      return script[0]
		return 0
	def __init__(self, prefix, host = "localhost", port = 80):
		SockJSClient.__init__(self, prefix, host, port)
	def pause(self):
		cmd =  "\"{"
		cmd += "\\\"action\\\":\\\"pause\\\""
		cmd += "}\""
		SockJSClient.send(self,cmd)
		return 1
Esempio n. 28
0
			cmd += "\\\"protocol\\\":\\\""+protocol+"\\\","
			cmd += "\\\"host_id\\\":\\\""+host_id+"\\\","
			cmd += "\\\"baudrate\\\":\\\""+baudrate+"\\\""
		cmd += "}\""
		myp.send(cmd)
		return 1
	return 0
	
try:
	#connect to myP server through a sock js connection
	ip = "192.168.80.219"
	#ip = "192.168.21.173"
	#ip = "localhost"
	#ip = "10.2.105.42"
	#ip = "192.168.1.16"
	myp = SockJSClient('/socket', ip, 8888)
	myp.connect()
		
	myp_get_connection_info()
	myp_initialize()
	time.sleep(2)
	myp_calibrate()
	time.sleep(0.5)
	
	while True:
		scripts = myp.get_status("scripts")
		print("Scripts: ", scripts)
		time.sleep(1)
	
	 #start xmlrpc server
#    server = SimpleXMLRPCServer(('', 8000), allow_none=True)