欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
基于機器視覺的網(wǎng)球識別與回收裝置—智能小車STM32代碼
[打印本頁]
作者:
1092648746
時間:
2019-6-5 21:38
標題:
基于機器視覺的網(wǎng)球識別與回收裝置—智能小車STM32代碼
好久沒逛51hei電子論壇了,最近看到有人詢問智能小車(其實很多人都喜歡做小車),又想起自己寫過智能小車,上傳了,讓大家參考下。
實物忘了放哪就不拍了,注意是拿來參考的,不是讓你直接燒錄的…………,直接燒錄也沒用是吧
。當時靠這個代碼拿了個電賽省二,新人們可以參考下,STM32的初學者也可以參照下思路,設計出一款自己的小車…………
好的,就這樣吧。
對了,第二個py文件是OPENMV的代碼,要用OPENMV攝像頭做顏色識別的同學也可參考下
0.png
(4.91 KB, 下載次數(shù): 62)
下載附件
2019-6-6 04:30 上傳
單片機源程序如下:
/**************************************************************************************
* 基于機器視覺的網(wǎng)球識別與回收裝置 *
摘要:本設計旨在制作出一個能夠在網(wǎng)球場上自動搜尋網(wǎng)球并自動回收網(wǎng)球的裝置。
本設計是以STM32單片機為核心設備,通過OPENMV攝像頭對網(wǎng)球進行圖像識別并回傳,
回傳數(shù)據(jù)處理后STM32將驅(qū)動回收裝置自動行駛到目標位置,實現(xiàn)將球自動拾取并存
放的功能。本設計基本模塊包括MCU、驅(qū)動板、攝像頭、撿球裝置、收集裝置和電源。
其中MCU為STM32F103核心板,驅(qū)動板為L293D電機驅(qū)動板,攝像頭為OPENMV,撿球裝
置及收集裝置為定制結構。
適用單片機:STM32F103ZET6 適用開發(fā)板:野火科技 F103霸道開發(fā)板
默認時鐘頻率:72MHZ
***************************************************************************************/
//連接方式 :請參考interface.h文件
#include "stm32f10x.h"
#include "interface.h" //STM32各種接口
#include "LCD1602.h" //1602液晶屏(提供坐標可視化)
#include "IRCtrol.h" //定時及中斷相關
#include "motor.h" //電機及舵機驅(qū)動
#include "uart.h" //串口相關
#include "redvoid.h" //紅外避障相關
#include "UltrasonicCtrol.h"//超聲波模塊相關(已棄用)
/******注意:各個子文件并未清晰注釋,請讀者自行研究****/
/**************************************************************************************/
//全局變量定義
unsigned int speed_count=0;//占空比計數(shù)器 50次一周期
char front_left_speed_duty=SPEED_DUTY;
char front_right_speed_duty=SPEED_DUTY;
char behind_left_speed_duty=SPEED_DUTY;
char behind_right_speed_duty=SPEED_DUTY;
unsigned int tick_5ms = 0;//5ms計數(shù)器,作為主函數(shù)的基本周期
unsigned int tick_1ms = 0;//1ms計數(shù)器,作為電機的基本計數(shù)器
unsigned int tick_200ms = 0;//刷新顯示
unsigned int tick_10ms = 0;
unsigned int tick_500ms = 0;
unsigned int zhuanjiao; //舵機角度參考值
unsigned int ServoFlag; //舵機標志位
unsigned int DetectFlag; //紅外避障標志位
unsigned int DataBuf_x[3]; // 攝像頭傳回的x坐標數(shù)據(jù)
unsigned int DataBuf_y[3]; // 攝像頭傳回的y坐標數(shù)據(jù)
unsigned int buf_i;
int x_pos;
int y_pos;
int x_pos_last;
int y_pos_last;
int Cam_key=0;
int Turn_Flag=0;
char ctrl_comm = COMM_STOP;//控制指令
char ctrl_comm_last = COMM_STOP;//上一次的指令
unsigned char continue_time=0;
unsigned char bt_rec_flag=0;//藍牙控制標志位
unsigned char redray_flag=0;//紅外循跡標志位
unsigned char duoji_count=0;
unsigned char RecFlag;
/*****************************************************************************************/
//定時器周期是0.1ms
//舵機PWM周期是20ms,0 - 180°分別對應 0.5 - 2.5ms 的脈寬
//變量zhuanjiao可調(diào)范圍為 5 - 25 對應 0 - 180°,當zhuanjiao = 15 時對應90°
//為了讓舵機運行更精確,建議向右或向左轉(zhuǎn)是不要使用0°或180°,建議向中間靠近一點
//右轉(zhuǎn)時選用zhuanjiao=7 左轉(zhuǎn)時用zhuanjiao=23
/*******************************************************************************
* 函 數(shù) 名 :DuojiMid
* 函數(shù)功能 :舵機下壓
* 輸 入 :無
* 輸 出 :無
*******************************************************************************/
void DuojiMid()
{
zhuanjiao++;
Delayms(20);
}
/*******************************************************************************
* 函 數(shù) 名 :DuojiRight
* 函數(shù)功能 :舵機上升
* 輸 入 :無
* 輸 出 :無
*******************************************************************************/
void DuojiRight()
{
zhuanjiao--;
Delayms(20);
}
//void DuojiLeft()
//{
// zhuanjiao = 230;
// Delayms(300);
//}
/*******************************************************************************
* 函 數(shù) 名 :DuojiRight
* 函數(shù)功能 :舵機相關動作
* 輸 入 :無
* 輸 出 :無
*******************************************************************************/
void Duoji() //舵機動作函數(shù)
{
int i;
zhuanjiao=100;
CarStop();
for(i=0;i<110;i++)
{
DuojiMid(); //zhuanjiao ++ 向下壓
}
for(i=0;i<110;i++)
{
DuojiRight(); //zhuanjiao -- 向上抬起
}
}
/*******************************************************************************
* 函 數(shù) 名 :search
* 函數(shù)功能 :小車處理攝像頭發(fā)送的坐標,根據(jù)不同情況執(zhí)行不同功能
* 輸 入 :無
* 輸 出 :無
*******************************************************************************/
void search()
{
if(Turn_Flag==1)
{
if(x_pos_last == x_pos)
{
CarRight();
}
}
else{
if(x_pos>200)
{
CarRight(); //修正轉(zhuǎn)右
}
else if(x_pos<120)
{
CarLeft(); //修正轉(zhuǎn)左
}
else if(120<x_pos && x_pos<200) //x坐標在區(qū)間內(nèi)
{
if(y_pos<150) //y坐標bu在區(qū)間內(nèi)
{
CarBack(); //go straight,wrong name
}
if(y_pos>180)
{
CarGo(); //go backwards,wrong name
}
else if(150<y_pos && y_pos<180 )
{
if(VOID_R_IO==BARRIER_Y||VOID_M_IO==BARRIER_Y||VOID_L_IO==BARRIER_Y)
Delayms(10);
if(VOID_R_IO==BARRIER_Y||VOID_M_IO==BARRIER_Y||VOID_L_IO==BARRIER_Y)
Duoji();
}
}
}
if( (x_pos_last - x_pos) > 50 || (x_pos_last - x_pos) < -50 )
{
CarRight();
} //比較x軸與前一次值避免兩球同時判斷混亂
x_pos_last=x_pos;
y_pos_last=y_pos; //記錄上一次的坐標
}
/*******************************************************************************
* 函 數(shù) 名 :TurnBack
* 函數(shù)功能 :小車強制右轉(zhuǎn)(適用于紅外避障)
* 輸 入 :無
* 輸 出 :無
*******************************************************************************/
void TurnBack()
{
CarRight();
Delayms(1000);
}
/*******************************************************************************
* 函 數(shù) 名 :main
* 函數(shù)功能 :主函數(shù)
* 輸 入 :無
* 輸 出 :無
*******************************************************************************/
int main(void)
{
unsigned int i;
delay_init();
GPIOCLKInit();
UserLEDInit();
LCD1602Init();
IRCtrolInit();
TIM2_Init();
TIM5_Init();
MotorInit();
//UltraSoundInit();
RedRayInit();
ServoInit();
USART1Conf(9600);
USART3Conf(9600);
Delayms(500);
for(i=0;i<3;i++)
{
DataBuf_x[i]=0x30;
DataBuf_y[i]=0x30;
}
/******************************************************************************************/
while(1)
{
if(tick_5ms >= 5)
{
tick_5ms = 0;
tick_200ms++;
if(tick_200ms >= 40)
{
tick_200ms = 0;
LEDToggle(LED_PIN);
}
continue_time--;//200ms 無接收指令就停車
if(continue_time == 0)
{
continue_time = 1;
CarStop();
}
LCD1602WriteCamData();
x_pos=(DataBuf_x[0]-0x30)*100+(DataBuf_x[1]-0x30)*10+(DataBuf_x[2]-0x30);
y_pos=(DataBuf_y[0]-0x30)*100+(DataBuf_y[1]-0x30)*10+(DataBuf_y[2]-0x30);
if(Cam_key==1)
{
search();
}
if(VOID_R_IO==BARRIER_Y||VOID_M_IO==BARRIER_Y||VOID_L_IO==BARRIER_Y)
{
Delayms(10);
if (VOID_R_IO==BARRIER_Y && VOID_M_IO==BARRIER_Y && VOID_L_IO==BARRIER_Y) //檢測前方是不是墻,是的話就掉頭
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
小車V6.1.7z
(618.95 KB, 下載次數(shù): 54)
2019-6-5 21:32 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
湘知權
時間:
2020-6-18 11:26
謝謝 分享
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1