ESP32(MicroPython) 网页控制两轮差速底盘(发出热点、串口输出)

由于本人目前没有Linux开发板,为了方便对两轮差速底盘进行闭环控制的调试,本人制作了在另一个主控上使用的程序以便通过网页向控制底盘的主控发送数据。实测发现在有负载时两轮差速底盘的P、I值可以增大,目前调到P=10、I=2,在目标速度为0.5m/s以上时响应速度良好。

程序如下

#导入Pin模块
from machine import Pin
import time
from machine import PWM
import network
import socket

#定义LED控制对象
led1=Pin(6,Pin.OUT,Pin.PULL_DOWN)
 
duty=0
speed=0
turn=0
angular=400
linear=400

#WIFI连接
def wifi_connect():
    ap = network.WLAN(network.AP_IF)  # 指定用ap模式
    ap.active(True)                   # 启用wifi前需要先激活接口
    ap.config(essid="ESP32_Motor_Control")      # 设置热点名称
    ap.config(authmode=0)  # 设置认证模式
    return True

#网页数据
def web_page():
    global a1
    global a2
    global a3
    global a4
  
    html = """<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  
  <style>
    .button{display: inline-block; background-color: #8080f0; border: none; 
    border-radius: 4px; color: white; padding: 8px 15px; text-decoration: none; font-size: 20px; margin: 2px; cursor: pointer;}
    a:link {text-decoration:none;}a:visited {text-decoration:none;}a:hover {text-decoration:none;}
    a:active {text-decoration:none;} 
    html {
     font-family: Arial;
     display: inline-block;
     margin: 0px auto;
     text-align: center;
    }
    h2 { font-size: 1.5rem; }
    p { font-size: 1.5rem; }
    .units { font-size: 1rem; }
    .dht-labels{
      font-size: 1rem;
      vertical-align:middle;
      padding-bottom: 7px;
    }
  </style>
</head>
<body>
  <h2>ESP32 Motor Control</h2> <p><a href="/?d1">linear: <strong>""" + str(speed) + """</strong></a></p>
        <p><a href="/?w10"><button class="button">-3.00</button></a>
        <a href="/?w11"><button class="button">-2.75</button></a>
        <a href="/?w12"><button class="button">-2.50</button></a>
        <a href="/?w13"><button class="button">-2.25</button></a>
        <a href="/?w14"><button class="button">-2.00</button></a>
        <a href="/?w15"><button class="button">-1.75</button></a>
        <a href="/?w16"><button class="button">-1.50</button></a>
        <a href="/?w17"><button class="button">-1.25</button></a>
        <a href="/?w18"><button class="button">-1.00</button></a>
        <a href="/?w19"><button class="button">-0.75</button></a>
        <a href="/?w1a"><button class="button">-0.50</button></a>
        <a href="/?w1b"><button class="button">-0.25</button></a>
        <a href="/?w1c"><button class="button">0.00</button></a>
        <a href="/?w1d"><button class="button">0.25</button></a>
        <a hre
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路易斯720

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值