手繪軌跡(STM32觸控式螢幕)控制小車運動
簡介:
利用STM32和STC12C5A60S2(增強型51)做的一款作品。其中STM32控制觸控式螢幕、按鍵等模組,STC12C5160S2處理手繪的軌跡資料控制小車,兩大部分通過NRF24L01通訊。(由於時序原因,兩者的通訊部分程式一定要處理好,否則無法通訊。)
使用者在觸控式螢幕(電阻屏)上繪畫出自己指定的軌跡,如:圓形,S形等。繪畫之後按下發送按鍵,STM32便會將各個點的座標資料處理,然後無線傳送給STC12C5160S2,繼而控制小車進行與手繪的軌跡相同的運動。
軟體設計:
分為兩個部分,一部分在觸控式螢幕上,如:路徑分析,座標取點等;另一部分在小車上。(後面我會把程式完全貼出來)
1. 路徑分析演算法
因為人在觸控式螢幕手繪的路徑是在一個固定的座標系上的移動軌跡,為了儘可能的靠近軌跡,我們加大軌跡的取點數量,基本的思想是從現在的點走向下一點,一直走到最後一點。為了傳送的資料簡潔,我們設計了一些演算法,下面取其中幾個自己繪畫的對座標的分析圖。分析圖中為了方便檢視和分析,取點數量減少。
黃色為手繪出的軌跡,紅色為取的點和座標原點形成的唯一矩形,分析可知:
Θ3 = Θ2 - Θ1,Θ5 = Θ4 - Θ3;
注:如果Θ<0,那麼以四軸自身形成的座標系而言,小車此時應該向左拐彎;如果Θ>0,那麼以小車自身形成的座標系而言,小車此時應該向右拐彎。所以這個的關鍵就是固定座標系和相對座標系之間的一些引數的轉化。
例如:
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. 不同頻率微控制器之間的無線通訊
由於不同頻率微控制器之間的無線通訊需要解決不少的時序問題,因為以前研究過STM32微控制器和51微控制器之間由於頻率不同造成的無法進行無線的通訊的問題,所以在STM32的程式加上了一些必要的延時,以實現時序上的一致,從而使通訊資料完善不會丟失或者造成通訊失敗。
例如:
delayms(250);
硬體設計:
同樣分為兩部分,一個是觸控式螢幕的硬體設計,另外一個是小車的硬體設計。
觸控式螢幕:
效果圖:
觸控式螢幕和STM32的連線圖:
小車:
1.
2.
3.
4.
關於小車的構造:小車分為四個部分:底座部分、電機驅動部分、變壓部分、控制部分。
底座部分:雙電機驅動,每一個電機通過齒輪軸承等零件同時帶動前後兩個車輪。由於沒有舵機轉向,所以該小車轉向通過差速轉向,因為機械結構簡單,所以轉向時具體情況為一邊向前運動一邊向後運動,通過IO口控制電機驅動部分。
電機驅動部分:引出6+8個埠,其中2個為7.2V電壓輸入埠(給控制埠),4個為控制底座部分電機輸出埠,2個為5V電壓輸入埠(給電機驅動模組),6個為連線到控制部分的埠。具體作用可以從程式中很清晰的看到。
變壓部分:沒什麼好說的,通過LM2940CT-5和AMS1117-3.3兩個變壓晶片簡單的7.2V(給電機)轉5V(給控制)轉3.3V(給NRF24L01)。要電路圖的可以百度或者加我QQ。
控制部分:用了前面提到的增強型51微控制器STC12C5160S2,程式和平時學習到的普通的51程式基本沒有區別,主要的區別好像是頻率不同,這個是12T微控制器,而51是1T微控制器,如想具體學習,請移步:http://blog.csdn.net/lxk7280/article/details/12781069。
其他的也沒什麼好記的了,下面貼出兩部分的主程式,全程式長了,無法全部貼:
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);
LCD_ShowString(60,130,"Please Check! ");
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);
Touch_Adjust();
Save_Adjdata();
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(1,0," 24L01 Ready! ");
// 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");
LCD_W_Word(1,0,"Received DATA: ");
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);
}
}
}
}
}
}
}
}
大概就是這樣子了,花時間記錄下這次的製作,一次美好的過程,一次美好的回憶。每一次辛酸的勞累,都是一次攀登;而每一次向上方的攀登,都是一次美好的經歷;可不知道怎麼的,給我最深的感覺卻是每一次長久的經歷,平靜之後都是無法形容的失落。失落。
允許我矯情一下:我珍惜每一天每一次的經歷,都是寶藏。