logo

openmv与stm32连接卡死?

2019-01-17 15:50
W
ia2g

只要有openmv跟飞控直接有数据通信,单片机就卡死,如果没有发送uart.write就不会卡死。。这是为什么?没弄明白

2019-01-17 18:53
I
网红小智智 星瞳科技

请说具体的现象,不要只说“卡死,不能运行,没反应,不动了”

I
网红小智智 星瞳科技

请提供openmv上的全部的代码,和飞控全部的代码。

你的串口发送频率是多少,用电脑调试过吗?

stm32的代码怎么写的?

W
ia2g

就是单片机没法工作 我是跟飞控板连接 卡死之后飞控板led都不闪 显示屏也不闪 就全部不工作

W
ia2g

@kidswong999 115200 分开是可以用的

I
网红小智智 星瞳科技

我说的是OpenMV串口发送的频率,比如每秒发送**多少次**数据过去。

W
ia2g

@kidswong999

import sensor, image, time

from pyb import UART

# Always pass UART 3 for the UART number for your OpenMV Cam.

# The second argument is the UART baud rate. For a more advanced UART control

# example see the BLE-Shield driver.

threshold_index = 0 # 0 for red, 1 for green, 2 for blue

thresholds = [(6,22,-12,16,-7, 20), # generic_red_thresholds

(30, 100, -64, -8, -32, 32), # generic_green_thresholds

(0, 30, 0, 64, -128, 0)] # generic_blue_thresholds

sensor.reset()

sensor.set_pixformat(sensor.RGB565)

sensor.set_framesize(sensor.QVGA)

sensor.skip_frames(time = 2000)

sensor.set_auto_gain(False) # must be turned off for color tracking

sensor.set_auto_whitebal(False) # must be turned off for color tracking

clock = time.clock()

uart = UART(3, 115200)

def find_max(blobs):

max_size=0

for blob in blobs:

if blob.pixels() > max_size:

max_blob=blob

max_size = blob.pixels()

return max_blob

while(True):

clock.tick()

img = sensor.snapshot()

blobs = img.find_blobs([thresholds[threshold_index]])

if blobs:

max_blob=find_max(blobs)

img.draw_rectangle(max_blob.rect())

img.draw_cross(max_blob.cx(), max_blob.cy())

a=int(max_blob.cx()/4)

b=int(max_blob.cy()/4)

dotx_high=(a>>8)&0XFF

dotx_low=a&0XFF

doty_high=(b>>8)&0XFF

doty_low=b&0XFF

print(a,b)

#uart.write(hex(170)+hex(175)+hex(242)+hex(7)+hex(0)+hex(175)+a1+hex(0)+b1+hex(12)+hex(242)+hex(1)+hex(0))

c=max_blob.pixels()

pix_high=(c>>8)&0XFF

pix_low=c&0XFF

xy=[0xAA, 0xAF,0XF2,0x07,dotx_high,dotx_low,doty_high,doty_low,pix_high,pix_low,0x01,0x00]

uart.write(bytes(xy))

time.sleep(10)

else:

xy=[0xAA, 0xAF,0XF2,0x07,0x00,0x00,0x00,0x00,0x0c,0xf2,0x00,0x00]

uart.write(bytes(xy))

time.sleep(10)

W
ia2g

@kidswong999 我是把色块的中心点坐标封装成数据包发送过去

I
网红小智智 星瞳科技

用USB转串口连接飞控,单独用电脑调试,用电脑发送数据给飞控,飞控有没有问题。

W
ia2g

@kidswong999 我试试

I
网红小智智 星瞳科技

还有可能是电路连接的问题。没准你线连错了,短路了什么的鬼知道。

W
ia2g

@kidswong999 openmv只运行helloworld的程序就是可以的 只有数据通信就不行

I
网红小智智 星瞳科技

用USB转串口连接飞控,单独用电脑调试,用电脑发送数据给飞控,飞控有没有问题?

I
网红小智智 星瞳科技

也就是这个协议你有没有验证过。如果没试过,肯定会挂。