600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 避障跟随测距c语言程序 红外避障小车c语言程序.pdf

避障跟随测距c语言程序 红外避障小车c语言程序.pdf

时间:2024-03-09 10:08:43

相关推荐

避障跟随测距c语言程序 红外避障小车c语言程序.pdf

智能小车红外避障智能小车红外避障 c 语言程序语言程序 #include bit RandomFactor = 0 ; bit RandomFactorBuf = 0 ; #include #define FLeftMotor P0_2 = 1 ; P0_3 = 0 #define BLeftMotor P0_2 = 0 ; P0_3 = 1 #define FRightMotor P0_5 = 1 ; P0_4 = 0 #define BRightMotor P0_5 = 0 ; P0_4 = 1 #define LeftStop P0_2 = 0 ; P0_3 = 0 #define RightStop P0_4 = 0 ; P0_5 = 0 #define CarStop P0_2 = 0 ; P0_3 = 0 ; P0_4 = 0 ; P0_5 = 0 #define RightSenser P0_0 #define LeftSenser P0_1 //******************************************************** // 左转 //******************************************************** void TurnLeft_1() { LeftStop ; FRightMotor ; } //******************************************************** // 快速左转 //******************************************************** void TurnLeft_Fast() { BLeftMotor ; FRightMotor ; } //******************************************************** // 右转 //******************************************************** void TurnRight_1() { RightStop ; FLeftMotor ; } //******************************************************** // 快速右转 //******************************************************** void TurnRight_Fast() { BRightMotor ; FLeftMotor ; } //******************************************************** // 用倒退的方式进行车头右转 //******************************************************** void BTurnRight_1() { LeftStop ; BRightMotor ; } //******************************************************** // 用倒退的方式进行车头左转 //******************************************************** void BTurnLeft_1() { RightStop ; BLeftMotor ; } //******************************************************** // 前进 //******************************************************** void FCar() { FLeftMotor ; FRightMotor ; } //******************************************************** // 后退 //******************************************************** void BCar() { BLeftMotor ; BRightMotor ; } //******************************************************** // 壁障程序 //******************************************************** void Obstacle_Avoid(void) { if(RightSenser } if((!RightSenser) } if(RightSenser } if(!(RightSenser || LeftSenser)) { RandomFactorBuf = RandomFactor ; while (!(RightSenser || LeftSenser)) { if(RandomFactorBuf) { BTurnLeft_1() ; delay (300) ; } if(!RandomFactorBuf) { BTurnRight_1() ; delay (300) ; } } } if(!PWM) { LeftStop ; RightStop ; } } //******************************************************** // 跟随程序 //******************************************************** void Follow(void) { if(RightSenser RightStop; } if((!RightSenser) } if(RightSenser } if(!(RightSenser || LeftSenser)) { FCar() ; } } //******************************************************** //******************************************************** main() { Timer0Setup(500) ; Timer1Setup(50) ; Obstacle_Avoid() ; // Follow() ; }

展开阅读全文

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。