예제 #1
0
def update():
    global outputLabel
    cont.update()
    buttons1 = 0x0
    buttons2 = 0x0
    # going to eight would include the start button; however, it seems that when 0x80 (only the start button) is sent
    # the arduino lags for a second or two and reports false values for buttons
    for i in range(0, cont.getNumButtons()):
        if(cont.getButton(i)):
            if(cont.getValueForButton(i) <= 0xFF):
                buttons1 += cont.getValueForButton(i)
            else:
                buttons2 += cont.getValueForButton(i) >> 8

    outbound.write("STR")                               #  sends a signal to tell that this is the start of data
    outbound.write(chr(buttons1))                       # writes the buttons first
    outbound.write(chr(buttons2))
    outbound.write(str(int(cont.getPrimaryX())))        # casts the floats to ints, then to strings for simple parsing
    outbound.write(" ")
    outbound.write(str(int(cont.getPrimaryY())))
    outbound.write(" ")
    outbound.write(str(int(cont.getSecondaryX())))
    outbound.write(" ")
    outbound.write(str(int(cont.getSecondaryY())))
    outbound.write(" ")
    outbound.write(str(int(cont.getTriggers())))
    outbound.write(" ")
    counter = 10
    proceed = False
    while True and counter > 0:
        counter -= 1
        if outbound.readable():
            if 'S' == outbound.read(1):
                if 'T' == outbound.read(1):
                    if 'R' == outbound.read(1):
                        proceed = True
                        break
    if(proceed):

        linesToRead = int(outbound.read(3))                 # allows for up to 999 lines to be read...
        for i in range(0, linesToRead):
            outputLabel['text'] = outbound.readline().rstrip()
    outputLabel.after(100, update)
예제 #2
0
파일: com.py 프로젝트: CalPolyUROV/UROV2016
    cont.update()
    buttons1 = 0x0
    buttons2 = 0x0
    # going to eight would include the start button; however, it seems that when 0x80 (only the start button) is sent
    # the arduino lags for a second or two and reports false values for buttons
    for i in range(0, cont.getNumButtons()):
        if(cont.getButton(i)):
            if(cont.getValueForButton(i) <= 0xFF):
                buttons1 += cont.getValueForButton(i)
            else:
                buttons2 += cont.getValueForButton(i) >> 8

    outbound.write("STR")                               #  sends a signal to tell that this is the start of data
    outbound.write(chr(buttons1))                       # writes the buttons first
    outbound.write(chr(buttons2))
    outbound.write(str(int(cont.getPrimaryX())))        # casts the floats to ints, then to strings for simple parsing
    outbound.write(" ")
    outbound.write(str(int(cont.getPrimaryY())))
    outbound.write(" ")
    outbound.write(str(int(cont.getSecondaryX())))
    outbound.write(" ")
    outbound.write(str(int(cont.getSecondaryY())))
    outbound.write(" ")
    outbound.write(str(int(cont.getTriggers())))
    outbound.write(" ")
    time.sleep(0.1)                                    # allows for chirps of information rather than a stream




