예제 #1
0
import pygame
import json
from udp import udp
from event import KeyboardControlState
from config import Settings

settings = Settings('settings.ini')

left_key = settings.getParser().getint('default', 'keyboard_left')
right_key = settings.getParser().getint('default', 'keyboard_right')
up_key = settings.getParser().getint('default', 'keyboard_up')
down_key = settings.getParser().getint('default', 'keyboard_down')

keyboardControlState = KeyboardControlState()


def init_keyboard():
    pygame.key.set_repeat(1, 1)


def determine_key():
    keys = pygame.key.get_pressed()

    if keys[left_key]:
        keyboardControlState.update_steering(-10)
        keyboardControlState.new_steering_event = True
    if keys[right_key]:
        keyboardControlState.update_steering(10)
        keyboardControlState.new_steering_event = True

    if keys[down_key]:
예제 #2
0
import pygame
import pygame.locals
import sys
import cv2
from udp import udp
from config import Settings
from controller import keyboard
from event import KeyboardControlState

settings = Settings('settings.ini')
keyboardControlState = KeyboardControlState()

udp_client_enabled = settings.getParser().getboolean('default',
                                                     'udp_client_enabled')
video_enabled = settings.getParser().getboolean('default',
                                                'video_streaming_enabled')
width_height = (settings.getParser().getint('default', 'window_width'),
                settings.getParser().getint('default', 'window_height'))
video_stream_url = (settings.getParser().get('default', 'video_stream_url'))

if video_enabled:
    stream = cv2.VideoCapture(video_stream_url)


def init():
    pygame.init()
    keyboard.init_keyboard()
    return create_window()


def create_window():
예제 #3
0
import socket
from config import Settings

settings = Settings('settings.ini')
udp_client_enabled = settings.getParser().getboolean('default',
                                                     'udp_client_enabled')
udp_host = settings.getParser().get('default', 'udp_host')
udp_port = settings.getParser().getint('default', 'udp_port')

host_and_port = (udp_host, udp_port)
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)


def send(command):
    if udp_client_enabled:
        client.sendto(bytes(command, 'utf8'), host_and_port)
    print(f'Sending UDP message to {host_and_port}: {command}')