欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
PIXY視覺(jué)追蹤程序
[打印本頁(yè)]
作者:
湘江舊跡秋心
時(shí)間:
2019-6-29 11:29
標(biāo)題:
PIXY視覺(jué)追蹤程序
pixy視覺(jué)追蹤模塊,使用串口通信,只需在主程序調(diào)用即可。
源程序如下:
#include "pixy/pixy.h"
uint16_t a,b,c,d,e;
uint8_t Raw_Data[40];//原始數(shù)據(jù)大包,為解串準(zhǔn)備
uint8_t counter;//計(jì)數(shù)用
void usart2_init(u32 baudRate)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_USART2,ENABLE);
//UART2 GPIO TX配置
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//UART2 GPIO RX配置
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//UART 數(shù)據(jù)格式配置
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx|USART_Mode_Rx;
USART_InitStructure.USART_BaudRate = baudRate;
USART_Init(USART2, &USART_InitStructure);
//中斷配置
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_Cmd(USART2, ENABLE); //使能串口
USART_ClearFlag(USART2, USART_FLAG_TC);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//開(kāi)啟相關(guān)中斷
//Usart NVIC 配置
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;//串口2中斷通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;//搶占優(yōu)先級(jí)1
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0; //子優(yōu)先級(jí)0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根據(jù)指定的參數(shù)初始化VIC寄存器、
}
void USART2_IRQHandler(void) //Pixy_Uart_ReadData
{
int i;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //等待讀取數(shù)據(jù)寄存器DR
{
USART_ClearITPendingBit(USART2,USART_IT_RXNE);
Raw_Data[counter] = USART_ReceiveData(USART2);
counter++;
if(counter == 40)
{
counter=0; //重新回?cái)?shù)組頭
for(i=0;i<40;i++) //計(jì)算更新一次坐標(biāo)
{
if((Raw_Data[i] == 0x55)&&(Raw_Data[i+1] == 0xaa)&&(Raw_Data[i+2] == 0x55)&&(Raw_Data[i+3] == 0xaa))
{
a= Raw_Data[i+6] + Raw_Data[i+7]*256; // a 顏色代號(hào)
b= Raw_Data[i+8] + Raw_Data[i+9]*256; // b X坐標(biāo)
c= Raw_Data[i+10] + Raw_Data[i+11]*256; // c Y坐標(biāo)
d= Raw_Data[i+12] + Raw_Data[i+13]*256; // d width
e= Raw_Data[i+14] + Raw_Data[i+15]*256; // e height
break; // 跳出for循環(huán)
}
}
}
}
}
復(fù)制代碼
所有資料51hei提供下載:
pixy.zip
(1.67 KB, 下載次數(shù): 13)
2019-6-29 11:29 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1