# 手绘轨迹（STM32触摸屏）控制小车运动

3782人阅读 评论(2)

1. 路径分析算法

Θ3 = Θ2 - Θ1，Θ5 = Θ4 - Θ3；

Move_Step(Path_Set_x[x-2],Path_Set_y[x-2],Path_Set_x[x-1],Path_Set_y[x-1]);
Ang[x-2]=Time_Move_Buf*(180/pi);
b = (int)(Time_Move_Buf+0.5) + 32;   //解码时前进的时间要-32
if(x==2) a=Ang[0];
else
a=(int)((Ang[x-2] - Ang[x-3])/Speed_Turn + 0.5) + 150;  //解码时 大于150的向右转，小于150的向左转
Time_Turn[x-2] = (unsigned char)a;
Time_Move[x-2] = (unsigned char)b;

void Move_Step(double Now_x,double Now_y,double Next_x,double Next_y)
{
Time_Turn_Buf = atan(Next_x - Now_x)/(Next_y - Now_y);
Time_Move_Buf = (sqrt((Next_x - Now_x)*(Next_x - Now_x)+(Next_y - Now_y)*(Next_y - Now_y)))/Speed_Move;
} 

2. 不同频率单片机之间的无线通信

delayms(250);

1.

2.

3.

4.

STM32控制触摸屏部分：

#include "led.h"
#include "delay.h"
#include "sys.h"
#include "key.h"
#include "usart.h"
#include "lcd.h"
#include "touch.h"
#include "spi.h"
#include "flash.h"
#include "touch.h"
#include "stdlib.h"
#include "24l01.h"
#include "math.h"
#define pi 3.1415926535
//double Speed_Move = 1.0,Speed_Turn = pi/3;	//已知的量：前行速度 转弯速度

int Time_Turn_Buf;
double Time_Move_Buf;
u8 x;
//收发都做在一个函数里面,通过按键来确定进入发送模式,还是接收模式
void Move_Step(int Now_x,int Now_y,int Next_x,int Next_y)
{
// 	if(Next_y == Now_y)
// 	{
// 		if(Next_x > Now_x)
// 			Time_Turn_Buf = pi/2.0;
// 		if(Next_x < Now_x)
// 			Time_Turn_Buf = -pi/2.0;
// 		if(Next_x == Now_x)
// 			Time_Turn_Buf = 0;
// 	}
// 	else
// 	{
//	}
//	Time_Turn_Buf = atan((Next_x - Now_x)/(Next_y - Now_y));			//在绝对坐标系下的坐标差
if(Now_x == Next_x && Next_y>Now_y)
Time_Turn_Buf = 2;//直走
else	if(Next_x>Now_x && Next_y>Now_y)
Time_Turn_Buf = 3;//右转45
else	if(Next_y==Now_y && Next_x>Now_x)
Time_Turn_Buf = 4;//右转90
else	if(Next_y<Now_y && Next_x>Now_x)
Time_Turn_Buf = 5;//右转135
else	if(Next_x<Now_x && Next_y>Now_y)
Time_Turn_Buf = 1;//左转45
else	if(Next_x<Now_x && Next_y==Now_y)
Time_Turn_Buf = 8;//左转90
else	if(Next_y<Now_y && Next_x<Now_x)
Time_Turn_Buf = 7;//左转135
else	if(Next_y<Now_y && Next_x==Now_x)
Time_Turn_Buf = 6;//后退
else	if(Next_x==Now_x && Next_y==Now_y)
Time_Turn_Buf = 10;//不动
else
Time_Turn_Buf = 3;//直走
Time_Move_Buf = sqrt(((double)Next_x - Now_x)*((double)Next_x - Now_x)+((double)Next_y - Now_y)*((double)Next_y - Now_y));
}

void Set_Path(void)
{
int i ;
LCD_Clear(WHITE);
POINT_COLOR=BLUE;
LCD_ShowString(0,0,"Set Path:");
POINT_COLOR=BLACK;
for(i=32;i<=230;i++)
Draw_Big_Point(i,33),Draw_Big_Point(i,253);
for(i=32;i<=253;i++)
Draw_Big_Point(33,i),Draw_Big_Point(230,i);
}

void Show_Send_Start(void)
{
LCD_Clear(WHITE);
POINT_COLOR=BLUE;
LCD_ShowString(20,40,"Sending ... ...");
}

