@sdwo 成功了,openmv端需要强制数值类型转换
N
n615 发布的帖子
-
RE: 1:OpenMV端引入串口通信模块,运行速度变的巨慢? 串口传输length信息到stm32端,为什么会这样报错
-
RE: 1:OpenMV端引入串口通信模块,运行速度变的巨慢? 串口传输length信息到stm32端,为什么会这样报错
官方提供的测距离代码,添加串口通信代码到stm32端为什么会这样报错,而且openmv运行速度变得很慢
-
1:OpenMV端引入串口通信模块,运行速度变的巨慢? 串口传输length信息到stm32端,为什么会这样报错
openMV端代码:
# Measure the distance # # This example shows off how to measure the distance through the size in imgage # This example in particular looks for yellow pingpong ball. import sensor, image, time from pyb import UART uart=UART(3,9600) # For color tracking to work really well you should ideally be in a very, very, # very, controlled enviroment where the lighting is constant... red_threshold = (13, 49, 18, 61, 6, 47) # 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. K=730#the value should be measured while(True): clock.tick() # Track elapsed milliseconds between snapshots(). img = sensor.snapshot() # Take a picture and return the image. blobs = img.find_blobs([red_threshold]) if len(blobs) == 1: # Draw a rect around the blob. b = blobs[0] img.draw_rectangle((b[0:4]),color=(255,0,0)) # rect img.draw_cross(b[5], b[6]) # cx, cy Lm = (b[2]+b[3])/2 length = K/Lm print(length) uart.write(length) time.sleep_ms(1000) #print(Lm) #print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while # connected to your computer. The FPS should increase once disconnected.
STM32端代码:
#include "stm32f10x.h" // Device header #include "Delay.h" #include "OLED.h" #include "Servo.h" #include "Key.h" #include "stdio.h" uint8_t KeyNum; float Angle; uint8_t count = 0; void USART1_Init(void); float res=0; int main(void) { NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); OLED_Init(); Delay_ms (1000); USART1_Init(); OLED_ShowString(1, 1, "COMEOUT:"); while (1) { OLED_ShowChar(2, 1, res); } } void USART1_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitSture; NVIC_InitTypeDef NVIC_InitSture; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); USART_InitSture.USART_BaudRate = 9600; USART_InitSture.USART_HardwareFlowControl =USART_HardwareFlowControl_None; USART_InitSture.USART_Mode =USART_Mode_Tx|USART_Mode_Rx; USART_InitSture.USART_Parity =USART_Parity_No; USART_InitSture.USART_StopBits =USART_StopBits_1; USART_InitSture.USART_WordLength =USART_WordLength_8b; USART_Init (USART1 ,&USART_InitSture); USART_ITConfig (USART1 ,USART_IT_RXNE ,ENABLE ); USART_Cmd (USART1 ,ENABLE ); NVIC_InitSture.NVIC_IRQChannel =USART1_IRQn; NVIC_InitSture.NVIC_IRQChannelCmd=ENABLE ; NVIC_InitSture.NVIC_IRQChannelPreemptionPriority =0; NVIC_InitSture.NVIC_IRQChannelSubPriority =1; NVIC_Init(&NVIC_InitSture ); } void USART1_IRQHandler(void) { if(USART_GetITStatus (USART1 ,USART_IT_RXNE )!=RESET ) { res=USART_ReceiveData(USART1); } } int fputc(int ch, FILE *f) { USART_SendData(USART1, (unsigned char) ch); while( USART_GetFlagStatus(USART1,USART_FLAG_TC)!= SET); return (ch); }