Esempio n. 1
0
 def __init__(self, joystickNumber=0):
     Gamepad.__init__(self, joystickNumber)
     self.axisNames = {
         0: 'LEFT-X',
         1: 'LEFT-Y',
         2: 'LT',
         3: 'RIGHT-X',
         4: 'RIGHT-Y',
         5: 'RT',
         6: 'D-PAD L.R.',
         7: 'D-PAD U.D.'
     }
     self.buttonNames = {
         0: 'A',
         1: 'B',
         2: 'X',
         3: 'Y',
         4: 'LB',
         5: 'RB',
         6: 'BACK',
         7: 'START',
         8: 'XBOX',
         9: 'LA',
         10: 'RA'
     }
     self._setupReverseMaps()
Esempio n. 2
0
def start():
    #setting up our gamepad interface
    gamepad = Gamepad.Gamepad()

    #establishing a TCP connection to the server
    driver = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    driver.connect(__env.HOST)

    #Checking if the server threw an error and disconects if thats the case
    connect_msg = driver.recv(__env.MAX_MESSAGE_SIZE).decode(__env.FORMAT)

    print(connect_msg)

    if connect_msg in __env.ERROR_MESSAGES:
        return

    #starting the server messages thread.
    thread = threading.Thread(target=handle_server_messages, args=[driver])
    thread.start()

    print("driver connected at ", __env.HOST)

    #To prevent spamming the server and causing undefined behavior, we are only sending the input message when the actual input state changes,
    #with a delay of 10ms between messages.
    #However, since we are using UDP to communicate with the robot, there is a slight chance of packet loss
    #To prevent that, the client will resend the message if a second has passed since it last sent one
    last_transmission_message = ""
    last_time = time.time() - 20

    while True:
        time.sleep(0.01)
        gamepad.update_inputs()
        message = gamepad.get_transmission_message() + "|"
        #'|' separator between packets
        if message != last_transmission_message or (time.time() - last_time >=
                                                    1):
            last_transmission_message = message
            last_time = time.time()
            driver.send(message.encode(__env.FORMAT))
Esempio n. 3
0
# Load the gamepad and time libraries
import Gamepad
import time

# Gamepad settings
gamepadType = Gamepad.PS4
buttonHappy = 'CROSS'
buttonBeep = 'CIRCLE'
buttonExit = 'PS'
joystickSpeed = 'LEFT-Y'
joystickSteering = 'RIGHT-X'
pollInterval = 0.2

# Wait for a connection
if not Gamepad.available():
    print('Please connect your gamepad...')
    while not Gamepad.available():
        time.sleep(1.0)
gamepad = gamepadType()
print('Gamepad connected')

# Set some initial state
global running
global beepOn
global speed
global steering
running = True
beepOn = False
speed = 0.0
steering = 0.0
Esempio n. 4
0
from Bluetooth import *
from Gamepad import *
from Keyboard import *
ch = 0
while ch == 0:
    print 'press 1 to emulate keyboard'
    print 'press 2 to emulate gamepad'
    ch = raw_input("Press any key from menu: ")
    if ch == '1':
        bt = Bluetooth("sdp_record_kbd.xml", "000540", "BT\ Keyboard")
        bt.listen()
        kb = Keyboard()
        kb.event_loop(bt)
    elif ch == '2':
        bt = Bluetooth("sdp_record_gamepad.xml", "000508", "BT\ Gamepad")
        bt.listen()
        gp = Gamepad()
        gp.event_loop(bt)
    else:
        ch = 0
        print('Please select from menu')
