예제 #1
0
def main(argv=None):
    options = parse_arguments(argv)

    controller = PS4Controller()
    controller.init()

    while True:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect((options.ip, 9999))
        axis_data = controller.listen()
        raw_steering = axis_data[0]
        raw_throttle = axis_data[4]
        converted_steering = str(convert_steering(raw_steering))
        converted_throttle, direction = convert_throttle(raw_throttle)
        converted_throttle = str(converted_throttle)
        if direction > 0:
            throttle_dir = 'f'
        else:
            throttle_dir = 'r'
        while len(converted_steering) < 3:
            converted_steering += ' '
        while len(converted_throttle) < 3:
            converted_throttle += ' '
        print(
            f'raw steering={raw_steering}, converted steering={converted_steering}'
        )  # noqa: E501
        print(
            f'raw throttle={raw_throttle}, converted throttle={throttle_dir}{converted_throttle}'
        )  # noqa: E501
        sock.send(
            f's {converted_steering} {throttle_dir} {converted_throttle}'.
            encode())
        sleep(0.05)
예제 #2
0
    def _parse_ps4(self):
        from controller import PS4Controller

        #It is not necessary to start a new thread for this
        #But since the controller is overhead anyway, it is elegant enough
        ps4 = PS4Controller()
        self.ps4_queue = queue.Queue()
        ps4.init(self.ps4_queue)
        self.controller_thread = Thread(target=ps4.listen)
        self.controller_thread.start()
        print("Crazyflie is ready for commands.")
        button = "Init"
        command = "Init"
        while command != "done":
            if not self.ps4_queue.empty():
                button = self.ps4_queue.get()
                if button == "select":
                    command = "done"
                elif button == "start" and self._takenOff == False:
                    command = "takeoff"
                elif button == "start" and self._takenOff == True:
                    command = "land"
                elif button == "square":
                    command = "square"
                elif button == "triangle":
                    command = "triangle"
                self._interpret_command(command)
        self.controller_thread.join()
예제 #3
0
    def __init__(self, image_path, log_path):
        self.base_image_path = image_path
        self.log_path = log_path
        self.state = {'steering': 90, 'throttle': 0}
        QtWidgets.QDialog.__init__(self)
        Ui_Running_screen.__init__(self)
        self.image_counter = 0
        self.setupUi(self)
        self.controller = PS4Controller()
        self.controller.init()

        if not connection_ok():
            raise RuntimeError('Shit hit the fan yo')
import sys
from board import SCL, SDA
import busio
from adafruit_pca9685 import PCA9685
from adafruit_motor import servo
from adafruit_motor import motor
from controller import PS4Controller
#import camera

#init controller
ps4 = PS4Controller()

#init i2c
i2c = busio.I2C(SCL, SDA)

#init PCA
pca = PCA9685(i2c)
pca.frequency = 50

servo_steer = servo.Servo(pca.channels[0])
esc = servo.ContinuousServo(pca.channels[1])


def scale_servo(x):
    y = round((30 - 70) * x + 1 / 1 + 1 + 70, 2)  #used to scale -1,1 to 0,180
    return y


def scale_esc(x):
    y = round((x + 1) / 8, 2)  #used to scale -1,1 to 0,180
    return y
예제 #5
0
 def __init__(self):
     self.controller = PS4Controller()
     self.controller.init()
예제 #6
0
import airsim
import time
import numpy as np
from PIL import Image
from controller import PS4Controller

MAX_SPEED = 1
MAX_THETA = 1

if __name__ == '__main__':
    client = airsim.CarClient()
    client.confirmConnection()
    client.enableApiControl(True)
    car_controls = airsim.CarControls()

    controller = PS4Controller()
    controller.start()
    """PS4 Controller's axes map

                 Axis 1                  Axis 4

                  -1                      -1
                   ^                       ^
                   |                       |
    Axis 0  -1 <---0---> 1   Axis 3 -1 <---0---> 1
                   |                       |
                   v                       v
                   1                       1
    """

    while True: