Example #1
0
 def _read_stream():
     print("Started reading")
     for event in xbox_read.event_stream(deadzone=12000):
         if event.key == 'X2':
             self.base = event
         if event.key == 'X1':
             self.lower = event
         if event.key == 'Y1':
             self.upper = event
         if event.key == 'LT':
             self.jaws = event
             self.jaws.value = -1 * self.jaws.value
         if event.key == 'RT':
             self.jaws = event
Example #2
0
 def _read_stream():
     print("Started reading")
     for event in xbox_read.event_stream(deadzone=12000):
         if event.key == 'X2':
             self.base = event
         if event.key == 'X1':
             self.lower = event
         if event.key == 'Y1':
             self.upper = event
         if event.key == 'LT':
             self.jaws = event
             self.jaws.value = -1 * self.jaws.value
         if event.key == 'RT':
             self.jaws = event
Example #3
0
def right_joystick():
    global thrust, pitch, roll, yaw, handshake, commandString
    for event in xbox_read.event_stream(deadzone=2000, scale=255):
        if event.key == 'RT' or event.key == 'LT':
            thrust = event.value
        elif event.key == 'X1': #left stick
            yaw = event.value
        elif event.key == 'X2':
            roll = event.value
        elif event.key == 'Y2':
            pitch = event.value
        
        if(handshake == 1):
            commandString = formatCommand(CMD_TYPE) #if we can we combine them to send off
Example #4
0
def right_joystick():
    global thrust, pitch, roll, yaw, handshake, commandString
    for event in xbox_read.event_stream(deadzone=2000, scale=255):
        if event.key == 'RT' or event.key == 'LT':
            thrust = event.value
        elif event.key == 'X1':  #left stick
            yaw = event.value
        elif event.key == 'X2':
            roll = event.value
        elif event.key == 'Y2':
            pitch = event.value

        if (handshake == 1):
            commandString = formatCommand(
                CMD_TYPE)  #if we can we combine them to send off
Example #5
0
ser = serial.Serial('/dev/ttyUSB0', 57600)
ser.write('test')

LALOG = 0
RALOG = 0
BOOM = 0
STAB = 0
rate = 331

boolh = True
booll = False
boolg = True
faster = True

for event in xbox_read.event_stream(deadzone=6000):
    #    print(ser.read())
    # Speed and direction
    if event.key == 'Y1':
        ldata = 'L'
        LALOG = event.value
        if LALOG >= 0:
            ldata += '+'
        else:
            ldata += '-'
            LALOG *= -1
        LALOG = int(LALOG / rate)
        ldata += str(LALOG)
        ser.write(ldata + '\n')
        print(ldata)
        #setup gpio
        GPIO.setmode(GPIO.BOARD)

        #create motor control
        motors = motorControl.MotorController()

        #setup xbox controller values
        x1 = 0
        y1 = 0
        #TODO
        #yButton = False
        #bButton = False

        #read xbox controller event stream

        for event in xbox_read.event_stream(deadzone=7000, scale=101):

            #TODO - if the Y button and B button are both pressed, exit
            #it does exit but the program does finish due to xbox_read not exiting!
            #if event.key=='Y': yButton = event.is_press()
            #if event.key=='B': bButton = event.is_press()
            #if yButton and bButton: break

            #analogue stick
            if event.key=='X1':
                x1 = event.value
                #print("X1 - " + str(event.value))
            if event.key=='Y1':
                y1 = event.value
                #print("Y1 - " + str(event.value))
thumbstickMin = -32768
thumbstickMax = 32767

def mapValue(value, leftMin, leftMax, rightMin, rightMax):
    # Taken from http://stackoverflow.com/questions/1969240/mapping-a-range-of-values-to-another
    # Figure out how 'wide' each range is
    leftSpan = leftMax - leftMin
    rightSpan = rightMax - rightMin

    # Convert the left range into a 0-1 range (float)
    valueScaled = float(value - leftMin) / float(leftSpan)

    # Convert the 0-1 range into a value in the right range.
    return rightMin + (valueScaled * rightSpan)

for event in xbox_read.event_stream(deadzone=12000):
    #Left thumbstick up/down controls speed
    if event.key == 'Y1':
        #map the thumbstick's value to the bot's driving speed
        vel = mapValue(event.value, thumbstickMin, thumbstickMax, -250, 250)
        print 'Driving'
        bot.drive_straight(vel)
    
    #Right thumbstick left/right controls rotation
    if event.key == 'X2':
        # Map the thumbstick's value to the bot's rotation
        if event.value > 0:
            # Thumbstick moved right
            print 'Steering Right'
            print event.value
            vel = mapValue(event.value, 0, thumbstickMax, 0, 100)
Example #8
0
        #setup gpio
        GPIO.setmode(GPIO.BOARD)

        #create motor control
        motors = motorControl.MotorController()

        #setup xbox controller values
        x1 = 0
        y1 = 0
        #TODO
        #yButton = False
        #bButton = False

        #read xbox controller event stream

        for event in xbox_read.event_stream(deadzone=7000, scale=101):

            #TODO - if the Y button and B button are both pressed, exit
            #it does exit but the program does finish due to xbox_read not exiting!
            #if event.key=='Y': yButton = event.is_press()
            #if event.key=='B': bButton = event.is_press()
            #if yButton and bButton: break

            #analogue stick
            if event.key == 'X1':
                x1 = event.value
                #print("X1 - " + str(event.value))
            if event.key == 'Y1':
                y1 = event.value
                #print("Y1 - " + str(event.value))
Example #9
0
#!/usr/bin/env python

from grizzly import *
from xbox_read import event_stream

g = Grizzly()
g.set_mode(ControlMode.NO_PID, DriveMode.DRIVE_BRAKE)
g.limit_acceleration(20)
g.limit_current(5)

inputs = event_stream(4000)
for event in inputs:
    if event.key == "Y2":
        throttle = int(event.value) / 328
        g.set_target(throttle)
    if event.key == "A":
        print("Current: " + str(g.read_motor_current()) + "Encoder: " + str(g.read_encoder()))


# Appendix: Keys
# --------------
# Key:                      Range of values:
# X1                        -32768 : 32767
# Y1                        -32768 : 32767
# X2                        -32768 : 32767
# Y2                        -32768 : 32767
# du                        0, 1
# dd                        0, 1
# dl                        0, 1
# dr                        0, 1
# back                      0, 1
Example #10
0
#!/usr/bin/env python

from grizzly import *
from xbox_read import event_stream

g = Grizzly()
g.set_mode(ControlMode.NO_PID, DriveMode.DRIVE_BRAKE)
g.limit_acceleration(20)
g.limit_current(5)

inputs = event_stream(4000)
for event in inputs:
    if event.key == "Y2":
        throttle = int(event.value) / 328
        g.set_target(throttle)
    if event.key == "A":
        print("Current: " + str(g.read_motor_current()) + "Encoder: " +
              str(g.read_encoder()))

# Appendix: Keys
# --------------
# Key:                      Range of values:
# X1                        -32768 : 32767
# Y1                        -32768 : 32767
# X2                        -32768 : 32767
# Y2                        -32768 : 32767
# du                        0, 1
# dd                        0, 1
# dl                        0, 1
# dr                        0, 1
# back                      0, 1
Example #11
0
import xbox_read

stream = xbox_read.event_stream(deadzone=12000)
for event in stream:
	print event