예제 #3
0
def update():
    cont.update()
    buttons1 = 0x0
    buttons2 = 0x0
    # going to eight would include the start button; however, it seems that when 0x80 (only the start button) is sent
    # the arduino lags for a second or two and reports false values for buttons
    for i in range(0, cont.getNumButtons()):
        if cont.getButton(i):
            if cont.getValueForButton(i) <= 0xFF:
                buttons1 += cont.getValueForButton(i)
            else:
                buttons2 += cont.getValueForButton(i) >> 8

    outbound.write("STR")  #  sends a signal to tell that this is the start of data
    outbound.write(chr(buttons1))  # writes the buttons first
    outbound.write(chr(buttons2))
    outbound.write(str(int(cont.getPrimaryX())))  # casts the floats to ints, then to strings for simple parsing
    outbound.write(" ")
    outbound.write(str(int(cont.getPrimaryY())))
    outbound.write(" ")
    outbound.write(str(int(cont.getSecondaryX())))
    outbound.write(" ")
    outbound.write(str(int(cont.getSecondaryY())))
    outbound.write(" ")
    outbound.write(str(int(cont.getTriggers())))
    outbound.write(" ")
    counter = 10
    proceed = False
    pressureOut["bg"] = "red"
    voltageOut["bg"] = "red"
    tempOut["bg"] = "red"
    accelOut["bg"] = "red"
    depthOut["bg"] = "red"
    pressureLabel["bg"] = "red"
    voltageLabel["bg"] = "red"
    tempLabel["bg"] = "red"
    accelLabel["bg"] = "red"
    depthLabel["bg"] = "red"
    while True and counter > 0:
        counter -= 1
        if outbound.readable():
            if "S" == outbound.read(1):
                if "T" == outbound.read(1):
                    if "R" == outbound.read(1):
                        proceed = True
                        break
    if proceed:
        linesToRead = int(outbound.read(3))  # allows for up to 999 lines to be read...
        for i in range(0, linesToRead // 2):
            label = outbound.readline().rstrip().lstrip()
            if label == "PSR":
                pressureOut["text"] = outbound.readline().rstrip()
                pressureOut["bg"] = "green"
                pressureLabel["bg"] = "green"
            elif label == "VLT":
                voltageOut["text"] = outbound.readline().rstrip()
                voltageOut["bg"] = "green"
                voltageLabel["bg"] = "green"
            elif label == "TMP":
                tempOut["text"] = outbound.readline().rstrip()
                tempOut["bg"] = "green"
                tempLabel["bg"] = "green"
            elif label == "ACL":
                accelOut["text"] = outbound.readline().rstrip() + "\n"
                accelOut["text"] += outbound.readline().rstrip() + "\n"
                accelOut["text"] += outbound.readline().rstrip()
                accelOut["bg"] = "green"
                accelLabel["bg"] = "green"
            elif label == "DPT":
                depthOut["text"] = outbound.readline().rstrip()
                depthOut["bg"] = "green"
                depthLabel["bg"] = "green"
            else:
                print "unknown datatype:", label
                print "data:", outbound.readline().rstrip()
    root.after(100, update)
예제 #4
0
    bytesize=serial.EIGHTBITS
)
print "connect the controller"
cont.update()
while not cont.isConnected():
    cont.update()
print "controller connected"
while(1):
    cont.update()
    buttons = 0x0
    for i in range(0, 8):
        if cont.getButton(i):
            buttons += (1 << i)
    #ser.print("STR")#should I send an ok signal to start the communication? how long does that take?
    ser.write(chr(buttons))
    ser.write(str(int(cont.getPrimaryX())))
    ser.write(" ")
    ser.write(str(int(cont.getPrimaryY())))
    ser.write(" ")
    ser.write(str(int(cont.getSecondaryX())))
    ser.write(" ")
    ser.write(str(int(cont.getSecondaryY())))
    ser.write(" ")
    ser.write(str(int(cont.getTriggers())))
    ser.write(" ")
    time.sleep(0.1)
    #ser.write("END")#should tis be replied to? or just not sent?



예제 #5
0
 def test_3_Axis(self):
     print "starting Axis test, press a to pass, b to fail"
     while True:
         time.sleep(0.1)
         cont.update()
         if cont.getButton(cont.A):
             break
         if cont.getButton(cont.B):
             self.assertEqual(True, False, "Axis Test Failed")
         print "X: ", cont.getPrimaryX(), " Y: ", cont.getPrimaryY(), " X2: ", cont.getSecondaryX(), " Y2: ", cont.getSecondaryY()