Esempio n. 5
0
        leftX = 0
        leftY = 0
        rightX = 0
        leftBumper = 0
        rightBumper = 0
        dpadLeft = 0
        dpadRight = 0
        dpadUp = 0
        dpadDown = 0
        aButton = 0
        bButton = 0
        xButton = 0
        yButton = 0

        gamepad = Gamepad.Xbox360()
        print('Gamepad connected')

        gamepad.startBackgroundUpdates()

        while True:
            leftX = gamepad.axis("LEFT-X")
            leftY = gamepad.axis("LEFT-Y")
            rightX = gamepad.axis("RIGHT-X")
            leftBumper = gamepad.isPressed("LB")
            rightBumper = gamepad.isPressed("RB")
            aButton = gamepad.isPressed("A")
            bButton = gamepad.isPressed("B")
            xButton = gamepad.isPressed("X")
            yButton = gamepad.isPressed("Y")
            packet = "z%0.2f;%0.2f;%0.2f;%d;%d;%d;%d;%d;%d" % (
Esempio n. 6
0
from Bluetooth import *
from Gamepad import *
from Keyboard import *
ch = 0
while ch==0:
    print 'press 1 to emulate keyboard'
    print 'press 2 to emulate gamepad'
    ch = raw_input("Press any key from menu: ")
    if ch == '1':
        bt = Bluetooth("sdp_record_kbd.xml","000540","BT\ Keyboard")
        bt.listen()
        kb = Keyboard()
        kb.event_loop(bt)
    elif ch=='2':
        bt = Bluetooth("sdp_record_gamepad.xml","000508", "BT\ Gamepad")
        bt.listen()
        gp = Gamepad()
        gp.event_loop(bt)
    else:
        ch = 0
        print('Please select from menu')
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jun  8 22:36:05 2020

@author: desconcordia
"""
from pathlib import Path
from psychopy import visual, core
import Gamepad
import csv

if Gamepad.available():
    gamepad = Gamepad.Precision()
else:
    print('Controller not connected')

path_parent = '/home/desconcordia/Documents/Psychopy_Psc290_Project/data'  #had to hardcode bc running in anaconda env
path = Path(path_parent)
data_log = 'Inputs_log.csv'
fpath = (path / data_log).with_suffix('.csv')

num_trials = 8
button_press = []

win = visual.Window([400, 400], color='black', colorSpace='rgb')

screen_text = visual.TextStim(win,
                              text=None,
                              alignHoriz="center",
                              color='white')
Esempio n. 8
0
'''---------------------------------

    Code Setup

---------------------------------'''

import sys
from PCA9685 import PCA9685
import Gamepad
import time

pwm = PCA9685(0x40)
pwm.setPWMFreq(50)

if Gamepad.available():
    gamepad = Gamepad.smx()
else:
    print("Controller not connected")

gamepad.startBackgroundUpdates()
'''---------------------------------

    Define Variables

---------------------------------'''

center = 1500
shooterRange = 1000
shooterMin = 1000

centerAdj = 80  #Adjust center of pwm range for drive
Esempio n. 9
0
import Gamepad as gp

print("Do it")
myGamepad = gp.Gamepad()
myGamepad.getControlSignals()
print("Before del")
del myGamepad
print("After del")

Esempio n. 10
0
from Bluetooth import *
from Gamepad import *
import gtk
from dbus.mainloop.glib import DBusGMainLoop

DBusGMainLoop(set_as_default=True)

bt = Bluetooth("sdp_record_gamepad.xml", "000508", "BT\ Gamepad")
bt.listen()
gp = Gamepad()
gp.register_keyboard_gobject_events(bt)
gtk.main()
Esempio n. 11
0
import Gamepad as gp

print("Do it")
myGamepad = gp.Gamepad("tcp://127.0.0.1:5555")
myGamepad.getControlSignals()
print("Before del")
del myGamepad
print("After del")

Esempio n. 12
0
#!/usr/bin/env python
# coding: utf-8

# Load the gamepad and time libraries
import Gamepad
import time

# Wait for a connection
if not Gamepad.available():
    print('Please connect your gamepad...')
    while not Gamepad.available():
        time.sleep(1.0)
print('Gamepad connected')

# Pick the gamepad type
#gamepad = Gamepad.Gamepad()   #Generic unnamed controls
#gamepad = Gamepad.PS3()
gamepad = Gamepad.PS4()

# Show the selected gamepad type
print('Gamepad type: ' + gamepad.__class__.__name__)

# Display axis names
axisNames = gamepad.availableAxisNames()
if axisNames:
    print('Available axis names:')
    for axis in axisNames:
        print('   ' + str(axis))
else:
    print('No axis name mappings configured')
print('')
Esempio n. 13
0
def removetasks(loop: object) -> object:
    tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()]

    for task in tasks:
        # skipping over shielded coro still does not help
        if task._coro.__name__ == "cant_stop_me":
            continue
        task.cancel()

    print("Cancelling outstanding tasks")
    #    await asyncio.gather(*tasks, return_exceptions=True)
    loop.stop()


async def shutdown_signal(signal, loop):
    print("Received exit signal {signal.name}...")
    await removetasks(loop)


available()
connect()
sleep(0.5)

Gamepad()
loop = asyncio.get_event_loop()
loop.run_until_complete(is_connected())
asyncio.run(read_gamepad_inputs())
loop.close()
#