PID反馈放大器&;位置控制器与直流电动机/ EN codeR [英] PID feedback & Position Controller with DC motor/encoder

查看:218
本文介绍了PID反馈放大器&;位置控制器与直流电动机/ EN codeR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很难得到双方PID反馈和定位在同一时间运行。

我认为计算RPM是:


  1. 启动一个定时器和使用中断数连接codeR脉冲。

  2. 使用一些简单的数学转换为RPM。

  3. 重新使用的变量并重新开始。

我可以计算RPM,但后来我只能计算后打电话给我的PID控制器(但长我想等获得良好的分辨率。)这将导致非常混乱code。是否有一个更简单的方法还是我丢失的东西?

信息关于我的应用程序:
我编程到爱特梅尔ATMEGA328P用直流电动机/双磁带codeR每转(减速机后)〜600脉冲。我想打电话给GoToTarget(#),并具备电机去的位置,同时更新的PID参数。此外,它必须是双向的。


解决方案

您速度计算定时器和您的PID回路计时器应该是相同的事情 - 而不是单独

不要浪费时间和分辨率转换脉冲计数在RPM速度;如果定时器是准确周期性的 - 它需要成为一个稳定的PID - 再脉冲计数是直接的比例的速度,并且PID不关心的单位 - 可以通过调整的系数的值。如果你希望你的设定点速度是在现实世界中的单位,转换的的脉冲到每PID周期,而不是​​周围的其他方式的等值数量。

您循环应该是这样的;

 为(;;)
{
    WaitTimer();
    脉冲= pulse_count - previous_pulse_count;
    previous_pulse_count = pulse_count;
    控制= PID(脉冲);
    马达(对照);
}

您那么只需要一个中断脉冲计数 - 它不需要任何计算,只需增加一个计数器 - 也许中断定时器,取决于WaitTimer(执行),这是多线程的<。 / p>

还要注意的是,如果共享变量pulse_count不是原子,你需要禁用中断,而它读取(在一个函数最好的包裹),它将需要声明挥发性

I'm having a hard time getting both PID feedback and positioning to run at the same time.

My thought to calculate the RPM is to:

  1. start a timer and count encoder pulses using an interrupt.
  2. use some simple math to convert to RPM.
  3. reset variables used and start over.

I can calculate RPM but then I can only call my PID controller after the calculation (however long I want to wait to get good resolution.) This results in very messy code. Is there a simpler method or something I'm missing?

Info about my application: I am programming to an Atmel ATmega328P with a DC motor/dual magnetic encoder with ~600 pulses per revolution (after gearhead). I want to call GoToTarget(#) and have the motor go to the position while updating the PID parameters. In addition,it must go both ways.

解决方案

Your speed calculation timer and your PID loop timer should be the same thing - not separate.

Do not waste time and resolution converting pulse count to speed in RPM; if the timer is accurately periodic - and it needs to be for a stable PID - then the pulse count is directly proportional to speed, and the PID does not care about the units - that can be adjusted for by the value of the coefficients. If you want your set-point speed to be in real-world units, convert that to the equivalent number of pulses-per-PID-period instead of the other way around.

Your loop should look like this ;

for(;;)
{
    WaitTimer() ;
    pulses = pulse_count - previous_pulse_count ;
    previous_pulse_count = pulse_count ;
    control = pid( pulses ) ;
    motor( control ) ;
}

You then need only an interrupt to count pulses - it need not perform any calculation, just increment a counter - and perhaps an interrupt for the timer, depending on the implementation of WaitTimer() and whether this is multi-threaded.

Note also that if the shared variable pulse_count is not atomic, you will need to disable interrupts while it is read (best wrapped in a function), and it will need to be declared volatile.

这篇关于PID反馈放大器&;位置控制器与直流电动机/ EN codeR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