飞思卡尔智能车程序Word文档格式.docx

上传人:b****5 文档编号:15842751 上传时间:2022-11-16 格式:DOCX 页数:17 大小:18.47KB
下载 相关 举报
飞思卡尔智能车程序Word文档格式.docx_第1页
第1页 / 共17页
飞思卡尔智能车程序Word文档格式.docx_第2页
第2页 / 共17页
飞思卡尔智能车程序Word文档格式.docx_第3页
第3页 / 共17页
飞思卡尔智能车程序Word文档格式.docx_第4页
第4页 / 共17页
飞思卡尔智能车程序Word文档格式.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

飞思卡尔智能车程序Word文档格式.docx

《飞思卡尔智能车程序Word文档格式.docx》由会员分享,可在线阅读,更多相关《飞思卡尔智能车程序Word文档格式.docx(17页珍藏版)》请在冰豆网上搜索。

飞思卡尔智能车程序Word文档格式.docx

//x-positionofthearray

unsignedcharline;

//y-positionofthearray

unsignedintrow_count;

//rowcounter

unsignedcharline_sample;

//usedtocounterinAD

unsignedcharrow_image;

unsignedcharline_temp;

//temperaryvariableusedindatatransfer

unsignedcharsample_data[LINE_MAX];

//usedtosaveone-dimensionarraygotin

interruption

//variablesbelowareusedinspeedmeasure

Unsignedcharpulse[5];

//usedtosavedatainPAprocess

Unsignedcharcounter;

//temporarycounterinSpeeddetect

Unsignedcharcur_speed;

//currentspeed

shortstand;

shortdata;

unsignedcharcurve;

//valveusedtodecidestraightorturn

shortBounds(shortdata);

shortFuzzyLogic(shortstand);

/*----------------------------------------------------------------------------*\

receive_sci

\*----------------------------------------------------------------------------*/

unsignedcharreceive_sci(void)//receivedatathroughsci

{unsignedcharsci_data;

while(SCI0SR1_RDRF!

=1);

sci_data=SCI0DRL;

returnsci_data;

}

transmit_sci

voidtransmit_sci(unsignedchartransmit_data)//senddatathroughsci

{

while(SCI0SR1_TC!

while(SCI0SR1_TDRE!

SCI0DRL=transmit_data;

/*****************************************************************************

***/

abs_sub

unsignedcharabs_sub(unsignedcharnum1,unsignedcharnum2)

{unsignedchardifference;

if(num1>

=num2){

difference=num1-num2;

}else{

difference=num2-num1;

returndifference;

voidpwm_set(unsignedintdutycycle)

PWMDTY1=dutycycle&

0x00FF;

PWMDTY0=dutycycle>

>

8;

voidget_black_wire(void)//usedtoextractblackwire

{unsignedchari;

for(row=0;

row<

ROW_MAX;

row++){

for(line=LINE_MIN;

line<

LINE_MAX-3;

line++){

if(image_data[row][line]>

image_data[row][line+3]+VALVE){

for(i=3;

i<

10;

i++){

if(image_data[row][line+i]+VALVE<

image_data[row][line+i+3]){

black_x[row]=line+i/2+2;

i=10;

line=LINE_MAX;

}else{

//black_x[row]=(black_x[row]/45)*78;

speed_control

voidspeed_control(void)

unsignedintsum,average;

sum=0;

FIRST_FIVE;

sum=sum+black_x[row];

average=sum/FIRST_FIVE;

curve=0;

row++)

curve=curve+abs_sub(black_x[row],average);

if(curve>

CURVE_MAX){

curve_flag=0;

speed=low_speed;

else{

curve_flag=1;

speed=hign_speed;

steer_control

voidsteer_control(void)

{unsignedintdutycycle;

unsignedcharvideo_center;

unsignedintcoefficient;

intE,U;

//current

staticinte=0;

video_center=(LINE_MIN+LINE_MAX)/2;

stand=abs_sub(black_x[1]+black_x[9],2*black_x[5]);

E=video_center-black_x[8];

coefficient=30+1*FuzzyLogic(stand);

U=coefficient*E;

dutycycle=Bounds(center+U);

pwm_set(dutycycle);

//makesureitiswithinbounds

shortBounds(shortdata){

if(data>

right_limit){

data=right_limit;

if(data<

left_limit){

data=left_limit;

returndata;

Voidspeed_get(void)

Unsignedchartemp;

Counter++;

Temp=PACN1;

cur_speed=temp-pulse[counter-1];

pulse[counter-1]=temp;

if(counter==5)

counter=0;

Voidset_speed(unsignedchardesired_speed)

If(desired_speed<

cur_speed)

PWMDTY2=low_speed;

Else

PWMDTY2=high_speed;

*\

Main

\*****************************************************************************

*/

voidmain(void){

//mainfunctiion

init_PORT();

//portinitialization

init_PLL();

//settingofthePLL

init_ECT();

init_PWM();

//PWMINITIALIZATION

init_SPEED();

init_SCI();

for(;

;

){

if(field_signal==0){//even->

odd

while(field_signal==0);

row_count=0;

row_image=0;

EnableInterrupts;

while(row_count<

ROW_END){

get_black_wire();

speed_control();

steer_control();

DisableInterrupts;

else{//odd->

even

while(field_signal==1);

ROW_END)

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 解决方案

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1