8.18完成udp通信发送mpu6050数据
commit
3988ab1b17
|
@ -0,0 +1,36 @@
|
|||
# FocProject
|
||||
|
||||
#### Description
|
||||
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
|
||||
|
||||
#### Software Architecture
|
||||
Software architecture description
|
||||
|
||||
#### Installation
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### Instructions
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### Contribution
|
||||
|
||||
1. Fork the repository
|
||||
2. Create Feat_xxx branch
|
||||
3. Commit your code
|
||||
4. Create Pull Request
|
||||
|
||||
|
||||
#### Gitee Feature
|
||||
|
||||
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
|
||||
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
|
||||
4. The most valuable open source project [GVP](https://gitee.com/gvp)
|
||||
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
|
||||
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
|
@ -0,0 +1,39 @@
|
|||
# FocProject
|
||||
|
||||
#### 介绍
|
||||
{**以下是 Gitee 平台说明,您可以替换此简介**
|
||||
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
|
||||
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
|
||||
|
||||
#### 安装教程
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 使用说明
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 参与贡献
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 新建 Feat_xxx 分支
|
||||
3. 提交代码
|
||||
4. 新建 Pull Request
|
||||
|
||||
|
||||
#### 特技
|
||||
|
||||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
||||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
||||
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
||||
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
|
@ -0,0 +1,114 @@
|
|||
/**
|
||||
Deng's FOC 闭环速度控制例程 测试库:SimpleFOC 2.1.1 测试硬件:灯哥开源FOC V1.0
|
||||
在串口窗口中输入:T+速度,就可以使得两个电机闭环转动
|
||||
比如让两个电机都以 10rad/s 的速度转动,则输入:T10
|
||||
在使用自己的电机时,请一定记得修改默认极对数,即 BLDCMotor(7) 中的值,设置为自己的极对数数字
|
||||
程序默认设置的供电电压为 16.8V,用其他电压供电请记得修改 voltage_power_supply , voltage_limit 变量中的值
|
||||
默认PID针对的电机是 GB6010 ,使用自己的电机需要修改PID参数,才能实现更好效果
|
||||
*/
|
||||
#include <SimpleFOC.h>
|
||||
#include <WiFi.h>
|
||||
#include <AsyncUDP.h> //引用以使用异步UDP
|
||||
|
||||
const char *ssid = "esp32";
|
||||
const char *password = "12345678";
|
||||
|
||||
AsyncUDP udp; //创建UDP对象
|
||||
unsigned int localUdpPort = 2333; //本地端口号
|
||||
|
||||
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
|
||||
|
||||
TwoWire I2Cone = TwoWire(0);
|
||||
|
||||
|
||||
//电机参数
|
||||
BLDCMotor motor = BLDCMotor(5);
|
||||
BLDCDriver3PWM driver = BLDCDriver3PWM(32, 33, 25, 22);
|
||||
|
||||
|
||||
//命令设置
|
||||
int target_velocity = 0;
|
||||
void onPacketCallBack(AsyncUDPPacket packet)
|
||||
{
|
||||
target_velocity = atoi((char*)(packet.data()));
|
||||
Serial.print("数据内容: ");
|
||||
Serial.println(target_velocity);
|
||||
// packet.print("reply data");
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
//wifi初始化
|
||||
WiFi.mode(WIFI_AP);
|
||||
while(!WiFi.softAP(ssid, password)){}; //启动AP
|
||||
Serial.println("AP启动成功");
|
||||
while (!udp.listen(localUdpPort)) //等待udp监听设置成功
|
||||
{
|
||||
}
|
||||
udp.onPacket(onPacketCallBack); //注册收到数据包事件
|
||||
I2Cone.begin(23, 5, 400000); //SDA,SCL
|
||||
|
||||
sensor.init(&I2Cone);
|
||||
|
||||
//连接motor对象与传感器对象
|
||||
motor.linkSensor(&sensor);
|
||||
|
||||
|
||||
//供电电压设置 [V]
|
||||
driver.voltage_power_supply = 12;
|
||||
driver.init();
|
||||
|
||||
|
||||
//连接电机和driver对象
|
||||
motor.linkDriver(&driver);
|
||||
|
||||
|
||||
//FOC模型选择
|
||||
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
|
||||
|
||||
//运动控制模式设置
|
||||
motor.controller = MotionControlType::velocity;
|
||||
|
||||
|
||||
|
||||
//速度PI环设置
|
||||
motor.PID_velocity.P = 1.5;
|
||||
|
||||
motor.PID_velocity.I = 20;
|
||||
|
||||
//最大电机限制电机
|
||||
motor.voltage_limit = 12;
|
||||
|
||||
|
||||
//速度低通滤波时间常数
|
||||
motor.LPF_velocity.Tf = 0.01;
|
||||
|
||||
|
||||
//设置最大速度限制
|
||||
motor.velocity_limit = 40;
|
||||
|
||||
|
||||
motor.useMonitoring(Serial);
|
||||
|
||||
|
||||
//初始化电机
|
||||
motor.init();
|
||||
|
||||
//初始化 FOC
|
||||
motor.initFOC();
|
||||
|
||||
|
||||
Serial.println(F("Motor ready."));
|
||||
Serial.println(F("Set the target velocity using serial terminal:"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop() {
|
||||
motor.loopFOC();
|
||||
|
||||
|
||||
motor.move(target_velocity);
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
问题1:wifi接受到的数据为const uint_8 不能直接用atoi转换为int。
|
||||
解决:atoi((char*)(packet.data())) //使用(char*) 进行强制类型转换
|
||||
|
||||
问题2:c语言中sizeof()返回的是变量声明后所占的内存数,不是实际长度。strlen是一个函数,求的是字符串的实际长度,它求得方法是从开始到遇到第一个'\0',如果你只定义没有给它赋初值,这个结果是不定的,它会从arr首地址一直找下去,直到遇到'\0'停止
|
||||
解决:字符串转换中使用strlen()获得实际长度
|
||||
|
||||
问题3:数字转字符串中可以使用sprintf
|
||||
解决:sprintf(s, "%d", 100//将100转为10进制表示的字符串
|
||||
|
||||
问题4:强制类型转换(const unsigned char*)不能直接使用print输出
|
||||
解决:atoi((char*)(packet.data())) //使用(char*) 进行强制类型转换
|
|
@ -0,0 +1,92 @@
|
|||
#include <WiFi.h>
|
||||
#include <AsyncUDP.h> //引用以使用异步UDP
|
||||
#include<Wire.h>
|
||||
|
||||
const char *ssid = "esp32";
|
||||
const char *password = "12345678";
|
||||
|
||||
const int MPU_addr=0x68; // I2C address of the MPU-6050
|
||||
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
|
||||
|
||||
AsyncUDP udp; //创建UDP对象
|
||||
unsigned int localUdpPort = 2333; //本地端口号
|
||||
|
||||
|
||||
unsigned int broadcastPort = localUdpPort;
|
||||
//const char *broadcastData = "broadcast data";
|
||||
const uint8_t broadcastData[] = {"broadcast data"};
|
||||
|
||||
void onPacketCallBack(AsyncUDPPacket packet)
|
||||
{
|
||||
Serial.print("UDP数据包来源类型: ");
|
||||
Serial.println(packet.isBroadcast() ? "广播数据" : (packet.isMulticast() ? "组播" : "单播"));
|
||||
Serial.print("远端地址及端口号: ");
|
||||
Serial.print(packet.remoteIP());
|
||||
Serial.print(":");
|
||||
Serial.println(packet.remotePort());
|
||||
Serial.print("目标地址及端口号: ");
|
||||
Serial.print(packet.localIP());
|
||||
Serial.print(":");
|
||||
Serial.println(packet.localPort());
|
||||
Serial.print("数据长度: ");
|
||||
Serial.println(packet.length());
|
||||
Serial.print("数据内容: ");
|
||||
Serial.write(packet.data(), packet.length());
|
||||
Serial.println();
|
||||
|
||||
// packet.print("reply data");
|
||||
// broadcastPort = packet.remotePort();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
// mpu6050初始化
|
||||
Wire.begin(19, 18, 400000);
|
||||
Wire.beginTransmission(MPU_addr);
|
||||
Wire.write(0x6B); // PWR_MGMT_1 register
|
||||
Wire.write(0); // set to zero (wakes up the MPU-6050)
|
||||
Wire.endTransmission(true);
|
||||
|
||||
//wifi初始化
|
||||
WiFi.mode(WIFI_AP);
|
||||
while(!WiFi.softAP(ssid, password)){}; //启动AP
|
||||
Serial.println("AP启动成功");
|
||||
while (!udp.listen(localUdpPort)) //等待udp监听设置成功
|
||||
{
|
||||
}
|
||||
udp.onPacket(onPacketCallBack); //注册收到数据包事件
|
||||
}
|
||||
char s[255];
|
||||
void loop()
|
||||
{
|
||||
Wire.beginTransmission(MPU_addr);
|
||||
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
|
||||
Wire.endTransmission(false);
|
||||
Wire.requestFrom(MPU_addr,14,true); // request a total of 14 registers
|
||||
// AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
|
||||
AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
|
||||
// AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
|
||||
// Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
|
||||
// GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
|
||||
// GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
|
||||
// GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
|
||||
|
||||
// Serial.print("AcX = "); Serial.print(AcX);
|
||||
Serial.print(" | AcY = "); Serial.println(AcY);
|
||||
// itoa(AcY,s,10);
|
||||
|
||||
sprintf(s, "%d", AcY); //将100转为16进制表示的字符串
|
||||
Serial.println(strlen(s));
|
||||
// Serial.print(" | AcZ = "); Serial.print(AcZ);
|
||||
// Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53); //equation for temperature in degrees C from datasheet
|
||||
// Serial.print(" | GyX = "); Serial.print(GyX);
|
||||
// Serial.print(" | GyY = "); Serial.print(GyY);
|
||||
// Serial.print(" | GyZ = "); Serial.println(GyZ);
|
||||
delay(100);
|
||||
|
||||
// udp.broadcastTo(broadcastData, broadcastPort); //可以使用该方法广播信息
|
||||
|
||||
IPAddress broadcastAddr((~(uint32_t)WiFi.subnetMask())|((uint32_t)WiFi.localIP())); //计算广播地址
|
||||
udp.writeTo((const unsigned char*)s, strlen(s), broadcastAddr, localUdpPort); //广播数据
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
#include <WiFi.h>
|
||||
#include <AsyncUDP.h> //引用以使用异步UDP
|
||||
|
||||
const char *ssid = "esp32";
|
||||
const char *password = "12345678";
|
||||
|
||||
AsyncUDP udp; //创建UDP对象
|
||||
unsigned int localUdpPort = 2333; //本地端口号
|
||||
|
||||
unsigned int broadcastPort = localUdpPort;
|
||||
const char *broadcastData = "broadcast data";
|
||||
// const uint8_t broadcastData[] = {"broadcast data"};
|
||||
|
||||
void onPacketCallBack(AsyncUDPPacket packet)
|
||||
{
|
||||
// Serial.print("UDP数据包来源类型: ");
|
||||
// Serial.println(packet.isBroadcast() ? "广播数据" : (packet.isMulticast() ? "组播" : "单播"));
|
||||
// Serial.print("远端地址及端口号: ");
|
||||
// Serial.print(packet.remoteIP());
|
||||
// Serial.print(":");
|
||||
// Serial.println(packet.remotePort());
|
||||
// Serial.print("目标地址及端口号: ");
|
||||
// Serial.print(packet.localIP());
|
||||
// Serial.print(":");
|
||||
// Serial.println(packet.localPort());
|
||||
// Serial.print("数据长度: ");
|
||||
// Serial.println(packet.length());
|
||||
Serial.print("数据内容: ");
|
||||
// Serial.write(packet.data(), packet.length());
|
||||
Serial.println(atoi( (char*)(packet.data())));
|
||||
|
||||
// packet.print("reply data");
|
||||
// broadcastPort = packet.remotePort();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
|
||||
WiFi.mode(WIFI_AP);
|
||||
while(!WiFi.softAP(ssid, password)){}; //启动AP
|
||||
Serial.println("AP启动成功");
|
||||
while (!udp.listen(localUdpPort)) //等待udp监听设置成功
|
||||
{
|
||||
}
|
||||
udp.onPacket(onPacketCallBack); //注册收到数据包事件
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// delay(5000);
|
||||
//
|
||||
// udp.broadcastTo(broadcastData, broadcastPort); //可以使用该方法广播信息
|
||||
|
||||
// IPAddress broadcastAddr((~(uint32_t)WiFi.subnetMask())|((uint32_t)WiFi.localIP())); //计算广播地址
|
||||
// udp.writeTo(broadcastData, sizeof(broadcastData), broadcastAddr, localUdpPort); //广播数据
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/gui.iml" filepath="$PROJECT_DIR$/.idea/gui.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,62 @@
|
|||
import sys
|
||||
from PyQt5.QtWidgets import QApplication, QMainWindow
|
||||
from main_ui import *
|
||||
from wifi_udp import *
|
||||
import threading #引入并行
|
||||
import numpy as np
|
||||
import pyqtgraph as pg
|
||||
|
||||
|
||||
class MyWindow(QMainWindow, Ui_MainWindow):
|
||||
def __init__(self, parent=None):
|
||||
super(MyWindow, self).__init__(parent)
|
||||
self.setupUi(self)
|
||||
self.v_list=[]
|
||||
self.v_list.append(np.zeros(300))
|
||||
self.timeArray = np.arange(-300, 0, 1)
|
||||
|
||||
self.velocity = 0
|
||||
# 滑条
|
||||
self.velocity_lineEdit.setText(str(self.velocity_horizontalSlider.value()))
|
||||
self.velocity_horizontalSlider.valueChanged.connect(self.velocity_horizontalSlider_valueChanged)
|
||||
# wifi udp
|
||||
self.udp = udp()
|
||||
|
||||
# 接收数据
|
||||
self.udp_data = ''
|
||||
t1 = threading.Thread(target=self.udp_recv)
|
||||
t1.start()
|
||||
# 绘图对象
|
||||
self.pw = pg.PlotWidget()
|
||||
self.curve = self.pw.plot(pen='y')
|
||||
self.gridLayout.addWidget(self.pw)
|
||||
# 定时器
|
||||
self.timer = QtCore.QTimer()
|
||||
self.timer.timeout.connect(self.update_plot)
|
||||
self.timer.start(50)
|
||||
|
||||
|
||||
|
||||
# 滑条事件绑定
|
||||
def velocity_horizontalSlider_valueChanged(self):
|
||||
value = self.velocity_horizontalSlider.value()
|
||||
self.velocity_lineEdit.setText(str(value))
|
||||
# self.udp.send_message(str(value))
|
||||
# self.curve.updateItems()
|
||||
# self.curve.sigPlotChanged.emit(self.curve)
|
||||
|
||||
def udp_recv(self):
|
||||
while True:
|
||||
recv_data = self.udp.udpClientSocket.recv(1024)
|
||||
recv_data = recv_data.decode('utf-8')
|
||||
self.udp_data = recv_data
|
||||
def update_plot(self):
|
||||
print(self.udp_data)
|
||||
self.v_list[0] = np.roll(self.v_list[0], -1)
|
||||
self.v_list[0][-1] = self.udp_data
|
||||
self.curve.setData(self.timeArray, self.v_list[0]) # 在绘图部件中绘制折线图
|
||||
if __name__ == '__main__':
|
||||
app = QApplication(sys.argv)
|
||||
myWin = MyWindow()
|
||||
myWin.show()
|
||||
sys.exit(app.exec_())
|
|
@ -0,0 +1,55 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'main_ui.ui'
|
||||
#
|
||||
# Created by: PyQt5 UI code generator 5.15.2
|
||||
#
|
||||
# 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(800, 600)
|
||||
self.centralwidget = QtWidgets.QWidget(MainWindow)
|
||||
self.centralwidget.setObjectName("centralwidget")
|
||||
self.velocity_horizontalSlider = QtWidgets.QSlider(self.centralwidget)
|
||||
self.velocity_horizontalSlider.setGeometry(QtCore.QRect(470, 420, 261, 22))
|
||||
self.velocity_horizontalSlider.setMinimum(-100)
|
||||
self.velocity_horizontalSlider.setMaximum(100)
|
||||
self.velocity_horizontalSlider.setOrientation(QtCore.Qt.Horizontal)
|
||||
self.velocity_horizontalSlider.setTickPosition(QtWidgets.QSlider.TicksAbove)
|
||||
self.velocity_horizontalSlider.setTickInterval(10)
|
||||
self.velocity_horizontalSlider.setObjectName("velocity_horizontalSlider")
|
||||
self.velocity_lineEdit = QtWidgets.QLineEdit(self.centralwidget)
|
||||
self.velocity_lineEdit.setGeometry(QtCore.QRect(580, 460, 113, 21))
|
||||
self.velocity_lineEdit.setObjectName("velocity_lineEdit")
|
||||
self.label = QtWidgets.QLabel(self.centralwidget)
|
||||
self.label.setGeometry(QtCore.QRect(520, 460, 51, 16))
|
||||
self.label.setObjectName("label")
|
||||
self.gridLayoutWidget = QtWidgets.QWidget(self.centralwidget)
|
||||
self.gridLayoutWidget.setGeometry(QtCore.QRect(180, 20, 581, 361))
|
||||
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
|
||||
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
|
||||
self.gridLayout.setContentsMargins(0, 0, 0, 0)
|
||||
self.gridLayout.setObjectName("gridLayout")
|
||||
MainWindow.setCentralWidget(self.centralwidget)
|
||||
self.menubar = QtWidgets.QMenuBar(MainWindow)
|
||||
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
|
||||
self.menubar.setObjectName("menubar")
|
||||
MainWindow.setMenuBar(self.menubar)
|
||||
self.statusbar = QtWidgets.QStatusBar(MainWindow)
|
||||
self.statusbar.setObjectName("statusbar")
|
||||
MainWindow.setStatusBar(self.statusbar)
|
||||
|
||||
self.retranslateUi(MainWindow)
|
||||
QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
||||
|
||||
def retranslateUi(self, MainWindow):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
|
||||
self.label.setText(_translate("MainWindow", "速度:"))
|
|
@ -0,0 +1,91 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<widget class="QSlider" name="velocity_horizontalSlider">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>470</x>
|
||||
<y>420</y>
|
||||
<width>261</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-100</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::TicksAbove</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>10</number>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="velocity_lineEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>580</x>
|
||||
<y>460</y>
|
||||
<width>113</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>520</x>
|
||||
<y>460</y>
|
||||
<width>51</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>速度:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="gridLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>180</x>
|
||||
<y>20</y>
|
||||
<width>581</width>
|
||||
<height>361</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout"/>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,7 @@
|
|||
import socket
|
||||
#创建socket对象
|
||||
#SOCK_DGRAM udp模式
|
||||
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
||||
s.bind(("169.254.184.146",8000)) #绑定服务器的ip和端口
|
||||
data=s.recv(1024) #一次接收1024字节
|
||||
print(data.decode())# decode()解码收到的字节
|
|
@ -0,0 +1,42 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
This example demonstrates many of the 2D plotting capabilities
|
||||
in pyqtgraph. All of the plots may be panned/scaled by dragging with
|
||||
the left/right mouse buttons. Right click on any plot to show a context menu.
|
||||
"""
|
||||
|
||||
from pyqtgraph.Qt import QtGui, QtCore
|
||||
import numpy as np
|
||||
import pyqtgraph as pg
|
||||
|
||||
#QtGui.QApplication.setGraphicsSystem('raster')
|
||||
app = QtGui.QApplication([])
|
||||
#mw = QtGui.QMainWindow()
|
||||
#mw.resize(800,800)
|
||||
|
||||
win = pg.GraphicsLayoutWidget(show=True, title="Basic plotting examples")
|
||||
win.resize(1000,600)
|
||||
win.setWindowTitle('pyqtgraph example: Plotting')
|
||||
|
||||
# Enable antialiasing for prettier plots
|
||||
pg.setConfigOptions(antialias=True)
|
||||
|
||||
p6 = win.addPlot(title="Updating plot")
|
||||
curve = p6.plot(pen='y')
|
||||
data = np.random.normal(size=(10,1000))
|
||||
ptr = 0
|
||||
def update():
|
||||
global curve, data, ptr, p6
|
||||
curve.setData(data[ptr%10])
|
||||
if ptr == 0:
|
||||
p6.enableAutoRange('xy', False) ## stop auto-scaling after the first data set is plotted
|
||||
ptr += 1
|
||||
timer = QtCore.QTimer()
|
||||
timer.timeout.connect(update)
|
||||
timer.start(50)
|
||||
|
||||
## Start Qt event loop unless running in interactive mode or using pyside.
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
|
||||
QtGui.QApplication.instance().exec_()
|
|
@ -0,0 +1,34 @@
|
|||
import socket #引入套接字
|
||||
import threading #引入并行
|
||||
udp_data = None
|
||||
def udp_send(udp_socket):
|
||||
|
||||
while True:
|
||||
num1 = '192.168.4.1'
|
||||
num2 = 2333
|
||||
send_data = input('请输入要发送的数据:')
|
||||
send_data = send_data.encode('utf-8')
|
||||
udp_socket.sendto(send_data,(num1,num2)) #sendto(发送数据,发送地址)
|
||||
|
||||
def udp_recv(udp_socket):
|
||||
global udp_data
|
||||
while True:
|
||||
recv_data = udp_socket.recv(1024)
|
||||
recv_data = recv_data.decode('utf-8')
|
||||
udp_data = recv_data
|
||||
print('收到信息为:%s'%recv_data)
|
||||
|
||||
def main():
|
||||
udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #创建套接字
|
||||
ip = '192.168.4.2' #服务器ip和端口
|
||||
port = 2333
|
||||
udp_socket.bind(("192.168.4.2",2333)) #服务器绑定ip和端口
|
||||
#发送数据
|
||||
t=threading.Thread(target=udp_send,args=(udp_socket,)) # Thread函数用于并行
|
||||
#接收数据
|
||||
t1=threading.Thread(target=udp_recv,args=(udp_socket,))
|
||||
t.start() #并行开始
|
||||
t1.start()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,30 @@
|
|||
from socket import *
|
||||
class udp(object):
|
||||
"""wifi udp to esp32"""
|
||||
def __init__(self,HOST = '192.168.4.1',PORT = 2333):
|
||||
|
||||
self.HOST = HOST
|
||||
self.PORT =PORT
|
||||
self.BUFSIZ = 1024
|
||||
self.ADDRESS = (self.HOST, self.PORT)
|
||||
|
||||
self.udpClientSocket = socket(AF_INET, SOCK_DGRAM)
|
||||
self.udpClientSocket.bind(("192.168.4.2",2333))
|
||||
|
||||
def send_message(self,data):
|
||||
if not data:
|
||||
return 0
|
||||
self.udpClientSocket.sendto(data.encode('utf-8'),self.ADDRESS)
|
||||
|
||||
if __name__ == '__main__':
|
||||
udp = udp()
|
||||
while True:
|
||||
data = input('>')
|
||||
udp.send_message(data)
|
||||
# 接收数据
|
||||
data, ADDR = udp.udpClientSocket.recvfrom(udp.BUFSIZ)
|
||||
if not data:
|
||||
break
|
||||
print("服务器端响应:", data.decode('utf-8'))
|
||||
|
||||
udp.udpClientSocket.close()
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in New Issue