def loop(): global xb, telem, coord DEFAULT_COM_PORT = 'COM7' DEFAULT_BAUD_RATE = 57600 DEFAULT_ADDRESS = '\x10\x21' DEFAULT_PAN = 0x1001 if len(sys.argv) == 1: com = DEFAULT_COM_PORT baud = DEFAULT_BAUD_RATE addr = DEFAULT_ADDRESS elif len(sys.argv) == 4: com = sys.argv[1] baud = int(sys.argv[2]) addr = pack('>H', int(sys.argv[3], 16)) else: print "Wrong number of arguments. Must be: COM BAUD ADDR" sys.exit(1) ser = Serial(port = com, baudrate = baud) xb = XBee(ser, callback = rxCallback) print "Setting PAN ID to " + hex(DEFAULT_PAN) xb.at(command = 'ID', parameter = pack('>H', DEFAULT_PAN)) comm = CommandInterface(addr, txCallback) telem = TelemetryReader(addr, txCallback) kbint = KeyboardInterface(comm) coord = NetworkCoordinator(txCallback) comm.enableDebug() telem.setConsoleMode(True) telem.setFileMode(True) telem.writeHeader() coord.resume() comm.setSlewLimit(3.0) while True: try: c = None if( msvcrt.kbhit() ): c = msvcrt.getch() kbint.process(c) time.sleep(0.01) #comm.sendPing() except: break telem.close() xb.halt() ser.close()
def loop(): global xb, telem, coord DEFAULT_COM_PORT = 'COM7' DEFAULT_BAUD_RATE = 57600 DEFAULT_ADDRESS = '\x10\x21' DEFAULT_PAN = 0x1001 if len(sys.argv) == 1: com = DEFAULT_COM_PORT baud = DEFAULT_BAUD_RATE addr = DEFAULT_ADDRESS elif len(sys.argv) == 4: com = sys.argv[1] baud = int(sys.argv[2]) addr = pack('>H', int(sys.argv[3], 16)) else: print "Wrong number of arguments. Must be: COM BAUD ADDR" sys.exit(1) ser = Serial(port=com, baudrate=baud) xb = XBee(ser, callback=rxCallback) print "Setting PAN ID to " + hex(DEFAULT_PAN) xb.at(command='ID', parameter=pack('>H', DEFAULT_PAN)) comm = CommandInterface(addr, txCallback) telem = TelemetryReader(addr, txCallback) kbint = KeyboardInterface(comm) coord = NetworkCoordinator(txCallback) comm.enableDebug() telem.setConsoleMode(True) telem.setFileMode(True) telem.writeHeader() coord.resume() comm.setSlewLimit(3.0) while True: try: c = None if (msvcrt.kbhit()): c = msvcrt.getch() kbint.process(c) time.sleep(0.01) #comm.sendPing() except: break telem.close() xb.halt() ser.close()
def loop(): DEFAULT_COM_PORT = 'COM7' DEFAULT_BAUD_RATE = 57600 DEFAULT_ADDRESS = '\x10\x21' DEFAULT_PAN = '\x10\x01' if len(sys.argv) == 1: com = DEFAULT_COM_PORT baud = DEFAULT_BAUD_RATE addr = DEFAULT_ADDRESS elif len(sys.argv) == 4: com = sys.argv[1] baud = int(sys.argv[2]) addr = pack('>H', int(sys.argv[3], 16)) else: print "Wrong number of arguments. Must be: COM BAUD ADDR" sys.exit(1) coord = CommandInterface(addr, txCallback) coord.enableDebug() ser = Serial(port = com, baudrate = baud) xb = XBee(ser) print "Setting PAN ID to " + hex(DEFAULT_PAN) xb.at(command = 'ID', parameter = pack('>H', DEFAULT_PAN)) thrust = 0.0 yaw = 0.0 elevator = 0.0 while True: try: c = msvcrt.getch() if c == 'w': thrust = thrust + THRUST_INCREMENT elif c == 'a': yaw = yaw + YAW_INCREMENT elif c == 's': thrust = thrust - THRUST_INCREMENT elif c == 'd': yaw = yaw - YAW_INCREMENT elif c == 'r': elevator = elevator + ELEVATOR_INCREMENT elif c == 'f': elevator = elevator - ELEVATOR_INCREMENT elif c == 'q': thrust = 0.0 yaw = 0.0 elevator = 0.0 elif c == 'e': break elif c == 't': coord.setRegulatorMode(RegulatorStates['Remote Control']) if thrust > THRUST_UPPER_LIMIT: thrust = THRUST_UPPER_LIMIT elif thrust < THRUST_LOWER_LIMIT: thrust = THRUST_LOWER_LIMIT if yaw > YAW_UPPER_LIMIT: yaw = YAW_UPPER_LIMIT elif yaw < YAW_LOWER_LIMIT: yaw = YAW_LOWER_LIMIT if elevator > ELEVATOR_UPPER_LIMIT: elevator = ELEVATOR_UPPER_LIMIT elif elevator < ELEVATOR_LOWER_LIMIT: elevator = ELEVATOR_LOWER_LIMIT coord.setRemoteControlValues(thrust, yaw, elevator) except: print "Exception: ", sys.exc_info()[0] break xb.halt() ser.close()
DEFAULT_PAN = 0x1001 DEFAULT_ITERS = 10 if len(sys.argv) == 1: com = DEFAULT_COM_PORT baud = DEFAULT_BAUD_RATE addr = DEFAULT_ADDRESS iters = DEFAULT_ITERS elif len(sys.argv) == 5: com = sys.argv[1] baud = int(sys.argv[2]) addr = pack(">H", int(sys.argv[3], 16)) iters = int(sys.argv[4]) coord = CommandInterface(addr, txCallback) coord.enableDebug() # Enable XBee ser = Serial(port=com, baudrate=baud) xb = XBee(ser, callback=processPacket) print "Setting PAN ID to " + hex(DEFAULT_PAN) xb.at(command="ID", parameter=pack(">H", DEFAULT_PAN)) # Create file today = datetime.today() d = str(today.year) + "_" + str(today.month) + "_" + str(today.day) t = str(today.hour) + "_" + str(today.minute) + "_" + str(today.second) fname = "Latency_Test-" + d + "-" + t + ".txt" record_log = open(fname, "w")
def loop(): DEFAULT_COM_PORT = 'COM0' DEFAULT_BAUD_RATE = 57600 DEFAULT_ADDRESS = '\x10\x21' DEFAULT_PAN = '\x10\x01' if len(sys.argv) == 1: com = DEFAULT_COM_PORT baud = DEFAULT_BAUD_RATE addr = DEFAULT_ADDRESS elif len(sys.argv) == 4: com = sys.argv[1] baud = int(sys.argv[2]) addr = pack('>H', int(sys.argv[3], 16)) else: print "Wrong number of arguments. Must be: COM BAUD ADDR" sys.exit(1) coord = CommandInterface(addr, txCallback) coord.enableDebug() ser = Serial(port=com, baudrate=baud) xb = XBee(ser) print "Setting PAN ID to " + hex(DEFAULT_PAN) xb.at(command='ID', parameter=pack('>H', DEFAULT_PAN)) thrust = 0.0 yaw = 0.0 elevator = 0.0 while True: try: c = msvcrt.getch() if c == 'w': thrust = thrust + THRUST_INCREMENT elif c == 'a': yaw = yaw + YAW_INCREMENT elif c == 's': thrust = thrust - THRUST_INCREMENT elif c == 'd': yaw = yaw - YAW_INCREMENT elif c == 'r': elevator = elevator + ELEVATOR_INCREMENT elif c == 'f': elevator = elevator - ELEVATOR_INCREMENT elif c == 'q': thrust = 0.0 yaw = 0.0 elevator = 0.0 elif c == 'e': break elif c == 't': coord.setRegulatorMode(RegulatorStates['Remote Control']) if thrust > THRUST_UPPER_LIMIT: thrust = THRUST_UPPER_LIMIT elif thrust < THRUST_LOWER_LIMIT: thrust = THRUST_LOWER_LIMIT if yaw > YAW_UPPER_LIMIT: yaw = YAW_UPPER_LIMIT elif yaw < YAW_LOWER_LIMIT: yaw = YAW_LOWER_LIMIT if elevator > ELEVATOR_UPPER_LIMIT: elevator = ELEVATOR_UPPER_LIMIT elif elevator < ELEVATOR_LOWER_LIMIT: elevator = ELEVATOR_LOWER_LIMIT coord.setRemoteControlValues(thrust, yaw, elevator) except: print "Exception: ", sys.exc_info()[0] break xb.halt() ser.close()
def loop(): global xb, telem, coord DEFAULT_COM_PORT = 'COM7' DEFAULT_BAUD_RATE = 57600 DEFAULT_ADDRESS = '\x10\x21' DEFAULT_PAN = 0x1001 if len(sys.argv) == 1: com = DEFAULT_COM_PORT baud = DEFAULT_BAUD_RATE addr = DEFAULT_ADDRESS elif len(sys.argv) == 4: com = sys.argv[1] baud = int(sys.argv[2]) addr = pack('>H', int(sys.argv[3], 16)) else: print "Wrong number of arguments. Must be: COM BAUD ADDR" sys.exit(1) ser = Serial(port = com, baudrate = baud) xb = XBee(ser, callback = rxCallback) print "Setting PAN ID to " + hex(DEFAULT_PAN) xb.at(command = 'ID', parameter = pack('>H', DEFAULT_PAN)) comm = CommandInterface(addr, txCallback) telem = TelemetryReader(addr, txCallback) kbint = KeyboardInterface(comm) coord = NetworkCoordinator(txCallback) comm.enableDebug() telem.setConsoleMode(True) telem.setFileMode(True) telem.writeHeader() coord.resume() comm.setSlewLimit(3.0) while True: try: # Copied from code.activestate.com/recipes/134892/ # TODO: Find a way to avoid this blocking call fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno()) c = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) kbint.process(c) time.sleep(0.01) #comm.sendPing() except: break telem.close() xb.halt() ser.close()
DEFAULT_ITERS = 10 DEFAULT_CHAN = 0x12 if len(sys.argv) == 1: com = DEFAULT_COM_PORT baud = DEFAULT_BAUD_RATE #addr = DEFAULT_ADDRESS iters = DEFAULT_ITERS elif len(sys.argv) == 5: com = sys.argv[1] baud = int(sys.argv[2]) addr = pack('>H', int(sys.argv[3], 16)) iters = int(sys.argv[4]) coord = CommandInterface(addr, txCallback) coord.enableDebug() # Enable XBee ser = Serial(port = com, baudrate = baud) xb = XBee(ser, callback = processPacket) print "Setting PAN ID to " + hex(DEFAULT_PAN) xb.at(command = 'ID', parameter = pack('>H', DEFAULT_PAN)) xb.at(command = 'CH', parameter = pack('>H', DEFAULT_CHAN)) xb.at(command = 'MY', parameter = pack('>H', DEFAULT_ADDRESS)) # Create file today = datetime.today() d = str(today.year) + "_" + str(today.month) + "_" + str(today.day) t = str(today.hour) + "_" + str(today.minute) + "_" + str(today.second) fname = 'Latency_Test-' + d + '-' + t + '.txt'