/**********************************************/
int main(void)
{
int a,b;
unsigned char Time_Turn[50];
unsigned char Time_Move[50];
u8 Path_Set_x[80],Path_Set_y[80];
u8 Key_Press;
u8 Set_Delay=0;
SystemInit();
delay_init(72);
NVIC_Configuration();
uart_init(9600);
LED_Init();
KEY_Init();
LCD_Init();
NRF24L01_Init();
Touch_Init();
delay_ms(10);

POINT_COLOR=RED;
LCD_ShowString(60,50,"STM32 and 51");
LCD_ShowString(60,70,"2013/11/10");
LCD_ShowString(0,300,"Press KEY0 To Continue .") ;
while(NRF24L01_Check())//检测不到24L01
{
LCD_ShowString(60,130,"24L01 Check Failed!");
delay_ms(500);
delay_ms(500);
LED0=!LED0;//DS0闪烁
}
/****************************/
// 	do{
// 		 Key_Press=KEY_Scan();
// 		} while(Key_Press!=1);
//
Key_Press==1;
Set_Path();

while(1)
{
Key_Press=KEY_Scan();
if(Pen_Point.Key_Sta==Key_Down)//触摸屏被按下
{
Pen_Int_Set(0);//关闭中断
do
{
Convert_Pos();
Pen_Point.Key_Sta=Key_Up;
if(Pen_Point.X0>216&&Pen_Point.Y0<16) Set_Path();//清除
else
{
Draw_Big_Point(Pen_Point.X0,Pen_Point.Y0);
if(Set_Delay==0)
{
if(x>50)	x=0;	//限制数组大小
Path_Set_x[x] = Pen_Point.X0 / 15;           //11 18 点缩小20倍
Pen_Point.Y0 = 253 - Pen_Point.Y0 + 32;
Path_Set_y[x++]=Pen_Point.Y0 / 15;
/********限制判断 避免不明原因造成的错误点********/
if((Path_Set_x[x-1]-Path_Set_x[x-2])>40||(Path_Set_y[x-1]-Path_Set_y[x-2])>40)
x--;
if((Path_Set_x[x-1]==Path_Set_x[x-2])&&(Path_Set_y[x-1]==Path_Set_y[x-2]))
x--;
/*****************************************************/
if(x > 1)
{
Move_Step(Path_Set_x[x-2],Path_Set_y[x-2],Path_Set_x[x-1],Path_Set_y[x-1]);

// 								Time_Turn_Buf=Time_Turn_Buf*(180.0/pi);
// 								a = (int)(Time_Turn_Buf + 0.5);
a = Time_Turn_Buf + 65 ;   //此为角度  -90 至 90 对应转化为   60 至 240
b = (int)(Time_Move_Buf + 65 + 0.5) ;   //此为两点距离  0 至 200 对应转化为 40  至 240
if(a<-100.0||a>100.0)
a = 'S';
if(b<39||b>241)
b = 'S';
// 								Time_Turn_A[x-2] = a ;			//大于150有问题 小于150没问题
Time_Move[x-2] = (unsigned char)(b);
//
// 								if(x == 2)
//  									Time_Turn[x-2] = (unsigned char)(Time_Turn_A[x-2] + 150);
//  								else if(x >= 3)
// 									Time_Turn[x-2] = (unsigned char)(Time_Turn_A[x-2] - Time_Turn_A[x-3] + 150);
Time_Turn[x-2] = (unsigned char)(a);
}
/*****************************************************/
}
GPIOC->ODR|=1<<1;
Set_Delay++;	  				//以时间为标准 后期改为距离
if(Set_Delay==50)
Set_Delay=0;
}
}while(PEN==0);
Pen_Int_Set(1);
}else delay_ms(10);
if(Key_Press==1)
{
LCD_Clear(WHITE);
memset(Path_Set_x,0,sizeof(Path_Set_x));
memset(Path_Set_x,0,sizeof(Path_Set_x));
Set_Path();
}
if(Key_Press==2)
{
u8 i;
LCD_Clear(WHITE); //清屏
POINT_COLOR=BLUE;
LCD_ShowString(0,0,"PATH is:");
POINT_COLOR=BLACK;//红色画笔											白底蓝提示红字显示路迹
for(i=0;i<x;i++)
{
Draw_Big_Point(Path_Set_x[i] * 15,250 + 32 - 15 * Path_Set_y[i] );//循环体   画出轨迹
}
/******************************/
Key_Press=0;
while(1)
{
Key_Press=KEY_Scan();
if(Key_Press==3)
{
Show_Send_Start();
/***********发送函数***********/
TX_Mode();
while(1)
{
if(NRF24L01_TxPacket(Time_Turn)==TX_OK)
{
if(NRF24L01_TxPacket(Time_Move)==TX_OK)
{
LCD_ShowString(10,150,"Sended DATA(Time_Turn):");

LCD_ShowString(0,170,Time_Turn);
LCD_ShowString(0,210,Time_Move);
LCD_ShowString(0,250,Path_Set_x);
LCD_ShowString(0,290,Path_Set_y);
}

///加上结束语句
while(1);
}else
{
LCD_ShowString(0,170,Time_Turn);
LCD_ShowString(0,210,Time_Move);
LCD_ShowString(0,250,Path_Set_x);
LCD_ShowString(0,290,Path_Set_y);
LCD_ShowString(60,140,"Send Failed ");
while(1);
//							LCD_Fill(0,188,240,218,WHITE);//清空上面的显示
};
//						LED0=!LED0;
//						delay_ms(1000);
}
//					Show_Send_End();
//					break;
}
}
}
if(Key_Press==3)//wk_up按下，表示轨迹绘制完成  准备发送数据给飞行器   （NRF24L01）
{
Show_Send_Start();
/****************发送函数*************/
TX_Mode();
while(1)
{
if(NRF24L01_TxPacket(Time_Turn)==TX_OK)
{
if(NRF24L01_TxPacket(Time_Move)==TX_OK)
{
LCD_ShowString(10,150,"Sended DATA(Time_Turn):");

LCD_ShowString(0,170,Time_Turn);
LCD_ShowString(0,210,Time_Move);
LCD_ShowString(0,250,Path_Set_x);
LCD_ShowString(0,290,Path_Set_y);

///加上结束语句
while(1);
}
}else
{
LCD_ShowString(0,170,Time_Turn);
LCD_ShowString(0,210,Time_Move);
LCD_ShowString(0,250,Path_Set_x);
LCD_ShowString(0,290,Path_Set_y);
LCD_ShowString(60,170,"Send Failed ");
//		LCD_Fill(0,188,240,218,WHITE);//清空上面的显示
while(1);
};
// 				LED0=!LED0;
// 				delay_ms(1000);
}
//			Show_Send_End();
}
}
}


