当前位置:网站首页>基于open mv 搭配stm32循迹
基于open mv 搭配stm32循迹
2022-04-23 06:13:00 【ZLP啊~】
基于open mv 搭配stm32循迹
一.代码
THRESHOLD = (0, 43, 20, -8, -37, 14) # Grayscale threshold for dark things...
import sensor, image, time
from pyb import LED
import car
from pid import PID
from pyb import UART
from pyb import Pin
rho_pid = PID(p=0.4, i=0)
theta_pid = PID(p=0.001, i=0)
sensor.reset()
sensor.set_vflip(True)
sensor.set_hmirror(True)
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQQVGA) # 80x60 (4,800 pixels) - O(N^2) max = 2,3040,000.
#sensor.set_windowing([0,20,80,40])
sensor.skip_frames(time = 2000) # WARNING: If you use QQVGA it may take seconds
clock = time.clock() # to process a frame sometimes.
uart = UART(3, 115200)
while(True):
clock.tick()
img = sensor.snapshot().binary([THRESHOLD])
line = img.get_regression([(100,100)], robust = True)#二值化
if (line):
rho_err = abs(line.rho())-img.width()/2
if line.theta()>90:
theta_err = line.theta()-180
else:
theta_err = line.theta()
img.draw_line(line.line(), color = 127)
#print(rho_err,line.magnitude(),rho_err)
if line.magnitude()>8: #值越大线性回归效果越好
#if -40<b_err<40 and -30<t_err<30:
rho_output = rho_pid.get_pid(rho_err,1)
theta_output = theta_pid.get_pid(theta_err,1)
output = rho_output+theta_output
if rho_err > -3 and rho_err < 3:
uart.write("1")
p_out = Pin('P0', Pin.OUT_PP)
p_out.high()
p_out = Pin('P1', Pin.OUT_PP)
p_out.low()#设置p_out引脚为低
p_out = Pin('P2', Pin.OUT_PP)
p_out.low()#设置p_out引脚为低
print('0')
elif rho_err <= -3:
p_out = Pin('P1', Pin.OUT_PP)#设置p_out为输出引脚
p_out.high()#设置p_out引脚为高
p_out = Pin('P0', Pin.OUT_PP)
p_out.low()#设置p_out引脚为低
p_out = Pin('P2', Pin.OUT_PP)
p_out.low()#设置p_out引脚为低
uart.write("2")
print('1')
elif rho_err >= 3:
uart.write("3")
p_out = Pin('P2', Pin.OUT_PP)#设置p_out为输出引脚
p_out.high()#设置p_out引脚为高
p_out = Pin('P1', Pin.OUT_PP)
p_out.low()#设置p_out引脚为低
p_out = Pin('P0', Pin.OUT_PP)
p_out.low()#设置p_out引脚为低
print('2')
#print(clock.fps())
这里使用星瞳的例程,加入自己的思想,由于时刚学OPEN MV所以使用这种简单的思想。这里OPEN MV相当于循迹模块。
二.思想
这里我是主要使用rho_err这个函数,在星瞳例程中会在所循迹物体中间画出一条线,而rho_err便是那个线对于所循的误差,偏左了小于0,偏大了大于0,rho_err >= 某个数,某个数就是偏移量,可以对某个数进行调整使路线更加精准。然后对IO口设置高低电平。32读取io电平对路线进行调整。
如果还有问题可以在下方留言。
版权声明
本文为[ZLP啊~]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_52297353/article/details/120375132
边栏推荐
- Some common data type conversion methods in pytorch are similar to list and NP Conversion method of ndarray
- SHA512/384 原理及C语言实现(附源码)
- [dynamic programming] triangle minimum path sum
- ArcGIS license server administrator cannot start the workaround
- EMMC/SD学习小记
- LPDDR4笔记
- AUTOSAR从入门到精通100讲(八十一)-AUTOSAR基础篇之FiM
- 第5 章 机器学习基础
- 1.1 PyTorch和神经网络
- Face_ Recognition face detection
猜你喜欢

【点云系列】Neural Opacity Point Cloud(NOPC)

Write a wechat double open gadget to your girlfriend

pth 转 onnx 时出现的 gather、unsqueeze 等算子

ARMCC/GCC下的stack protector

SSL / TLS application example

使用 trt 的int8 量化和推断 onnx 模型

imx6ull-qemu 裸机教程1:GPIO,IOMUX,I2C

Chapter 2 pytoch foundation 2

主流 RTOS 评估

Infrared sensor control switch
随机推荐
torch.where能否传递梯度
Handlerthread principle and practical application
UEFI学习01-ARM AARCH64编译、ArmPlatformPriPeiCore(SEC)
Wechat applet uses wxml2canvas plug-in to generate some problem records of pictures
torch_ Geometric learning 1, messagepassing
AUTOSAR从入门到精通100讲(八十七)-高级EEA的关键利器-AUTOSAR与DDS
【点云系列】Relationship-based Point Cloud Completion
【指标】Precision、Recall
AUTOSAR从入门到精通100讲(八十一)-AUTOSAR基础篇之FiM
【点云系列】Learning Representations and Generative Models for 3D pointclouds
imx6ull-qemu 裸机教程2:USDHC SD卡
Gee configuring local development environment
Keras如何保存、加载Keras模型
【点云系列】 场景识别类导读
Computer shutdown program
[Point Cloud Series] SG - Gan: Adversarial Self - attachment GCN for Point Cloud Topological parts Generation
PyTorch训练一个网络的基本流程5步法
pth 转 onnx 时出现的 gather、unsqueeze 等算子
x509解析
ArcGIS license server administrator cannot start the workaround