• 基于PyQt5和PSoC6的多功能平衡车设计


    目录
    1故事的开始 1
    1.1设计背景与灵感来源 1
    1.2基本分工设计与器材准备 1
    2硬件设计与硬件驱动编写测试 2
    2.1硬件结构设计 2
    2.2硬件通路设计 3
    2.3硬件底层驱动设计与编写 4
    2.3.1PWM 控制驱动编写 4
    2.3.2编码器驱动编写与中断例程探索 5
    2.3.3加速度传感器驱动编写 7
    2.3.4各个驱动的配合调试 7
    3平衡算法以及平衡参数的调试设置 8
    3.1PID 平衡算法 8
    3.2平衡算法参数的选择 8
    3.3精益求精的调整 10
    4控制调试设置 11
    5主机端控制程序的编写 12
    5.1视频流的传输 13
    5.2小车通信配合 13
    5.3多线程工作 14
    5.4键盘事件与退出事件——改写原函数 15
    5.5UI 设计与部分结构调整 16
    6实验结果 16
    7问题集锦与实验总结反思 17
    7.1问题集锦 17
    7.2实验总结 18
    7.3实验反思 19
    8 总结 19
    5主机端控制程序的编写
    尽管最核心的功能已经大致实现了,但作为一个有实用价值的电子系统,一个集成化的主机端控制程序也是必不可少的,毕竟我们不能一直在 TCP 调试软件中输入命令。与此同时,语音识别功能和视频传输扫描二维码的功能也决定了我们必须在主机端实现一个集合所有功能的全套应用程序。

    经过一定的商量,我们决定让XXX同学研究二维码识别部分,让XXX同学研究语音识别的部分,我来进行包括控制端、视频流和各种功能整合的功能集成程序设计。

    与去年小学期里制作的 UI 不同,本次的主机端控制程序涉及到了几个较为新的东西,包括基于 TCP 协议的通信、视频流的实时显示以及语音输入等,加上XXX和XXX提供的功能模块均使用 python 编写,因此思考过后我决定尝试基于 PyQt5 来完成控制程序的编写。

    5.1视频流的传输
    在最开始,我们对于摄像头的构想是能够直接连在 PSoC6 上,而后通过数据线以及例如 SPI 协议等手段发送给PSoC,再由高速 WiFi 模块传输至电脑端。但是,PSoC6 上有限的资源不允许我们进行这样的操作,并且基于对本次课程的时间考虑,我们没有那么充分的时间进行关于视频流过于深入的学习,因此权衡之后我们考虑直接采用无线摄像头进行传输。

    XXX同学购买的无线摄像头自带电池且在电脑端有适配软件,只需要最开始让无线摄像头接入网络,即可在适配软件端观看实时视频。那么下一步就是如何让视频能够正常地显示在我写的应用程序上。在我和XXX探讨后决定使用虚拟摄像头 OBS 软件,其功能是可以创建一个虚拟摄像头,本文转载自http://www.biyezuopin.vip/onews.asp?id=14699让电脑认为除了本地摄像头外还有另外一个摄像头存在。

    在有了这个软件后,我希望能够将视频放入某个方形方框内。在PyQt5 中, 我使用了QLable 进行视频存放,方法是通过 opencv 中的 cv2.VideoCapture 对象来首先捕捉到摄像头拍摄的画面,而后对于每一帧而言将其作为图片在 QLable 中进行显示,这样可以充分对接二维码识别部分的程序,即希望对于每一帧的图片进行二维码的识别判断。因此最终,二维码识别程序成为了我将视频从虚拟摄像头读取至我自己的程序的一部分,做到了较为完美的融合。

    # -*- coding: utf-8 -*-
    
    # Form implementation generated from reading ui file 'mainwid.ui'
    #
    # Created by: PyQt5 UI code generator 5.15.0
    #
    # WARNING: Any manual changes made to this file will be lost when pyuic5 is
    # run again.  Do not edit this file unless you know what you are doing.
    
    
    from PyQt5 import QtCore, QtGui, QtWidgets
    
    
    class Ui_MainWindow(object):
        def setupUi(self, MainWindow):
            MainWindow.setObjectName("MainWindow")
            MainWindow.resize(1002, 802)
            MainWindow.setMinimumSize(QtCore.QSize(1002, 802))
            MainWindow.setMaximumSize(QtCore.QSize(1002, 802))
            MainWindow.setWindowFlag(QtCore.Qt.FramelessWindowHint)
            #MainWindow.setWindowOpacity(0.9)  # 设置窗口透明度
            MainWindow.setAttribute(QtCore.Qt.WA_TranslucentBackground)
            self.centralwidget = QtWidgets.QWidget(MainWindow)
            self.centralwidget.setObjectName("centralwidget")
            self.Button_W = QtWidgets.QPushButton(self.centralwidget)
            self.Button_W.setGeometry(QtCore.QRect(200, 610, 70, 70))
            self.Button_W.setMinimumSize(QtCore.QSize(70, 70))
            self.Button_W.setMaximumSize(QtCore.QSize(70, 70))
            font = QtGui.QFont()
            font.setFamily("微软雅黑")
            font.setPointSize(12)
            font.setBold(True)
            font.setWeight(75)
            self.Button_W.setFont(font)
            self.Button_W.setStyleSheet("QPushButton{\n"
    "    background:rgba(87,96,105,60);\n"
    "    border: 5px groove rgba(111, 255, 212, 30);\n"
    "    border-radius:20px;\n"
    "    color: rgb(255,255, 255);\n"
    "    selection-background-color: rgba(255,255,255,50);\n"
    "    border-style: outset;\n"
    "}\n"
    "\n"
    "QPushButton:hover{\n"
    "    background-color:rgba(140, 154, 168,60); \n"
    "    border-style: inset;\n"
    "}")
            self.Button_W.setObjectName("Button_W")
            self.Button_A = QtWidgets.QPushButton(self.centralwidget)
            self.Button_A.setGeometry(QtCore.QRect(130, 680, 70, 70))
            self.Button_A.setMinimumSize(QtCore.QSize(70, 70))
            self.Button_A.setMaximumSize(QtCore.QSize(70, 70))
            font = QtGui.QFont()
            font.setFamily("微软雅黑")
            font.setPointSize(12)
            font.setBold(True)
            font.setWeight(75)
            self.Button_A.setFont(font)
            self.Button_A.setStyleSheet("QPushButton{\n"
    "    background:rgba(87,96,105,60);\n"
    "    border: 5px groove rgba(111, 255, 212, 30);\n"
    "    border-radius:20px;\n"
    "    color: rgb(255,255, 255);\n"
    "    selection-background-color: rgba(255,255,255,50);\n"
    "    border-style: outset;\n"
    "}\n"
    "\n"
    "QPushButton:hover{\n"
    "    background-color:rgba(140, 154, 168,60); \n"
    "    border-style: inset;\n"
    "}")
            self.Button_A.setObjectName("Button_A")
            self.Button_S = QtWidgets.QPushButton(self.centralwidget)
            self.Button_S.setGeometry(QtCore.QRect(200, 680, 70, 70))
            self.Button_S.setMinimumSize(QtCore.QSize(70, 70))
            self.Button_S.setMaximumSize(QtCore.QSize(70, 70))
            font = QtGui.QFont()
            font.setFamily("微软雅黑")
            font.setPointSize(12)
            font.setBold(True)
            font.setWeight(75)
            self.Button_S.setFont(font)
            self.Button_S.setStyleSheet("QPushButton{\n"
    "    background:rgba(87,96,105,60);\n"
    "    border: 5px groove rgba(111, 255, 212, 30);\n"
    "    border-radius:20px;\n"
    "    color: rgb(255,255, 255);\n"
    "    selection-background-color: rgba(255,255,255,50);\n"
    "    border-style: outset;\n"
    "}\n"
    "\n"
    "QPushButton:hover{\n"
    "    background-color:rgba(140, 154, 168,60); \n"
    "    border-style: inset;\n"
    "}")
            self.Button_S.setObjectName("Button_S")
            self.Button_D = QtWidgets.QPushButton(self.centralwidget)
            self.Button_D.setGeometry(QtCore.QRect(270, 680, 70, 70))
            self.Button_D.setMinimumSize(QtCore.QSize(70, 70))
            self.Button_D.setMaximumSize(QtCore.QSize(70, 70))
            font = QtGui.QFont()
            font.setFamily("微软雅黑")
            font.setPointSize(12)
            font.setBold(True)
            font.setWeight(75)
            self.Button_D.setFont(font)
            self.Button_D.setStyleSheet("QPushButton{\n"
    "    background:rgba(87,96,105,60);\n"
    "    border: 5px groove rgba(111, 255, 212, 30);\n"
    "    border-radius:20px;\n"
    "    color: rgb(255,255, 255);\n"
    "    selection-background-color: rgba(255,255,255,50);\n"
    "    border-style: outset;\n"
    "}\n"
    "\n"
    "QPushButton:hover{\n"
    "    background-color:rgba(140, 154, 168,60); \n"
    "    border-style: inset;\n"
    "}")
            self.Button_D.setObjectName("Button_D")
            self.Button_I = QtWidgets.QPushButton(self.centralwidget)
            self.Button_I.setGeometry(QtCore.QRect(470, 680, 70, 70))
            self.Button_I.setMinimumSize(QtCore.QSize(70, 70))
            self.Button_I.setMaximumSize(QtCore.QSize(70, 70))
            font = QtGui.QFont()
            font.setFamily("微软雅黑")
            font.setPointSize(12)
            font.setBold(True)
            font.setWeight(75)
            self.Button_I.setFont(font)
            self.Button_I.setStyleSheet("QPushButton{\n"
    "    background:rgba(87,96,105,60);\n"
    "    border: 5px groove rgba(111, 255, 212, 30);\n"
    "    border-radius:20px;\n"
    "    color: rgb(255,255, 255);\n"
    "    selection-background-color: rgba(255,255,255,50);\n"
    "    border-style: outset;\n"
    "}\n"
    "\n"
    "QPushButton:hover{\n"
    "    background-color:rgba(140, 154, 168,60); \n"
    "    border-style: inset;\n"
    "}")
            self.Button_I.setObjectName("Button_I")
            self.Button_P = QtWidgets.QPushButton(self.centralwidget)
            self.Button_P.setGeometry(QtCore.QRect(470, 610, 70, 70))
            self.Button_P.setMinimumSize(QtCore.QSize(70, 70))
            self.Button_P.setMaximumSize(QtCore.QSize(70, 70))
            font = QtGui.QFont()
            font.setFamily("微软雅黑")
            font.setPointSize(12)
            font.setBold(True)
            font.setWeight(75)
            self.Button_P.setFont(font)
            self.Button_P.setStyleSheet("QPushButton{\n"
    "    background:rgba(87,96,105,60);\n"
    "    border: 5px groove rgba(111, 255, 212, 30);\n"
    "    border-radius:20px;\n"
    "    color: rgb(255,255, 255);\n"
    "    selection-background-color: rgba(255,255,255,50);\n"
    "    border-style: outset;\n"
    "}\n"
    "\n"
    "QPushButton:hover{\n"
    "    background-color:rgba(140, 154, 168,60); \n"
    "    border-style: inset;\n"
    "}")
            self.Button_P.setObjectName("Button_P")
            self.label_7 = QtWidgets.QLabel(self.centralwidget)
            self.label_7.setGeometry(QtCore.QRect(690, 328, 241, 51))
            font = QtGui.QFont()
            font.setFamily("微软雅黑")
            font.setPointSize(16)
            font.setBold(True)
            font.setWeight(75)
            self.label_7.setFont(font)
            self.label_7.setStyleSheet("color: rgb(66, 204, 165);\n"
    "")
            self.label_7.setTextFormat(QtCore.Qt.AutoText)
            self.label_7.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
            self.label_7.setObjectName("label_7")
            self.Lab_cmd = QtWidgets.QLabel(self.centralwidget)
            self.Lab_cmd.setGeometry(QtCore.QRect(710, 388, 241, 51))
            font = QtGui.QFont()
            font.setFamily("微软雅黑")
            font.setPointSize(16)
            font.setBold(True)
            font.setWeight(75)
            self.Lab_cmd.setFont(font)
            self.Lab_cmd.setStyleSheet("color: rgb(66, 204, 165);\n"
    "")
            self.Lab_cmd.setText("")
            self.Lab_cmd.setTextFormat(QtCore.Qt.AutoText)
            self.Lab_cmd.setAlignment(QtCore.Qt.AlignCenter)
            self.Lab_cmd.setObjectName("Lab_cmd")
            self.Lab_camera = QtWidgets.QLabel(self.centralwidget)
            self.Lab_camera.setGeometry(QtCore.QRect(70, 50, 501, 501))
            self.Lab_camera.setStyleSheet("border-radius:20px;")
            self.Lab_camera.setText("")
            self.Lab_camera.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse)
            self.Lab_camera.setObjectName("Lab_camera")
            self.Button_voice = QtWidgets.QPushButton(self.centralwidget)
            self.Button_voice.setGeometry(QtCore.QRect(750, 638, 161, 61))
            font = QtGui.QFont()
            font.setFamily("微软雅黑")
            font.setPointSize(12)
            font.setBold(True)
            font.setWeight(75)
            self.Button_voice.setFont(font)
            self.Button_voice.setStyleSheet("QPushButton{\n"
    "    background:rgba(87,96,105,80);\n"
    "    border: 5px groove rgba(111, 255, 212, 50);\n"
    "    border-radius:20px;\n"
    "    color: rgb(255,255, 255);\n"
    "    selection-background-color: rgba(255,255,255,80);\n"
    "    border-style: outset;\n"
    "}\n"
    "\n"
    "QPushButton:hover{\n"
    "    background-color:rgba(140, 154, 168,80); \n"
    "    border-style: inset;\n"
    "}")
            self.Button_voice.setObjectName("Button_voice")
            self.label_8 = QtWidgets.QLabel(self.centralwidget)
            self.label_8.setGeometry(QtCore.QRect(670, 448, 241, 51))
            font = QtGui.QFont()
            font.setFamily("微软雅黑")
            font.setPointSize(16)
            font.setBold(True)
            font.setWeight(75)
            self.label_8.setFont(font)
            self.label_8.setStyleSheet("color: rgb(66, 204, 165);\n"
    "")
            self.label_8.setTextFormat(QtCore.Qt.AutoText)
            self.label_8.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
            self.label_8.setObjectName("label_8")
            self.label_9 = QtWidgets.QLabel(self.centralwidget)
            self.label_9.setGeometry(QtCore.QRect(670, 508, 321, 71))
            font = QtGui.QFont()
            font.setFamily("微软雅黑")
            font.setPointSize(16)
            font.setBold(True)
            font.setWeight(75)
            self.label_9.setFont(font)
            self.label_9.setStyleSheet("color: rgb(66, 204, 165);\n"
    "")
            self.label_9.setAlignment(QtCore.Qt.AlignCenter)
            self.label_9.setOpenExternalLinks(True)
            self.label_9.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse|QtCore.Qt.TextSelectableByMouse)
            self.label_9.setObjectName("label_9")
            self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
            self.lineEdit.setGeometry(QtCore.QRect(700, 38, 251, 721))
            self.lineEdit.setStyleSheet("background-color:rgba(255,255,255,60);\n"
    "border-radius:20px;")
            self.lineEdit.setReadOnly(True)
            self.lineEdit.setObjectName("lineEdit")
            self.lineEdit.raise_()
            self.Lab_camera.raise_()
            self.Button_W.raise_()
            self.Button_A.raise_()
            self.Button_S.raise_()
            self.Button_D.raise_()
            self.Button_I.raise_()
            self.Button_P.raise_()
            self.label_7.raise_()
            self.Lab_cmd.raise_()
            self.Button_voice.raise_()
            self.label_8.raise_()
            self.label_9.raise_()
            MainWindow.setCentralWidget(self.centralwidget)
    
            self.retranslateUi(MainWindow)
            QtCore.QMetaObject.connectSlotsByName(MainWindow)
    
        def retranslateUi(self, MainWindow):
            _translate = QtCore.QCoreApplication.translate
            MainWindow.setWindowTitle(_translate("MainWindow", "BalanceCar Console"))
            self.Button_W.setText(_translate("MainWindow", "W"))
            self.Button_A.setText(_translate("MainWindow", "A"))
            self.Button_S.setText(_translate("MainWindow", "S"))
            self.Button_D.setText(_translate("MainWindow", "D"))
            self.Button_I.setText(_translate("MainWindow", "I"))
            self.Button_P.setText(_translate("MainWindow", "P"))
            self.label_7.setText(_translate("MainWindow", "Last Command:"))
            self.Button_voice.setText(_translate("MainWindow", "Voice Control"))
            self.label_8.setText(_translate("MainWindow", "Information:"))
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  • 相关阅读:
    mysql kudu impala中 多层分组 先统计用户数量 再区间统计和的数量
    python 打包可执行文件-Nuitka详解
    腾讯云GPU云服务器计算型和渲染型分别适用于哪些场景?
    【无标题】微信小程序登录流程详解
    Linux本地RStudio工具安装指南及远程访问配置安装RStudio Server
    LeetCode 654. 最大二叉树
    win docker clickhouse 挂载本地目录到容器后无法写入数据问题解决
    解密铭控传感从数字压力表到多品类物联感知硬件的发展史!
    centos虚拟机无法接受消息(防火墙)
    windows10(19044_1706)离线安装wsl和Docker的填坑记录
  • 原文地址:https://blog.csdn.net/sheziqiong/article/details/127132997