STC12C5160S2（增强型51）：

#include "reg52.h"
#include "string.h"
#include "lcd.h"
#include "24l01.h"
#include "car.h"
#define uint unsigned int
#define uchar unsigned char
sbit LED=P1^6;
//==============================
//		延时函数
//=========================

void delayms(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void delay_turn(unsigned int z)
{
unsigned int x,y;
for(x=z; x>0; x--)
for(y=1848; y>0; y--);
}
void delay_s(unsigned int xs)
{
unsigned int i ,j;
for(i=xs*1000;i>0;i--)
for(j=110;j>0;j--);
}
/*====================================
主函数
====================================*/
void main()
{
unsigned char Time_Turn_Buf[41],Time_Move_Buf[41];
uchar i,key;
uchar mode;
int j ;
LCD_Init();
LCD_CLR();

LCD_W_Word(1,0,"       ");
LCD_W_Word(2,0,"             ");
LCD_W_Word(3,0,"TIME: 2013-11-12 ");
LCD_W_Word(4,0,"             !  ");
for(i=0;i<8;i++)
{
//delay_ms(250);
delayms(250);
}
NRF24L01_Init();
//	TIMER0_Init();
//	LCD_CLR();
while(NRF24L01_Check())
{
delayms(250);
delayms(250);
delayms(250);
delayms(250);
delayms(250);
delayms(250);
delayms(250);
delayms(250);
LCD_W_Word(1,0,"                ");
LCD_W_Word(2,0,"                ");
LCD_W_Word(3,0,"                ");
LED=~LED;//DS0闪烁
delayms(250);
delayms(250);
delayms(250);
delayms(250);
delayms(250);
delayms(250);
delayms(250);
delayms(250);
}
//	LCD_CLR();
//	LCD_W_Word(2,0,"KEY0: 发送模式");
//	LCD_W_Word(3,0,"KEY1: 接收模式");
intime();
//	LCD_CLR();

mode = RX;			  //改变51单片机的状态：TX=发送 RX=接受
if(mode==TX)
{
LCD_W_Word(1,0," NRF24L01 TX_Mode");
TX_Mode();
mode=32;//从空格键开始
while(1)
{
if(NRF24L01_TxPacket(Time_Turn_Buf)==TX_OK)
{
LCD_W_Word(2,0,"Sended DATA:");
LCD_POS(2,0);
for(i=0;i<16;i++)
{
LCD_Write_dat(Time_Turn_Buf[i]);
}
LCD_POS(3,0);
for(i=16;i<32;i++)
{
LCD_Write_dat(Time_Turn_Buf[i]);
}

key=mode;
for(i=0;i<32;i++)
{
key++;
if(key>'~')
key=32;
Time_Turn_Buf[i]=key;
}
mode++;
if(mode>'~')
mode=32;
Time_Turn_Buf[32]=0;
for(i=0;i<10;i++)
{
delayms(200);
}
}
else
{
LCD_W_Word(2,0,"发送错误");
delayms(250);
delayms(250);
delayms(250);
delayms(250);
}
LCD_W_Word(2,0,"                ");
LED=~LED;
delayms(250);
delayms(250);
delayms(250);
delayms(250);
}
}
else if(mode==RX)
{
LCD_W_Word(0,0,"NRF24L01 RX_Mode");
RX_Mode();
while(1)
{
if(NRF24L01_RxPacket(Time_Turn_Buf)==0) //以150为界限
{
if(NRF24L01_RxPacket(Time_Move_Buf)==0) //要减去-32
{
/**********************************开始对数组解码*******************************/
for(j = 0;j < strlen(Time_Move_Buf) - 3;j++) // forward的延时要求精确的话需要联系Turn_Move_Buf
{											 //	转弯的要是不需要联系其他的东西只需要将后面的延时的时间调试好
if(j==0)
{
if(Time_Turn_Buf[0]=='B')	{left();delay_turn(150);forward();delay_s(4);stop();delay_turn(1);}
else if(Time_Turn_Buf[0]=='C') 	{forward();delay_s(4);stop();delay_turn(2);}
else if(Time_Turn_Buf[0]=='D')	{right();delay_turn(150);forward();delay_s(4);stop();delay_turn(1);}
else if(Time_Turn_Buf[0]=='E')	{right();delay_turn(300);forward();delay_s(4);stop();delay_turn(1);}
else if(Time_Turn_Buf[0]=='F')	{right();delay_turn(450);forward();delay_s(4);stop();delay_turn(1);}
else if(Time_Turn_Buf[0]=='G')	{right();delay_turn(600);forward();delay_s(4);stop();delay_turn(1);}
else if(Time_Turn_Buf[0]=='H')	{left();delay_turn(450);forward();delay_s(4);stop();delay_turn(1);}
else if(Time_Turn_Buf[0]=='I')	{left();delay_turn(300);forward();delay_s(4);stop();delay_turn(1);}
else {stop();delayms(1);}
}
else
{
if(Time_Turn_Buf[j-1]=='B')
{
if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==7)	{left();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==0) 	{forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==1)	{right();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==2)	{right();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==3)	{right();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==4)	{right();delay_turn(600);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==5)	{left();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==6)	{left();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else {stop();delayms(1);}
}
if(Time_Turn_Buf[j-1]=='C')
{
if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-1)	{left();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==0) 	{forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==1)	{right();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==2)	{right();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==3)	{right();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==4)	{right();delay_turn(600);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==5)	{left();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==6)	{left();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else {stop();delayms(1);}
}
if(Time_Turn_Buf[j-1]=='D')
{
if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-1)	{left();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==0) 	{forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==1)	{right();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==2)	{right();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==3)	{right();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==4)	{right();delay_turn(600);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==5)	{left();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-2)	{left();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else {stop();delayms(1);}
}
if(Time_Turn_Buf[j-1]=='E')
{
if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-1)	{left();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==0) 	{forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==1)	{right();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==2)	{right();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==3)	{right();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==4)	{right();delay_turn(600);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-3)	{left();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-2)	{left();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else {stop();delayms(1);}
}
if(Time_Turn_Buf[j-1]=='F')
{
if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-1)	{left();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==0) 	{forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==1)	{right();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==2)	{right();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==3)	{right();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-4)	{right();delay_turn(600);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-3)	{left();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-2)	{left();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else {stop();delayms(1);}
}
if(Time_Turn_Buf[j-1]=='G')
{
if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-1)	{left();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==0) 	{forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==1)	{right();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==2)	{right();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-5)	{right();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-4)	{right();delay_turn(600);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-3)	{left();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-2)	{left();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else {stop();delayms(1);}
}
if(Time_Turn_Buf[j-1]=='H')
{
if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-1)	{left();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==0) 	{forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==1)	{right();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-6)	{right();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-5)	{right();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-4)	{right();delay_turn(600);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-3)	{left();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-2)	{left();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else {stop();delayms(1);}
}
if(Time_Turn_Buf[j-1]=='I')
{
if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-1)	{left();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==0) 	{forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-7)	{right();delay_turn(150);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-6)	{right();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-5)	{right();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-4)	{right();delay_turn(600);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-3)	{left();delay_turn(450);forward();delay_s(3);stop();delay_turn(1);}
else if(Time_Turn_Buf[j]-Time_Turn_Buf[j-1]==-2)	{left();delay_turn(300);forward();delay_s(3);stop();delay_turn(1);}
else {stop();delayms(1);}
}
else
{
stop();
delayms(1);
}
}
}
}
}
}
}
}	

5
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：123149次
• 积分：1691
• 等级：
• 排名：千里之外
• 原创：39篇
• 转载：12篇
• 译文：0篇
• 评论：79条
评论排行
最新评论