智能车制作
标题: 求翻译 [打印本页]
作者: 緋龍在天 时间: 2015-3-13 23:15
标题: 求翻译
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include "main.h"
#include <math.h>
#include "Hardware_Init.H"
#include "CCD_TSL1401.h"
#include "delay.h"
#include "SCIISP.h"
#include"Fuzzy.h"
int LR_Add = 0;
int LR_Sub = 0;
int Dir_Error[3]={0};
int Dir_Deviation[3];
int Dir_P;
int Dir_I;
int Dir_D;
int k1;
int k2;
int Dir_ControlOut;
unsigned char BIN[128] = {0};
unsigned char CCD2_BIN[128] = {0};
int NowSpeed;
int Speed_Error[3]={0};
int Speed_Deviation[3]={0};
int Speed_Zhi;
int Speed_Wan;
int Speed_P;
int Speed_I;
int Speed_D;
/**/
int Zhidao_Flag=0;
int StopLine_Flag=0;
int temptemp;
int temptemp1;
unsigned int STime=0;
unsigned int RenTime=0;
int Pass_Renzi=0;
int RenziJiance=0;
void Parameter_Setting(void)
{
//Dir_P = 10;
Dir_I = 0;
Dir_D = 0;
Speed_Zhi = 170;
Speed_Wan = 170;
Speed_P = 2;
Speed_I = 1;
Speed_D = 0;
STime = 3;
RenTime = 3;
TH = 15;
TH1 = 2;
}
void Stop_Car(void)
{
PWME_PWME0 = 0;
DDRP_DDRP0 = 1;
PERP_PERP0 = 1;
PPSP_PPSP0 = 1;
PTP_PTP0 = 0;
if(NowSpeed>40)
Motor_Out(0,200);
else
{
Motor_Out(0,0);
PWME_PWME1 = 0;
DDRP_DDRP1 = 1;
PERP_PERP1 = 1;
PPSP_PPSP1 = 1;
PTP_PTP1 = 0;
}
}
void StopLine_Judgement(void)//(请队员查询一下红外对管的工作原理)
{
static int Flag_Q1;
static int Flag_Q2;
static int Time_Q1;
static int Time_Q2;
if(PORTA_PA6==0)
{
Flag_Q1 = 1;
}
if(Flag_Q1 == 1)
{
Time_Q1++;
}
if((Time_Q1>=1)&&(PTIJ_PTIJ6==0))
{
StopLine_Flag = 1;
Flag_Q1 = 0;
Time_Q1 = 0;
}
if(Time_Q1>15)
{
Flag_Q1 = 0;
Time_Q1 = 0;
}
if(PTIJ_PTIJ6==0)
{
Flag_Q2 = 1;
}
if(Flag_Q2 == 1)
{
Time_Q2++;
}
if((Time_Q2>=1)&&(PORTA_PA6==0))
{
StopLine_Flag = 1;
Flag_Q2 = 0;
Time_Q2 = 0;
}
if(Time_Q2>15)
{
Flag_Q2 = 0;
Time_Q2 = 0;
}
}
void Binarization(void)
{
unsigned char i;
for(i=0;i<128;i++)
{
if(Pixel>Threshold)
{
BIN = 50;
}
else
{
BIN = 0;
}
if(Pixel2>Threshold1)
{
CCD2_BIN = 50;
}
else
{
CCD2_BIN = 0;
}
}
}
void Get_LRSide(unsigned char *ABIN)
{
int i,j,k;
for(i=0;i<127;i++)
{
if((ABIN==0)&&(ABIN[i+1]==0)&&(ABIN[i+2]==50)&&(ABIN[i+3]==50)&&(ABIN[i+4]==50))
{
k1 = i;
}
if((ABIN[i-3]==50)&&(ABIN[i-2]==50)&&(ABIN[i-1]==50)&&(ABIN==0)&&(ABIN[i+1]==0))
{
k2 = i; break;
}
}
}
float Pos_cal(void)
{
float fValue=0.0;
float Value=0.0;
LR_Add = 64-middle;
//LR_Add = 64-(k1+k2)/2;
//LR_Sub = k1-k2;
Dir_Error[2] = Dir_Error[1];
Dir_Error[1] = Dir_Error[0];
Dir_Error[0] = LR_Add;
Dir_Deviation[2] = Dir_Deviation[1];
Dir_Deviation[1] = Dir_Deviation[0];
Dir_Deviation[0] = Dir_Error[0]- Dir_Error[1];
Fuzzy_lishudu(LR_Add,Dir_Deviation[0]);
Dir_P = Fuzzy_Kp(0,0);
//Dir_I = Fuzzy_Ki(10,1);
//Dir_D = Fuzzy_Kd(0,0);
Value = LR_Add*Dir_P +Dir_Deviation[0]*Dir_I/100.0+Dir_Error[1]*Dir_D/100.0;
fValue=Value;
return fValue;
}
void Dir_Out(void)
{
float Dir;
static unsigned char flag1=0,flag2=0;
Dir = Pos_cal();
Dir_ControlOut = Dir_M - Dir;
if(Dir_ControlOut <= Dir_MIN) Dir_ControlOut = Dir_MIN;
if(Dir_ControlOut >= Dir_MAX) Dir_ControlOut = Dir_MAX;
PWMDTY23 = (unsigned int)Dir_ControlOut;
}
void Speed_Control(unsigned int speed)
{
static int Speed_Out;
int speed_temp;
speed_temp = speed;
Speed_Error[2]=Speed_Error[1];
Speed_Error[1]=Speed_Error[0];
Speed_Error[0]=speed_temp-NowSpeed;
Speed_Deviation[2] = Speed_Deviation[1];
Speed_Deviation[1]= Speed_Deviation[0];
Speed_Deviation[0] = Speed_Error[0]-Speed_Error[1];
Speed_Out +=Speed_P*Speed_Error[0]+Speed_I*(Speed_Deviation[0])+Speed_D*(Speed_Deviation[1]);
if(Speed_Out>250)
Speed_Out=250;
else if(Speed_Out<0)
Speed_Out=0;
Motor_Out(Speed_Out,0);
}
void Motor_Out(unsigned charForward,unsigned char back)
{
if(Forward>=250) Forward =250;
if(back>=250) back = 250;
PWMDTY0 = Forward;
PWMDTY1 = back;
}
欢迎光临 智能车制作 (http://dns.znczz.com/) |
Powered by Discuz! X3.2 |