新闻中心

EEPW首页>电源与新能源>设计应用> 声音引导系统完整硬件设计和源代码

声音引导系统完整硬件设计和源代码

作者: 时间:2016-12-08 来源:网络 收藏

电机进行前进和后退,因此需采用位置式PID控制。

本文引用地址://m.amcfsurvey.com/article/201612/327594.htm

经过不断的测试,比例,积分,微分常数目前调出的最佳参数如下:

Kp: 1.6 Ki: 2.1 Kd:1.4 具体部分代码参见附录。第五章调试及结果分析

5.1音频信号采集模块调试

次数

声源离接收器的距离/cm

波形是否有变化

1

10

2

50

3

100

4

150

不定

5

200

5.2路程测量测试

次数

测试距离(cm)

实际距离(cm)

误差计算

1

45

47

4.44%

2

50

51

2.00%

3

55

57

5.18%

4

60

59

1.67%

调试仪器:20MHz双踪示波器、信号发生器、数字万用表、秒表、米尺等

5.3结果分析

经测试,在外界干扰不是太强的情况下,可移动声源能够通过接收器方传回的数据精确地定位,精度在1—3cm.

PID调试部分代码:

// 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

}


上一页 1 2 下一页

评论


技术专区

关闭