STM32
直播中

王平

7年用户 1242经验值
私信 关注
[问答]

如何利用STM32和STC12C5A60S2去控制小车运动呢

如何利用STM32和STC12C5A60S2去控制小车运动呢?其软硬件该怎样去设计呢?

回帖(2)

周必镜

2021-12-20 14:55:54
简介:
利用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的连接图:
  
  



  


  小车:

  关于小车的构造:小车分为四个部分:底座部分、电机驱动部分、变压部分、控制部分。
  底座部分:双电机驱动,每一个电机通过齿轮轴承等零件同时带动前后两个车轮。由于没有舵机转向,所以该小车转向通过差速转向,因为机械结构简单,所以转向时具体情况为一边向前运动一边向后运动,通过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单片机,

  

  其他的也没什么好记的了,下面贴出两部分的主程序,全程序长了,无法全部贴:
  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_yNow_x)
                Time_Turn_Buf = 5;//右转135
        else        if(Next_xNow_y)
                Time_Turn_Buf = 1;//左转45
        else        if(Next_x                 Time_Turn_Buf = 8;//左转90
        else        if(Next_y                 Time_Turn_Buf = 7;//左转135
        else        if(Next_y                 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                          {
                                Draw_Big_Point(Path_Set_x * 15,250 + 32 - 15 * Path_Set_y );//循环体   画出轨迹       
                         }
                        /******************************/
                        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
***it 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);
                                }
                                LCD_POS(3,0);
                                for(i=16;i<32;i++)
                                {
                                        LCD_Write_dat(Time_Turn_Buf);       
                                }
                               
                                key=mode;
                                for(i=0;i<32;i++)
                                {
                                        key++;
                                        if(key>'~')
                                                key=32;
                                        Time_Turn_Buf=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)
        {
举报

刘龙飞

2021-12-20 14:55:59
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);
                                                        }
                                                }                       
                                        }         
                                }
                        }
                }
        }       
}       
大概就是这样子了,花时间记录下这次的制作,一次美好的过程,一次美好的回忆。每一次辛酸的劳累,都是一次攀登;而每一次向上方的攀登,都是一次美好的经历;可不知道怎么的,给我最深的感觉却是每一次长久的经历,平静之后都是无法形容的失落。失落。
  
   
举报

更多回帖

×
20
完善资料,
赚取积分