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)
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")
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")