本文使用ps4手柄旨在控制机器人行走,故只获取了手柄的部分信息。
硬件:PS4手柄
环境:win7/10,python3.7,opencv4.0,Pyqt5,pygame,time,math,sys
一、使用pygame库获取手柄信息
主要代码如下:
import pygame
import time
import numpy as np
import math
import sys
class JoyStick(object):
def __init__(self, id):
pygame.init()
pygame.joystick.init()
if pygame.joystick.get_count() == 0:
raise Exception("Joystick not found!")
self.joystick = pygame.joystick.Joystick(id)
self.joystick.init()
self.axis = np.zeros(self.joystick.get_numaxes())
self.__alpha = 0.0
self.button = [self.joystick.get_button(i) for i in range(self.joystick.get_numbuttons())]
self.hat = [self.joystick.get_hat(i) for i in range(self.joystick.get_numhats())]
self.lst_button = [self.joystick.get_button(i) for i in range(self.joystick.get_numbuttons())]
self.lst_hat = [self.joystick.get_hat(i) for i in range(self.joystick.get_numhats())]
self.button_click = self._check_button_click(self.lst_button, self.button)
self.hat_click = self._check_hat_click(self.lst_hat, self.hat)
self.dead_zone = 0.1
@staticmethod
def _check_button_click(lst, cur):
rise = [0] * len(lst)
for i in range(len(lst)):
if not lst[i] and cur[i]:
rise[i] = 1
return rise
@staticmethod
def _check_hat_click(lst, cur):
rise = [(0, 0)] * len(lst)
for i in range(len(lst)):
h0 = 1 if not lst[i][0] and cur[i][0] else 0
h1 = 1 if not lst[i][1] and cur[i][1] else 0
rise[i] = (h0, h1)
return rise
@staticmethod
def count():
pygame.init()
return pygame.joystick.get_count()
@staticmethod
def device_name(id):
if id < JoyStick.count():
return pygame.joystick.Joystick(id).get_name()
else:
return None
def name(self):
return self.joystick.get_name()
def refresh(self):
pygame.event.pump()
for i in range(self.joystick.get_numaxes()):
axis = self.joystick.get_axis(i)
self.axis[i] = self.axis[i] * self.__alpha + axis * (1.0 - self.__alpha)
if -self.dead_zone < self.axis[i] < self.dead_zone:
self.axis[i] = 0
self.lst_button = self.button
self.lst_hat = self.hat
self.button = [self.joystick.get_button(i) for i in range(self.joystick.get_numbuttons())]
self.hat = [self.joystick.get_hat(i) for i in range(self.joystick.get_numhats())]
self.button_click = self._check_button_click(self.lst_button, self.button)
self.hat_click = self._check_hat_click(self.lst_hat, self.hat)
class PS4Robot(object):
def __init__(self, id=0):
self.ps4 = JoyStick(id)
if self.ps4.name().find("PS4") < 0:
raise Exception("No a PS4 handle")
self.dx = 0.0
self.dy = 0.0
self.step = 0.0
self.yaw = 0.0
self.speed = 0.0
def refresh(self):
self.ps4.refresh()
x = self.ps4.axis[2]
y = -self.ps4.axis[3]
xy = math.sqrt(x * x + y * y)
if xy < 0.1:
self.dx = 0.0
self.dy = 0.0
self.step = 0.0
else:
self.dx = x / xy
self.dy = y / xy
self.step = max(math.fabs(x), math.fabs(y))
self.yaw = self.ps4.axis[0]
if self.ps4.button_click[3]:
self.speed += 0.1
elif self.ps4.button_click[0]:
self.speed -= 0.1
self.speed = min(1.0, max(0.0, self.speed))
msg_list=[]
msg_list.append(self.dx)
msg_list.append(self.dy)
msg_list.append(self.step)
msg_list.append(self.yaw)
msg_list.append(self.speed)
return msg_list
# print("Yaw = %3.1f" % self.yaw)
# print("Speed = %3.1f" % self.speed)
二、QT界面绘制以及程序生成
使用QT Designer绘制好界面,然后保存为.ui文件,最后将.ui生成.py文件导入程序中即可使用。
QT Designer软件界面如下:
使用命令行pyuic5 -o login.py login.ui转换成.py文件。调用格式为pyuic5 -o {输出文件名} {输入designer设计好的.ui后缀界面文件}。
三、完整展示
分为两部分程序,主程序以及qt界面程序:
ps4_contrlo.py程序为主程序,login.py为界面程序,放入一个目录下,运行ps4_control.py即可运行(安装好所需库)
- ps4_control
import pygame
import time
import numpy as np
import math
import sys
#导入designer工具生成的login模块
from login import Ui_Form
from PyQt5 import QtCore, QtGui, QtWidgets
#PyQt5中使用的基本控件都在PyQt5.QtWidgets模块中
from PyQt5.QtWidgets import *
class JoyStick(object):
def __init__(self, id):
pygame.init()
pygame.joystick.init()
if pygame.joystick.get_count() == 0:
raise Exception("Joystick not found!")
self.joystick = pygame.joystick.Joystick(id)
self.joystick.init()
self.axis = np.zeros(self.joystick.get_numaxes())
self.__alpha = 0.0
self.button = [self.joystick.get_button(i) for i in range(self.joystick.get_numbuttons())]
self.hat = [self.joystick.get_hat(i) for i in range(self.joystick.get_numhats())]
self.lst_button = [self.joystick.get_button(i) for i in range(self.joystick.get_numbuttons())]
self.lst_hat = [self.joystick.get_hat(i) for i in range(self.joystick.get_numhats())]
self.button_click = self._check_button_click(self.lst_button, self.button)
self.hat_click = self._check_hat_click(self.lst_hat, self.hat)
self.dead_zone = 0.1
@staticmethod
def _check_button_click(lst, cur):
rise = [0] * len(lst)
for i in range(len(lst)):
if not lst[i] and cur[i]:
rise[i] = 1
return rise
@staticmethod
def _check_hat_click(lst, cur):
rise = [(0, 0)] * len(lst)
for i in range(len(lst)):
h0 = 1 if not lst[i][0] and cur[i][0] else 0
h1 = 1 if not lst[i][1] and cur[i][1] else 0
rise[i] = (h0, h1)
return rise
@staticmethod
def count():
pygame.init()
return pygame.joystick.get_count()
@staticmethod
def device_name(id):
if id < JoyStick.count():
return pygame.joystick.Joystick(id).get_name()
else:
return None
def name(self):
return self.joystick.get_name()
def refresh(self):
pygame.event.pump()
for i in range(self.joystick.get_numaxes()):
axis = self.joystick.get_axis(i)
self.axis[i] = self.axis[i] * self.__alpha + axis * (1.0 - self.__alpha)
if -self.dead_zone < self.axis[i] < self.dead_zone:
self.axis[i] = 0
self.lst_button = self.button
self.lst_hat = self.hat
self.button = [self.joystick.get_button(i) for i in range(self.joystick.get_numbuttons())]
self.hat = [self.joystick.get_hat(i) for i in range(self.joystick.get_numhats())]
self.button_click = self._check_button_click(self.lst_button, self.button)
self.hat_click = self._check_hat_click(self.lst_hat, self.hat)
class PS4Robot(object):
def __init__(self, id=0):
self.ps4 = JoyStick(id)
if self.ps4.name().find("PS4") < 0:
raise Exception("No a PS4 handle")
self.dx = 0.0
self.dy = 0.0
self.step = 0.0
self.yaw = 0.0
self.speed = 0.0
def refresh(self):
self.ps4.refresh()
x = self.ps4.axis[2]
y = -self.ps4.axis[3]
xy = math.sqrt(x * x + y * y)
if xy < 0.1:
self.dx = 0.0
self.dy = 0.0
self.step = 0.0
else:
self.dx = x / xy
self.dy = y / xy
self.step = max(math.fabs(x), math.fabs(y))
self.yaw = self.ps4.axis[0]
if self.ps4.button_click[3]:
self.speed += 0.1
elif self.ps4.button_click[0]:
self.speed -= 0.1
self.speed = min(1.0, max(0.0, self.speed))
msg_list=[]
msg_list.append(self.dx)
msg_list.append(self.dy)
msg_list.append(self.step)
msg_list.append(self.yaw)
msg_list.append(self.speed)
return msg_list
# print("Yaw = %3.1f" % self.yaw)
# print("Speed = %3.1f" % self.speed)
class MyMainForm(QMainWindow, Ui_Form):
def __init__(self, robot,parent=None):
super(MyMainForm, self).__init__(parent)
self.setupUi(self)
self.robot=robot
self.pushButton_2.clicked.connect(self.close)
self.timer=QtCore.QTimer()
self.timer.timeout.connect(self.display)
self.timer.start(100)
def display(self):
msg=self.robot.refresh()
self.line_2.setGeometry(QtCore.QRect(130+self.robot.yaw*80, 30, 20, 31))
temp=80
self.line_3.setGeometry(QtCore.QRect(125+self.robot.dx*temp, 202-self.robot.dy*temp, 50, 20))
self.line_4.setGeometry(QtCore.QRect(140+self.robot.dx*temp, 187-self.robot.dy*temp, 20, 50))
self.line_10.setGeometry(QtCore.QRect(299, 300-self.robot.step*200, 20, 20+self.robot.step*200))
# 利用text Browser控件对象setText()函数设置界面显示
self.progressBar.setProperty("value",self.robot.speed*100)
self.textBrowser.setText( "x: " + str(self.robot.dx) + "\n"+"y: "+str(self.robot.dy)+"\n"+"step: " + str(self.robot.step) +"\n"+ "yaw: " + str(self.robot.yaw)+"\n"+"speed: " + str(self.robot.speed))
if __name__ == '__main__':
# 初始化
robot = PS4Robot()
print(robot.ps4.name())
app = QApplication(sys.argv)
myWin = MyMainForm(robot)
#将窗口控件显示在屏幕上
myWin.show()
#程序运行,sys.exit方法确保程序完整退出。
myWin.display()
time.sleep(0.1)
sys.exit(app.exec_())
```、
2. login.py(将login.ui文件生成的.py文件),将login.py文件放置程序当前目录可直接使用
```python
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'login.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(639, 414)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(85, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(85, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(85, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(85, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
Form.setPalette(palette)
self.label = QtWidgets.QLabel(Form)
self.label.setGeometry(QtCore.QRect(120, 380, 101, 31))
font = QtGui.QFont()
font.setPointSize(15)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.pushButton_2 = QtWidgets.QPushButton(Form)
self.pushButton_2.setGeometry(QtCore.QRect(440, 360, 111, 31))
self.pushButton_2.setObjectName("pushButton_2")
self.progressBar = QtWidgets.QProgressBar(Form)
self.progressBar.setGeometry(QtCore.QRect(50, 360, 221, 23))
self.progressBar.setMaximum(100)
self.progressBar.setProperty("value", 0)
self.progressBar.setObjectName("progressBar")
self.label_2 = QtWidgets.QLabel(Form)
self.label_2.setGeometry(QtCore.QRect(120, 60, 71, 20))
self.label_2.setBaseSize(QtCore.QSize(0, 0))
font = QtGui.QFont()
font.setPointSize(15)
font.setBold(True)
font.setWeight(75)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.textBrowser = QtWidgets.QTextBrowser(Form)
self.textBrowser.setGeometry(QtCore.QRect(350, 90, 261, 251))
font = QtGui.QFont()
font.setPointSize(15)
self.textBrowser.setFont(font)
self.textBrowser.setFrameShadow(QtWidgets.QFrame.Plain)
self.textBrowser.setLineWidth(5)
self.textBrowser.setObjectName("textBrowser")
self.line = QtWidgets.QFrame(Form)
self.line.setGeometry(QtCore.QRect(60, 40, 160, 20))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.line.setPalette(palette)
self.line.setFrameShadow(QtWidgets.QFrame.Plain)
self.line.setLineWidth(9)
self.line.setMidLineWidth(6)
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setObjectName("line")
self.line_2 = QtWidgets.QFrame(Form)
self.line_2.setGeometry(QtCore.QRect(130, 30, 20, 31))
self.line_2.setFrameShadow(QtWidgets.QFrame.Raised)
self.line_2.setLineWidth(19)
self.line_2.setMidLineWidth(4)
self.line_2.setFrameShape(QtWidgets.QFrame.VLine)
self.line_2.setObjectName("line_2")
self.label_4 = QtWidgets.QLabel(Form)
self.label_4.setGeometry(QtCore.QRect(400, 60, 141, 20))
self.label_4.setBaseSize(QtCore.QSize(0, 0))
font = QtGui.QFont()
font.setPointSize(15)
font.setBold(True)
font.setWeight(75)
self.label_4.setFont(font)
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(Form)
self.label_5.setGeometry(QtCore.QRect(144, 320, 21, 20))
self.label_5.setBaseSize(QtCore.QSize(0, 0))
font = QtGui.QFont()
font.setPointSize(15)
font.setBold(True)
font.setWeight(75)
self.label_5.setFont(font)
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(Form)
self.label_6.setGeometry(QtCore.QRect(20, 204, 21, 20))
self.label_6.setBaseSize(QtCore.QSize(0, 0))
font = QtGui.QFont()
font.setPointSize(15)
font.setBold(True)
font.setWeight(75)
self.label_6.setFont(font)
self.label_6.setObjectName("label_6")
self.line_3 = QtWidgets.QFrame(Form)
self.line_3.setGeometry(QtCore.QRect(125, 202, 50, 20))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.line_3.setPalette(palette)
self.line_3.setFrameShadow(QtWidgets.QFrame.Plain)
self.line_3.setLineWidth(10)
self.line_3.setMidLineWidth(10)
self.line_3.setFrameShape(QtWidgets.QFrame.HLine)
self.line_3.setObjectName("line_3")
self.line_4 = QtWidgets.QFrame(Form)
self.line_4.setGeometry(QtCore.QRect(140, 187, 20, 50))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.line_4.setPalette(palette)
self.line_4.setFrameShadow(QtWidgets.QFrame.Plain)
self.line_4.setLineWidth(10)
self.line_4.setMidLineWidth(10)
self.line_4.setFrameShape(QtWidgets.QFrame.VLine)
self.line_4.setObjectName("line_4")
self.line_5 = QtWidgets.QFrame(Form)
self.line_5.setGeometry(QtCore.QRect(30, 100, 20, 220))
self.line_5.setFrameShadow(QtWidgets.QFrame.Plain)
self.line_5.setLineWidth(5)
self.line_5.setFrameShape(QtWidgets.QFrame.VLine)
self.line_5.setObjectName("line_5")
self.line_6 = QtWidgets.QFrame(Form)
self.line_6.setGeometry(QtCore.QRect(250, 100, 20, 220))
self.line_6.setFrameShadow(QtWidgets.QFrame.Plain)
self.line_6.setLineWidth(5)
self.line_6.setFrameShape(QtWidgets.QFrame.VLine)
self.line_6.setObjectName("line_6")
self.line_7 = QtWidgets.QFrame(Form)
self.line_7.setGeometry(QtCore.QRect(38, 92, 224, 16))
self.line_7.setFrameShadow(QtWidgets.QFrame.Plain)
self.line_7.setLineWidth(5)
self.line_7.setFrameShape(QtWidgets.QFrame.HLine)
self.line_7.setObjectName("line_7")
self.line_8 = QtWidgets.QFrame(Form)
self.line_8.setGeometry(QtCore.QRect(40, 310, 220, 16))
self.line_8.setFrameShadow(QtWidgets.QFrame.Plain)
self.line_8.setLineWidth(5)
self.line_8.setFrameShape(QtWidgets.QFrame.HLine)
self.line_8.setObjectName("line_8")
self.label_7 = QtWidgets.QLabel(Form)
self.label_7.setGeometry(QtCore.QRect(20, 110, 21, 20))
self.label_7.setBaseSize(QtCore.QSize(0, 0))
font = QtGui.QFont()
font.setPointSize(15)
font.setBold(True)
font.setWeight(75)
self.label_7.setFont(font)
self.label_7.setObjectName("label_7")
self.label_8 = QtWidgets.QLabel(Form)
self.label_8.setGeometry(QtCore.QRect(10, 290, 21, 20))
self.label_8.setBaseSize(QtCore.QSize(0, 0))
font = QtGui.QFont()
font.setPointSize(15)
font.setBold(True)
font.setWeight(75)
self.label_8.setFont(font)
self.label_8.setObjectName("label_8")
self.label_9 = QtWidgets.QLabel(Form)
self.label_9.setGeometry(QtCore.QRect(240, 320, 21, 20))
self.label_9.setBaseSize(QtCore.QSize(0, 0))
font = QtGui.QFont()
font.setPointSize(15)
font.setBold(True)
font.setWeight(75)
self.label_9.setFont(font)
self.label_9.setObjectName("label_9")
self.label_10 = QtWidgets.QLabel(Form)
self.label_10.setGeometry(QtCore.QRect(40, 320, 21, 20))
self.label_10.setBaseSize(QtCore.QSize(0, 0))
font = QtGui.QFont()
font.setPointSize(15)
font.setBold(True)
font.setWeight(75)
self.label_10.setFont(font)
self.label_10.setObjectName("label_10")
self.line_9 = QtWidgets.QFrame(Form)
self.line_9.setGeometry(QtCore.QRect(300, 300, 21, 21))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.line_9.setPalette(palette)
font = QtGui.QFont()
font.setPointSize(12)
self.line_9.setFont(font)
self.line_9.setFrameShadow(QtWidgets.QFrame.Raised)
self.line_9.setLineWidth(10)
self.line_9.setMidLineWidth(3)
self.line_9.setFrameShape(QtWidgets.QFrame.VLine)
self.line_9.setObjectName("line_9")
self.label_11 = QtWidgets.QLabel(Form)
self.label_11.setGeometry(QtCore.QRect(290, 330, 51, 20))
self.label_11.setBaseSize(QtCore.QSize(0, 0))
font = QtGui.QFont()
font.setPointSize(15)
font.setBold(True)
font.setWeight(75)
self.label_11.setFont(font)
self.label_11.setObjectName("label_11")
self.line_10 = QtWidgets.QFrame(Form)
self.line_10.setGeometry(QtCore.QRect(299, 300, 20, 20))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(0, 255, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 255, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.line_10.setPalette(palette)
self.line_10.setFrameShadow(QtWidgets.QFrame.Plain)
self.line_10.setLineWidth(15)
self.line_10.setMidLineWidth(3)
self.line_10.setFrameShape(QtWidgets.QFrame.VLine)
self.line_10.setObjectName("line_10")
self.line_11 = QtWidgets.QFrame(Form)
self.line_11.setGeometry(QtCore.QRect(302, 90, 16, 10))
self.line_11.setFrameShadow(QtWidgets.QFrame.Raised)
self.line_11.setLineWidth(10)
self.line_11.setMidLineWidth(3)
self.line_11.setFrameShape(QtWidgets.QFrame.VLine)
self.line_11.setObjectName("line_11")
self.line_12 = QtWidgets.QFrame(Form)
self.line_12.setGeometry(QtCore.QRect(293, 100, 20, 201))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(0, 255, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 255, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.line_12.setPalette(palette)
self.line_12.setFrameShadow(QtWidgets.QFrame.Plain)
self.line_12.setLineWidth(3)
self.line_12.setFrameShape(QtWidgets.QFrame.VLine)
self.line_12.setObjectName("line_12")
self.line_13 = QtWidgets.QFrame(Form)
self.line_13.setGeometry(QtCore.QRect(306, 100, 20, 201))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(0, 255, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 255, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.line_13.setPalette(palette)
self.line_13.setFrameShadow(QtWidgets.QFrame.Plain)
self.line_13.setLineWidth(3)
self.line_13.setFrameShape(QtWidgets.QFrame.VLine)
self.line_13.setObjectName("line_13")
self.line_10.raise_()
self.label.raise_()
self.pushButton_2.raise_()
self.progressBar.raise_()
self.label_2.raise_()
self.textBrowser.raise_()
self.line.raise_()
self.line_2.raise_()
self.label_4.raise_()
self.label_5.raise_()
self.label_6.raise_()
self.line_3.raise_()
self.line_4.raise_()
self.line_5.raise_()
self.line_6.raise_()
self.line_7.raise_()
self.line_8.raise_()
self.label_7.raise_()
self.label_8.raise_()
self.label_9.raise_()
self.label_10.raise_()
self.label_11.raise_()
self.line_11.raise_()
self.line_12.raise_()
self.line_13.raise_()
self.line_9.raise_()
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.label.setText(_translate("Form", "speed"))
self.pushButton_2.setText(_translate("Form", "退出"))
self.label_2.setText(_translate("Form", "yaw"))
self.label_4.setText(_translate("Form", "data display"))
self.label_5.setText(_translate("Form", "x"))
self.label_6.setText(_translate("Form", "y"))
self.label_7.setText(_translate("Form", "1"))
self.label_8.setText(_translate("Form", "-1"))
self.label_9.setText(_translate("Form", "1"))
self.label_10.setText(_translate("Form", "-1"))
self.label_11.setText(_translate("Form", "step"))
运行界面展示
程序中需要手柄提供控制方向x,y,yaw(偏航角)以及机器人速度speed和步长step。文章来源:https://www.toymoban.com/news/detail-418825.html
文章来源地址https://www.toymoban.com/news/detail-418825.html
到了这里,关于python获取ps4手柄信息并使用QT界面显示读取内容的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!