logo

问下openmv和stm32f103zet6的通信问题,问下怎么改发的是[x,y],能进这个中断函数,但是返回值不对。

2018-07-22 11:30
X
_18601068786
# Blob Detection and uart transport
import sensor, image, time
from pyb import UART
import json
# For color tracking to work really well you should ideally be in a very, very,
# very, controlled enviroment where the lighting is constant...
yellow_threshold   = (32, 84, -16, 25, -62, -37)
# You may need to tweak the above settings for tracking green things...
# Select an area in the Framebuffer to copy the color settings.

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # use RGB565.
sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
sensor.skip_frames(10) # Let new settings take affect.
sensor.set_auto_whitebal(False) # turn this off.
clock = time.clock() # Tracks FPS.

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):
    img = sensor.snapshot() # Take a picture and return the image.
    blobs = img.find_blobs([yellow_threshold])
    if blobs:
        max_blob=find_max(blobs)
        print('sum :', len(blobs))
        img.draw_rectangle(max_blob.rect())
        img.draw_cross(max_blob.cx(), max_blob.cy())

        output_str="[%d,%d]" % (max_blob.cx(),max_blob.cy()) #方式1
        #output_str=json.dumps([max_blob.cx(),max_blob.cy()]) #方式2
     #   print('you send:',output_str)
        uart.write(output_str+'\r\n')

void USART3_IRQHandler(void)

{ unsigned char a[4];

unsigned char b[4];

char data;

int test=0;

int i=0;

int j=0;

if(USART_GetITStatus(USART3,USART_IT_RXNE)!=RESET)

{

data = USART_ReceiveData(USART3);

// test=atoi(( char const *)data);

// printf("%d\r\n",test);

if(data=='['){mode=0;}

if(data==','){mode=1;}

if(data==']'){mode=2;}

if(mode==0){

a[i]=(data-'0');

i++;

}

else if(mode==1){

b[j]=(data-'0');

j++;

}

else if(mode==2){

x=0;y=0;i=0;j=0;

mid_input=(a[1]-'0')+(a[2]-'0')*10+(a[3]-'0')*100;

mid_vertical=(a[1]-'0')+(a[2]-'0')*10+(a[3]-'0')*100;

a[0]=0;

a[1]=0;

a[2]=0;

a[3]=0;

b[0]=0;

b[1]=0;

b[2]=0;

b[3]=0;

printf("x=%d,y=%d\r\n",mid_input,mid_vertical);

}

}

651d5689-bdda-42fd-9331-f704085d1b3e.png