智能车制作
标题:
新手求大神指教:电机与舵机调整
[打印本页]
作者:
陆羽凡
时间:
2012-8-29 15:54
标题:
新手求大神指教:电机与舵机调整
#include <hidef.h> /* common defines and macros */
#include <MC9S12XS128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
#include "ADC.h"
#include "SCI.h"
#include "Delay.h"
#include "PWM.h"
#include "MCU.h"
void main(void)
{
long x,i,y,z,big,small;
int snap[8];
unsigned char b;
unsigned char loop_index,ch; //定义循环变量
MCUInit();
Sci0Init();
PWM_Init();
ADCInit();
for (;;) { int snap[8];
int i;
for(i=0;i<8;i++)
{
snap[i]=ADCvalue(i);
put_char_change(snap[i]);
Sci0Printf("\t");
}
Sci0Printf("\n\r");
Delay(30000) ;
}
Delay(30000) ;
big=0;small=0;
for(i=1;i<8;i++){
if(snap[i]<snap[small]){
small=i;
}
if(snap[i]>snap[big]){
big=i;
}
}
switch(small){
case 7:
PWMDTY0 = 90;
PWMDTY2= 5;
break;
case 6:
PWMDTY0 = 70;
PWMDTY2= 25;
break;
case 5:
PWMDTY0 = 150;
PWMDTY2= 7;
break;
case 4:
PWMDTY0 = 110;
PWMDTY2= 22;
break;
case 3:
PWMDTY0 = 170;
PWMDTY2= 11;
break;
case 2:
PWMDTY0 = 170;
PWMDTY2= 19;
break;
case 1:
PWMDTY0 = 210;
PWMDTY2= 14;
break;
case 0:
PWMDTY0 = 210;
PWMDTY2= 16;
break;
case 0xff:
PWMDTY0 = 0;
PWMDTY2= 15;
break;
}
}
/*while(1){
ch=Sci0Read() ;
switch(ch)
{
case '0': PWMDTY2 = 5; Sci0Write(ch);break;
case '1': PWMDTY2 = 10;Sci0Write(ch); break;
case '2': PWMDTY2 = 15;Sci0Write(ch); break;
case '3': PWMDTY2 = 20;Sci0Write(ch); break;
case '4': PWMDTY2 = 25;Sci0Write(ch); break;
case 's': PWMDTY0 -= 5;Sci0Write(ch); break;
case 'w': PWMDTY0 += 5;Sci0Write(ch); break;
case 'x': PWMDTY0 = 0;Sci0Write(ch); break;
}
} */
这个程序能不能调节舵机方向和电机转速???
追问:为什么在小车上测试无法对电机和舵机做出调整
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2