|
基于stm32f1的智能小车超声波避障源码,仅供参考0 r. o& n+ T3 M; l #include "stm32f10x.h" #include "delay.h"/ b P9 _& ?7 E2 F7 q3 z2 J #include "motor.h" #include "keysacn.h" #include "IRSEARCH.h"- D/ {3 s5 n9 G5 y$ x #include "IRAvoid.h" #include "usart.h" #include "UltrasonicWave.h"9 |2 n* b9 G; ?4 w( R) k( S6 v% R: h* | #include "timer.h"$ M1 ^0 p# h ]. } #include "Server.h"% A- W% g* V, @0 j7 w Q% G* k$ }% J7 Z // 超声波转头函数0 |" v! g) u" O) e1 @* r int front_detection()+ C" F8 i' U9 \% d( U7 Y { + E- ~3 F! T) b8 Z+ q6 @ // ZYSTM32_brake(0);& V& r6 n, ?% j$ q* Y8 J! P SetJointAngle(90); delay_ms(100);- S, v+ @5 v3 r/ X5 k, J& b. i return UltrasonicWave_StartMeasure(); }, y4 W( h/ F3 m* K( \ int left_detection()1 w; i( Q5 X- U: p3 E8 x0 Z; t6 s { // ZYSTM32_brake(0); SetJointAngle(175); delay_ms(300);5 n! d" h8 F6 j2 U' _5 y- a; ` return UltrasonicWave_StartMeasure();5 L) t! d! n% Y4 D: l7 f } int right_detection()1 g0 b3 W9 g& Q; c1 i* A$ a2 r { + ]4 C; G4 e) H( d) j // ZYSTM32_brake(0);# w& d) v! }, G; W SetJointAngle(5);' S- |3 h2 Q$ |; Y$ L6 `+ S delay_ms(300);7 u* u& e' p- ?) l return UltrasonicWave_StartMeasure(); } //extern int U_temp; /*) Z% O+ O: U2 x- b) P/ h void ZYSTM32_run(int speed,int time); //前进函数 void ZYSTM32_brake(int time); //刹车函数 void ZYSTM32_Left(int speed,int time); //左转函数+ }7 z; q# @* y$ q, _' Z void ZYSTM32_Spin_Left(int speed,int time); //左旋转函数1 \1 z( c" o" J+ _( C# _ void ZYSTM32_Right(int speed,int time); //右转函数, T" M' q3 M: B5 b$ ` void ZYSTM32_Spin_Right(int speed,int time);//右旋转函数1 Z0 S5 g |0 h( m, p# L void ZYSTM32_back(int speed,int time); //后退函数 */# s- A: Z% L( c+ z. U$ F/ _3 y int main(void)- J& B: B8 X3 J) @) E { int Q_temp,L_temp,R_temp; delay_init();9 H3 a$ n. Q4 ~# e9 w KEY_Init(); IRSearchInit(); IRAvoidInit();1 o6 e! c# O+ P- _ b8 U3 Y Timerx_Init(5000,7199); //10Khz的计数频率,计数到5000为500ms UltrasonicWave_Configuration(); //对超声波模块初始化3 B4 Y: R. ~1 K8 e) q4 X uart_init(115200); TIM4_PWM_Init(7199,0); //初始化PWM6 l: T" Y7 w/ D1 r TIM5_PWM_Init(9999,143); //不分频,PWM频率=72*10^6/(9999+1)/(143+1)=50Hz ZYSTM32_brake(500); keysacn(); : l1 N0 G) C% a0 { while(1)" c; a9 o; d! L) V- A& g { // Q_temp = front_detection();+ f ~8 T2 ?- q U // printf("测到的距离值为:%d\n",Q_temp); Q_temp = front_detection(); if(Q_temp<60 && Q_temp>0) //测量距离值 3 t, J ^8 H; W {( u/ R# w. a& _: }/ P0 [" i. l ZYSTM32_brake(500); * r/ f- e$ Q9 R. W4 h ZYSTM32_back(60,500); : d# L. r6 K* E% x$ H ZYSTM32_brake(1000); L_temp=left_detection();//测量左边障碍物的距离值 delay_ms(500);0 g% x3 Q5 g+ y/ ] r% L R_temp=right_detection();//测量右边障碍物的距离值/ U+ j% s6 G% ^( j- ? delay_ms(500); # [) E: X4 p* }# c3 [1 \. K if((L_temp < 60 ) &&( R_temp < 60 ))//当左右两侧均有障碍物靠的比较近( z' [/ @* d: S6 J7 r2 d {4 y9 V _+ h, ]$ A Q" y: C: n ZYSTM32_Spin_Left(60,500);" \$ I u A, B$ j5 u, r3 i } else if(L_temp > R_temp) {' w9 D* I0 m; k ZYSTM32_Left(60,700); ZYSTM32_brake(500);& Y3 F" s: R3 k# a# W- B) a } else& b, V. i4 w8 A7 G5 y0 R7 f. N { ZYSTM32_Right(60,700); ZYSTM32_brake(500); $ A3 H5 _: X$ b; C& x5 } } } , o j1 d+ k( ^ else {/ Y2 a3 K% H! \9 [: @" k3 w ZYSTM32_run(60,10); } } } ; V @, V1 [- s& d$ n, Z |
7ãZYSTM32-A0 æºè½å°è½¦è¶ 声波é¿éå®éª(æèµæº).zip
下载7.49 MB, 下载次数: 24
| st币扣了也没下载,什么事 |
| 好东西,感谢分享!! |
微信公众号
手机版