예제 #6
0
def update():
    cont.update()
    buttons1 = 0x0
    buttons2 = 0x0
    # going to eight would include the start button; however, it seems that when 0x80 (only the start button) is sent
    # the arduino lags for a second or two and reports false values for buttons
    for i in range(0, cont.getNumButtons()):
        if(cont.getButton(i)):
            if(cont.getValueForButton(i) <= 0xFF):
                buttons1 += cont.getValueForButton(i)
            else:
                buttons2 += cont.getValueForButton(i) >> 8

    outbound.write("STR")                               #  sends a signal to tell that this is the start of data
    outbound.write(chr(buttons1))                       # writes the buttons first
    outbound.write(chr(buttons2))
    outbound.write(str(int(cont.getPrimaryX())))        # casts the floats to ints, then to strings for simple parsing
    outbound.write(" ")
    outbound.write(str(int(cont.getPrimaryY())))
    outbound.write(" ")
    outbound.write(str(int(cont.getSecondaryX())))
    outbound.write(" ")
    outbound.write(str(int(cont.getSecondaryY())))
    outbound.write(" ")
    outbound.write(str(int(cont.getTriggers())))
    outbound.write(" ")
    counter = 10
    proceed = False
    pressureOut['bg'] = "red"
    voltageOut['bg'] = "red"
    tempOut['bg'] = "red"
    accelOut['bg'] = "red"
    depthOut['bg'] = "red"
    pressureLabel['bg'] = "red"
    voltageLabel['bg'] = "red"
    tempLabel['bg'] = "red"
    accelLabel['bg'] = "red"
    depthLabel['bg'] = "red"
    while True and counter > 0:
        counter -= 1
        if outbound.readable():
            if 'S' == outbound.read(1):
                if 'T' == outbound.read(1):
                    if 'R' == outbound.read(1):
                        proceed = True
                        break
    if(proceed):
        linesToRead = int(outbound.read(3))                 # allows for up to 999 lines to be read...
        for i in range(0, linesToRead // 2):
            label = outbound.readline().rstrip().lstrip()
            if(label == "PSR"):
                pressureOut['text'] = outbound.readline().rstrip()
                pressureOut['bg'] = "green"
                pressureLabel['bg'] = "green"
            elif(label == "VLT"):
                voltageOut['text'] = outbound.readline().rstrip()
                voltageOut['bg'] = "green"
                voltageLabel['bg'] = "green"
            elif(label == "TMP"):
                tempOut['text'] = outbound.readline().rstrip()
                tempOut['bg'] = "green"
                tempLabel['bg'] = "green"
            elif(label == "ACL"):
                accelOut['text'] = outbound.readline().rstrip() + '\n'
                accelOut['text'] += outbound.readline().rstrip() + '\n'
                accelOut['text'] += outbound.readline().rstrip()
                accelOut['bg'] = "green"
                accelLabel['bg'] = "green"
            elif(label == "DPT"):
                depthOut['text'] = outbound.readline().rstrip()
                depthOut['bg'] = "green"
                depthLabel['bg'] = "green"
            else:
                print "unknown datatype:", label
                print "data:", outbound.readline().rstrip()
    root.after(100, update)
예제 #7
0
        if half_m:
            outbound.write(str(int(cont.getPrimaryX()) / 2))
            outbound.write(" ")
            outbound.write(str(int(cont.getPrimaryY()) / 2))
        else:
            outbound.write(str(int(cont.getPrimaryX())))
            outbound.write(" ")
            outbound.write(str(int(cont.getPrimaryY())))

        #outbound.write(" ")
        #outbound.write(str(int(cont.getPrimaryY())))
        outbound.write(" ")
        outbound.write(str(int(cont.getSecondaryX())))
        outbound.write(" ")
        outbound.write(str(int(cont.getSecondaryY())))
        outbound.write(" ")
        #outbound.write(str(int(cont.getTriggers())))

        if half_m:
            outbound.write(str(int(cont.getTriggers()) / 2))
        else:
            outbound.write(str(int(cont.getTriggers())))

        outbound.write(" ")

    except:
        print "Crashed while reading controller input"
        pass

    counter = 10
예제 #8
0
                    p_factor = p_factor / 2.0
                    if(p_factor < 0.5):
                        p_factor = 1

    try:
        outbound.write("STR") #  sends a signal to tell that this is the start of data
        outbound.write(chr(buttons1))# writes the buttons first
        outbound.write(chr(buttons2))

        outbound.write(str(int(cont.getPrimaryX() * p_factor)))# casts the floats to ints, then to strings for simple parsing
        outbound.write(" ")
        outbound.write(str(int(cont.getPrimaryY() * p_factor)))
        outbound.write(" ")
        outbound.write(str(int(cont.getSecondaryX() * p_factor)))
        outbound.write(" ")
        outbound.write(str(int(cont.getSecondaryY() * p_factor)))
        outbound.write(" ")
        outbound.write(str(int(cont.getTriggers() * p_factor)))

        outbound.write(" ")

    except serial.serialutil.SerialException:
        no_serial = True

    except:
        print "Crashed while sending controller input"

    got = ''                                                            #shows in red the old data in case of lost connection.
    textwrite(200, 90, (str(pressure) + " mbars"), 255, 10, 10)
    textwrite(200, 110, (str(current) + " amps"), 255, 10, 10)
    textwrite(200, 130, (str(temperature) + " degrees C"), 255, 10, 10)