聲音引導(dǎo)系統(tǒng)完整硬件設(shè)計(jì)和源代碼
電機(jī)進(jìn)行前進(jìn)和后退,因此需采用位置式PID控制。
本文引用地址:http://www.ex-cimer.com/article/201612/327594.htm經(jīng)過(guò)不斷的測(cè)試,比例,積分,微分常數(shù)目前調(diào)出的最佳參數(shù)如下:
Kp: 1.6 Ki: 2.1 Kd:1.4 具體部分代碼參見(jiàn)附錄。第五章調(diào)試及結(jié)果分析
5.1音頻信號(hào)采集模塊調(diào)試
次數(shù) | 聲源離接收器的距離/cm | 波形是否有變化 |
1 | 10 | 是 |
2 | 50 | 是 |
3 | 100 | 是 |
4 | 150 | 不定 |
5 | 200 | 否 |
5.2路程測(cè)量測(cè)試
次數(shù) | 測(cè)試距離(cm) | 實(shí)際距離(cm) | 誤差計(jì)算 |
1 | 45 | 47 | 4.44% |
2 | 50 | 51 | 2.00% |
3 | 55 | 57 | 5.18% |
4 | 60 | 59 | 1.67% |
調(diào)試儀器:20MHz雙蹤示波器、信號(hào)發(fā)生器、數(shù)字萬(wàn)用表、秒表、米尺等
5.3結(jié)果分析
經(jīng)測(cè)試,在外界干擾不是太強(qiáng)的情況下,可移動(dòng)聲源能夠通過(guò)接收器方傳回的數(shù)據(jù)精確地定位,精度在1—3cm.
PID調(diào)試部分代碼:
// define difference : the difference between the latest data and the previous data
// define U0 : the PWM to send to the moto
int main (void)
{
······ // Omitted the previous code
int P = 0 , D = 0 ;
tcount++ ;
CarState.E0 = BitNum ;
if ( CarState.E0 == CarState.E1 ) if ( CarState.E0 == 0 ) FlagD = 0 ;
else if ( CarState.E0 < CarState.E1 ) FlagD = -1 ;
else if ( CarState.E0 > CarState.E1 ) FlagD = 1 ;
P = CarState.E0 * Kp ;
D = Kd * KdS * ( CarState.E0 + 3*CarState.E1 - 3*CarState.E2 - CarState.E3 ) ;
if ( D < - 30 * KdS ) D = -30*KdS ;
else if ( D > 30*KdS ) D = 30*KdS ;
if ( D != 0 ) D_old = D ;
if ( D_old < -10 ) D_old++ ;
else if ( D_old > 10 ) D_old-- ;
if ( (CarState.E0 > -3)&&(CarState.E0 < 3) ) S = 0 ;
else if ( ( FlagD == -1) && ( CarState.E0 <= -1 ) )
if ( S > ( BitNum * BitNum * 20 * KsS ) ) S-- ;
else if ( ( FlagD == -1) && ( CarState.E0 >= -1 ) ) S = 0 ; //
else if ( ( FlagD == 1 ) && ( CarState.E0 <= 1 ) ) S = 0 ; //
else if ( ( FlagD == 1 ) && ( CarState.E0 >= 1 ) )
if ( S < ( BitNum * BitNum * 20 * KsS) ) S++ ; //
u8_pwm_a = U0 + P + ( D_old / KdS )+ ( S / KsS ); // ;
······ // Omitted the following code
}
評(píng)論