def main(): print menu_header # Open the serial port # ************************** USER ENTERED PORT *************************** port = raw_input("Enter your serial port (EX: COM14)\n>>") cobs = cobs_serial(port, 115200, 1) # ************************** DEFAULT DEBUG PORT *************************** #print "Defaulting port to COM14. Change script if neeeded" #cobs = cobs_serial('COM14', 115200, 1) #apparently the port is offset by 1 (so COM14 is 13) # *************************** END PORT CONFIG **************************** #User Menu #Loop until user quits while True: option = raw_input(menu) sel = option.strip() if sel == '6': break elif sel == '1': #CONTROL LEDS do_led(cobs) elif sel == '2': #READ ADC VALUE do_adc(cobs) elif sel == '3': #TEST MOTORS do_motor(cobs) elif sel == '4': #CONTROL SERVOS do_servo(cobs) elif sel == '5': #READ ULTRASONIC SENSOR do_ultrasonic(cobs)
def main(): print menu_header # Open the serial port # ************************** USER ENTERED PORT *************************** port = raw_input("Enter your serial port (EX: COM14)\n>>") cobs = cobs_serial(port, 115200, 1) # ************************** DEFAULT DEBUG PORT *************************** # print "Defaulting port to COM14. Change script if neeeded" # cobs = cobs_serial('COM14', 115200, 1) #apparently the port is offset by 1 (so COM14 is 13) # *************************** END PORT CONFIG **************************** # User Menu # Loop until user quits while True: option = raw_input(menu) sel = option.strip() if sel == "6": break elif sel == "1": # CONTROL LEDS do_led(cobs) elif sel == "2": # READ ADC VALUE do_adc(cobs) elif sel == "3": # TEST MOTORS do_motor(cobs) elif sel == "4": # CONTROL SERVOS do_servo(cobs) elif sel == "5": # READ ULTRASONIC SENSOR do_ultrasonic(cobs)
def main(): print menu_header # Open the serial port # ************************** USER ENTERED PORT *************************** port = raw_input("Enter your serial port (EX: COM14)\n>>") cobs = cobs_serial(port, 115200, 1) # ************************** DEFAULT DEBUG PORT *************************** #print "Defaulting port to COM17. Change script if neeeded" #cobs = cobs_serial('COM17', 115200, 1) # *************************** END PORT CONFIG **************************** #User Menu #Loop until user quits while True: #sys.stderr.write("\x1b[2J\x1b[H") #print("\033c"); #clear() print menu_header # ask the user for the motor and command type motornum = getNumInRange(0, 5, motor_menu); if motornum == -1 or motornum == 0: continue if motornum == 4: stopMotors(cobs) continue if motornum == 5: break type = getNumInRange(0, 7, option_menu) if type == -1: continue # decide how to handle user input if type == 7: break elif type == 0: #DIRECTION do_direction(motornum, type, cobs) elif type == 1: #SPEED do_speed(motornum, type, cobs) elif type == 2: #ENCODER do_encoder(motornum, type, cobs) elif type == 3: #CURRENT do_current(motornum, type, cobs) elif type == 4: #MODE do_mode(motornum, type, cobs) elif type == 5: #POWER do_power(motornum, type, cobs); elif type == 6: #STOP MOTORS stopMotors(cobs)
def main(debug = False): print header # Open the serial port # ************************** USER ENTERED PORT *************************** #port = raw_input("Enter your serial port (EX: COM14)\n>>") #cobs = cobs_serial(port, 115200, 1) # ************************** DEFAULT DEBUG PORT *************************** print "Defaulting port to COM12. Change script if needed" cobs = cobs_serial('COM12', 115200, 1) # *************************** END PORT CONFIG **************************** print "Adding hardcoded ID's to whitelist..." white1 = 0x0201041B # apparent ID taken from C# code that worked with "observer" code. # (0201041B) in hex = (33621019) in decimal. white2 = 0x01010101 # arbitrary second white listed ID whitelist = [white1, white2, 10506251] #list of whitelisted ID's #print "Whitelisted ID: " + repr(white1) print "Whitelist contents: " + repr(list(whitelist)) #print len(whitelist) # print "Building data structures..." id_map = {} for id in whitelist: id_map[id] = [init_rssi_avg, -1000, deque([init_rssi_avg,init_rssi_avg,init_rssi_avg, \ init_rssi_avg,init_rssi_avg,init_rssi_avg,init_rssi_avg,init_rssi_avg, \ init_rssi_avg,init_rssi_avg])] #total, average (UNUSED ATM), values (10 total) if debug: print id_map while(True): #below read has a timeout of 1 second? retarray = cobs.block_and_return() #this function checks the CRC for us. returns data only, no crc if not(retarray == None): rssi_number = struct.unpack('b', retarray[rssi_start_byte:rssi_stop_byte]) id_number = struct.unpack('>L', retarray[id_start_byte:id_stop_byte]) #if debug: #print "Recieved byte array:\n" + repr(retarray) #print "ID bytes: " + repr(retarray[id_start_byte:id_stop_byte]) #print "RSSI bytes: " + repr(retarray[rssi_start_byte:rssi_stop_byte]) + "\n" if debug: print "\nID number = " + repr(id_number[0]) print "RSSI number = " + repr(rssi_number[0]) #if id_number in id_map: #currently the update_map function implements this behavior update_map(id_map, id_number[0], rssi_number[0], cobs, debug)