有人知道如何将前馈运算放大器PID循环转换为C代码吗?我正试着做这样的转换,老实说,我不知道从哪里开始。我可以通过ADC获得所有的输入值,电压,电流,任何东西,但是编码一个前馈PID对我来说是一个新的东西。有什么想法吗?
发布于 2012-11-16 03:46:04
对于非线性控制系统,您正在谈论用软件取代硬件。我想你唯一的希望就是写一个硬件的模拟。
我对PID一无所知,但我在谷歌上快速搜索一下就发现了:
http://www.cds.caltech.edu/~murray/books/AM05/pdf/am06-pid_16Sep06.pdf
它具有描述理想PID控制系统的方程式和图表。您可以从编写实现这些等式的代码开始。
在我考虑了一下你的问题后,我觉得这可能是一个常见的问题。我在谷歌上搜索了“离散PID控制器仿真”,找到了Simulink、Matlab和Python的答案,以及更多的书籍参考。
您可能希望从Python菜谱开始。使用Python比使用C更容易、更快,如果您使用SciPy,您可以绘制结果并确保获得您想要的数字。一旦你让它在Python中工作,如果需要的话,可以移植到C。
http://code.activestate.com/recipes/577231-discrete-pid-controller/
发布于 2013-02-07 03:40:20
巡回赛
你想用C语言模拟的模拟电路看起来像这样
Ci
|------| |--------------|
| Rp |
|----/\/\/\/\-----------|
| Rd Cd |
Rf |----/\/\/\---| |-------|
Vin o----/\/\/\---| |
| |\ |
| | \ |
|----|- \ |
| \ |
| \-------------|---------o Vout
| /
| /
|+ /
----| /
| |/
|
|
___|___ GND
_____
___
_
LEGEND:
Vin is the input signal.
Vout is the Output.
Rp controls the propotional term ( P in PID)
Ci controls the Integral term ( I in PID)
Rd and Cd controls the differential term ( D in PID)
Rf is the gain control, which is common to all of the above controllers.我强烈建议您使用this source中的电路进行学习。

尽管设置起来有点繁琐,但在数学上分析起来要简单得多,因为你可以直接将它与标准数学形式联系起来,而不是理想的数学形式。
最后,Vout去控制马达或任何需要控制的东西。Vin是过程变量电压。
在你涉足C(海?)
我假设你正在读取来自某种模数转换器的信号。如果不是,那么您将不得不将该信号模拟为输入。
如果我们使用Standard form,

假设循环运行时间足够小(一个缓慢的进程),我们可以使用以下函数来计算输出,
PIDoutput = Kp * err + (Ki * int * dt) + (Kd * der /dt);哪里
Kp = Proptional Constant.
Ki = Integral Constant.
Kd = Derivative Constant.
err = Expected Output - Actual Output ie. error;
int = int from previous loop + err; ( i.e. integral error )
der = err - err from previous loop; ( i.e. differential error)
dt = execution time of loop.其中,初始'der‘和'int’应该是零。如果在代码中使用延迟函数将循环频率调优为1 KHz,那么dt将为0.001秒。
现在前馈系统的输出将是,
FeedForwardOutput = Kf * Vin;其中Kf =前馈系统的比例常数。
因此,我们的具有PID控制器的前馈系统的总输出将是,
Output = FeedForwardOutput + PIDoutput;查看此link以进一步了解具有PID控制器的前馈系统。
用C语言绘图
我发现this是用C语言编写的很好的PID代码,尽管它没有涵盖它的所有方面,但它仍然是一个很好的代码。
//get value of setpoint from user
while(1){
// reset Timer
// write code to escape loop on receiving a keyboard interrupt.
// read the value of Vin from ADC ( Analogue to digital converter).
// Calculate the output using the formula discussed previously.
// Apply the calculated outpout to DAC ( digital to analogue converter).
// wait till the Timer reach 'dt' seconds.
}如果我们采用较慢的进程,那么我们可以使用较低的频率,以便dt >>>代码执行单循环的时间(远远大于)。在这种情况下,我们可以不使用计时器,而使用延迟函数。
https://stackoverflow.com/questions/13404658
复制相似问题