你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

智能车超声波避障源码

[复制链接]
梦帝呱呱 发布时间:2018-6-29 14:50
基于stm32f1的智能小车超声波避障源码,仅供参考0 r. o& n+ T3 M; l
#include "stm32f10x.h"
3 m# k: m" t$ }6 a# I4 n  D#include "delay.h"/ b  P9 _& ?7 E2 F7 q3 z2 J
#include "motor.h"
; b0 i, \% T: F( h/ x; s#include "keysacn.h"
; F$ y* I3 `' l1 M2 U* H#include "IRSEARCH.h"- D/ {3 s5 n9 G5 y$ x
#include "IRAvoid.h"
1 Z2 K, Z7 e) I; s! d1 i# K#include "usart.h"
. W4 b0 {6 X  H2 b) ?#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
{
, j/ d; M9 W, ?+ m% ?: {+ E- ~3 F! T) b8 Z+ q6 @
//        ZYSTM32_brake(0);& V& r6 n, ?% j$ q* Y8 J! P
        SetJointAngle(90);
( p8 M" K# V% K- }8 {        delay_ms(100);- S, v+ @5 v3 r/ X5 k, J& b. i
        return UltrasonicWave_StartMeasure();
4 a) @' e1 x/ F- v, _/ v}, y4 W( h/ F3 m* K( \
int left_detection()1 w; i( Q5 X- U: p3 E8 x0 Z; t6 s
{
* a5 L4 ~/ }: u& U+ v$ i
; J3 ~* k4 i- Y6 @//        ZYSTM32_brake(0);
: \* E7 j4 ]3 q' i0 C        SetJointAngle(175);
8 B# E3 x& C* o+ x        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
}
: u/ t5 y& D/ x+ g/ gint right_detection()1 g0 b3 W9 g& Q; c1 i* A$ a2 r
{
  ?# K$ E4 o% |0 C: |1 ]7 u9 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();
6 d- H) S2 I  s}
4 E# l2 O+ N. o7 `5 j//extern int U_temp;
8 b4 w* z; e, X/ `/ L0 P  H/*) Z% O+ O: U2 x- b) P/ h
void ZYSTM32_run(int speed,int time);       //前进函数
; {7 w4 h6 p$ s7 u+ J6 I& tvoid ZYSTM32_brake(int time);               //刹车函数
: G9 [) j8 r% ^4 H8 E: Z$ Zvoid 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);      //后退函数
; l& c0 _# L& {4 L; ~' M*/# s- A: Z% L( c+ z. U$ F/ _3 y

* o" o+ n! ]: K4 Z; z  J. @ int main(void)- J& B: B8 X3 J) @) E
{       
1 s$ h) b$ D9 x0 X* @+ e" L   int Q_temp,L_temp,R_temp;
' g; J" K8 @5 o         delay_init();9 H3 a$ n. Q4 ~# e9 w
         KEY_Init();
0 a7 b- J3 P# r1 r; @! i5 `3 T         IRSearchInit();
' Z* f5 j  L7 p' F2 P, G         IRAvoidInit();1 o6 e! c# O+ P- _  b8 U3 Y
   Timerx_Init(5000,7199);                //10Khz的计数频率,计数到5000为500ms
& A1 p$ H6 E8 K1 I+ s- N4 r- A7 k0 A: Y. Z         UltrasonicWave_Configuration();        //对超声波模块初始化3 B4 Y: R. ~1 K8 e) q4 X
         uart_init(115200);
( b/ @+ P* h& l8 ]4 R/ E         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         
! @4 f5 J" F3 I1 u7 {( D         ZYSTM32_brake(500);
2 u" K% ^" `7 b% s6 O         keysacn();                : l1 N0 G) C% a0 {
        while(1)" c; a9 o; d! L) V- A& g
        {                 
/ `6 ~5 Q5 n9 ^        //        Q_temp = front_detection();+ f  ~8 T2 ?- q  U
        //  printf("测到的距离值为:%d\n",Q_temp);
9 S8 B$ x" U7 X' d                Q_temp = front_detection();
3 C8 ^- E6 O6 [  b                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);       
9 G- @" C8 B0 ^* F) R& N; o                       
" Z5 _2 H6 H; w* F* t" |" k- c' T                        L_temp=left_detection();//测量左边障碍物的距离值
2 ~' F* H+ b8 j! p                        delay_ms(500);0 g% x3 Q5 g+ y/ ]  r% L
                        R_temp=right_detection();//测量右边障碍物的距离值/ U+ j% s6 G% ^( j- ?
                        delay_ms(500);
' k" S3 F  M2 ]. _                        # [) 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
                        }                               
- X& s0 V) W7 c      else if(L_temp > R_temp)
; ?0 m0 }2 ~. }; C                        {' w9 D* I0 m; k
                                ZYSTM32_Left(60,700);
6 `% x. k; k3 K4 `3 n                                ZYSTM32_brake(500);& Y3 F" s: R3 k# a# W- B) a
                        }       
3 J" g7 b4 J: j$ c% @+ f4 v; r2 n      else& b, V. i4 w8 A7 G5 y0 R7 f. N
                        {
0 h2 K9 H; [% T& D1 p                                ZYSTM32_Right(60,700);
2 ]5 V2 H0 t2 J: _                                ZYSTM32_brake(500);                                        $ A3 H5 _: X$ b; C& x5 }
                        }                                                       
8 D) v# ^5 M3 }9 C5 I4 {                }        , o  j1 d+ k( ^
                else
, q9 Q8 c! O, R                {/ Y2 a3 K% H! \9 [: @" k3 w
                        ZYSTM32_run(60,10);
! `6 @) U% L$ D; C+ P/ n4 Z                }
* I0 p: o/ p0 N6 d        }
9 i( }! M+ Y1 @, R# V. W( W5 E }
, U" m- N' o0 ^- _; V  @, V1 [- s& d$ n, Z

! V7 J# F9 Y( n( N

7、ZYSTM32-A0 智能小车超声波避障实验(有舵机).zip

下载

7.49 MB, 下载次数: 24

赞 收藏 1 评论2 发布时间:2018-6-29 14:50

举报

2个回答
mxl818 回答时间:2018-8-16 16:03:08
st币扣了也没下载,什么事
david69chen 回答时间:2018-9-26 11:21:49
好东西,感谢分享!!
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版