1

关于投票
PID CONTROL

PID Control
A proportional integral derivative controller (PID controller) is a common method of controlling robots. PID theory will help you design a better control equation for your robot.

Shown here is the basic closed-loop (a complete cycle) control diagram:

Robot PID Controller Diagram

The point of a control system is to get your robot actuators (or anything really) to do what you want without . . . ummmm . . . going out of control. The sensor (usually an encoder on the actuator) will determine what is changing, the program you write defines what the final result should be, and the actuator actually makes the change. Another sensor could sense the environment, giving the robot a higher-level sense of where to go.

Terminology
To get you started, here are a few terms you will need to know:

error - The error is the amount at which your device isnt doing something right. For example, if your robot is going 3mph but you want it to go 2mph, the error is 3mph-2mph = 1mph. Or suppose your robot is located at x="5" but you want it at x="7", then the error is 2. A control system cannot do anything if there is no error - think about it, if your robot is doing what you want, it wouldnt need control!

proportional (P) - The proportional term is typically the error. This is usually the distance you want the robot to travel, or perhaps a temperature you want something to be at.

derivative (D) - The derivative term is the change in error made over a set time period (t). This is usually the velocity of your robot. So if your robot was at x="5" about one t ago, and is at x="7" now, then the derivative term is 7 - 5 = 2/t. If you are using a microcontroller, you can calculate the time with this timer tutorial.

integral (I) - The integral term is the rate of change in the error made over a set period of time (t). This is usually the acceleration of your robot. If your derivative term was 2/t a second ago, and it is 2/t now, your integral term is 2 - 2 = 0/t^2. Thats an acceleration error of zero . . .

tweak constant (gain) - Each term (P, I, D) will need to be tweaked in your code. There are many things about a robot that is very difficult to model mathematically (ground friction, motor inductance, center of mass, ducktape holding your robot together, etc.). So often times it is better to just build the robot, implement a control equation, then tweak the equation until it works properly. A tweak constant is just a guessed number that you multiple each term with. For example, Kd is the derivative constant. Idealy you want the tweak constant high enough that your settling time is minimal but low enough so that there is no overshoot.

Typical Control Curve

What you see in this image is typically what will happen with your PID robot. It will start with some error and the actuator output will change until the error goes away (near the final value). The time it takes for this to happen is called the settling time. Shorter settling times are almost always better. Often times you might not design the system properly and the system will change so fast that it overshoots (bad!), causing some oscillation until the system settles. And there will usually be some error band. The error band is dependent on how fine a control your design is capable of - you will have to program your robot to ignore error within the error band or it will probably oscillate. There will always be an error band, no matter how advanced the system.

ignoring acceptable error band example:

    if error <= .000001 //subjectively determined acceptable
      then error = 0; //ignore it

The Complete PID Equation
Combining everything from above, here is the complete PID equation:

Actuator_Output = Kp*P + Ki*I + Kd*D

or in easy to understand terms:

Actuator_Output =

    tweakA * (distance from goal)
    + tweakB * (velocity error)
    + tweakC * (acceleration error)

Simplifications
The nice thing about tuning a PID controller is that you don't need to have a good understanding of formal control theory to do a fairly good job of it. Most control situations will work with just an hour or so max of tuning.

Better yet, rarely will you need the integral term. Thats right, just delete and ignore it! The only time you will need this term is when acceleration plays a big factor with your robot. If your robot is really heavy, or gravity is not on it's side (such as steep hills), then you will need the integral term. But out of all the robots I have ever programmed, only two needed an integral term - and both robots were over 30 lbs with a requirement for extremely high precision (millimeter or less error band). Control without the integral term is commonly referred to as simply PD control.

There are also times when you do not require a derivative term, but usually only when the device mechanical stabalizes itself, works at very low speeds so that overshoot just doesnt happen, or you simply dont require good precision.

Sampling Rate Issues
The sampling rate is the speed at which your control algorithm can update itself. The faster the sampling rate, the higher precision control your robot will have. Slower sampling rates will result in higher settling times and an increased chance of overshoot (bad). To increase sampling rate, you want an even faster update of sensor readings, and minimal delay in your program loop. Its good to have the robot react to a changing environment before it drives off the table, anyway. Humans suffer from the sampling rate issue too (apparently drinking reduces the sampling rate, who would have guessed?).

The rule of thumb is that the sample time should be between 1/10th and 1/100th of the desired system settling time. For a typical homemade robot you want a sampling rate of about 20+/second (very reasonable with today's microcontrollers).

系统分类: 汽车电子
用户分类: 电机控制
标签: 无标签
来源: 转贴
发表评论 阅读全文(533) | 回复(0)

3

关于投票
电动小车的电机驱动及控制
一个电动小车整体的运行性能,首 先取决于它的电池系统和电机驱动系统。 电动小车的驱动系统一般由控制器、功率变换器及电动机三个主要部分组成。 电动小车的驱动不但要求电机驱动系统 具有高转矩重量比、宽调速范围、高可靠 性,而且电机的转矩-转速特性受电源功 率的影响,这就要求驱动具有尽可能宽 的高效率区。我们所使用的电机一般为 直流电机,主要用到永磁直流电机、伺服 电机及步进电机三种。直流电机的控制 很简单,性能出众,直流电源也容易实 现。本文即主要介绍这种直流电机的驱 动及控制。

1.H 型桥式驱动电路

     直流电机驱动电路使用最广泛的就 是H型全桥式电路,这种驱动电路可以 很方便实现直流电机的四象限运行,分 别对应正转、正转制动、反转、反转制动。 它的基本原理图如图1所示。
     全桥式驱动电路的4只开关管都工 作在斩波状态,S1、S2为一组,S3、S4 为另一组,两组的状态互补,一组导通则 另一组必须关断。当S1、S2导通时,S3、 S4关断,电机两端加正向电压,可以实 现电机的正转或反转制动;当S3、S4导 通时,S1、S2关断,电机两端为反向电 压,电机反转或正转制动。


      在小车动作的过程中,我们要不断 地使电机在四个象限之间切换,即在正 转和反转之间切换,也就是在S1、S2导 通且S3、S4关断,到S1、S2关断且S3、 S4导通,这两种状态之间转换。在这种 情况下,理论上要求两组控制信号完全 互补,但是,由于实际的开关器件都存在 开通和关断时间,绝对的互补控制逻辑 必然导致上下桥臂直通短路,比如在上 桥臂关断的过程中,下桥臂导通了。这个过程可用图2说明。

因此,为了避免直通 短路且保证各个开关管动作之间的协同 性和同步性,两组控制信号在理论上要 求互为倒相的逻辑关系,而实际上却必须相差一个足够的死区时间,这个矫正过程既可以通过硬件实现,即在上下桥 臂的两组控制信号之间增加延时,也可 以通过软件实现(具体方法参看后文)。
     驱动电流不仅可以通过主开关管流通,而且还可以通过续流二极管流通。当电机处于制动状态时,电机便工作在发电状态,转子电流必须通过续流二极管流通,否则电机就会发热,严重时烧毁。
     开关管的选择对驱动电路的影响很大,开关管的选择宜遵循以下原则:
(1)由于驱动电路是功率输出,要求开关管输出功率较大;
(2)开关管的开通 和关断时间应尽可能小;
(3)小车使用的电源电压不高,因此开关管的饱和压降应该尽量低。
     在实际制作中,我们选用大功率达林顿管TIP122或场效应管IRF530,效果都还不错,为了使电路简化,建议使用集成有桥式电路的电机专用驱动芯片,如L298、LMD18200,性能比较稳定可靠。
     由于电机在正常工作时对电源的干扰很大,如果只用一组电源时会影响单片机的正常工作,所以我们选用双电源供电。一组5V给单片机和控制电路供电, 另外一组9V给电机供电。在控制部分和电机驱动部分之间用光耦隔开,以免影响控制部分电源的品质,并在达林顿管的基极加三极管驱动,可以给达林顿管提供足够大的基极电流。图3所示为采用TIP122的驱动电机电路,IOB8口为“0”,IOB9口输入PWM波时,电机正转,通过 改变PWM的占空比可以调节电机的速度。而当IOB9口为“0”,IOB8口输入PWM 波时,电机反转,同样通过改变PWM的占空比来调节电机的速度。

点击看大图

     图4为采用内部集成有两个桥式电 路的专用芯片L298所组成的电机驱动电路。驱动芯片L298是驱动二相和四相步进电机的专用芯片,我们利用它内部的 桥式电路来驱动直流电机,这种方法有一系列的优点。每一组PWM波用来控制一个电机的速度,而另外两个I/O口可以控制电机的正反转,控制比较简单,电路也很简单,一个芯片内包含有8个功率管,这样简化了电路的复杂性,如图所示IOB10、IOB11控制第一个电机的方向,IOB8输入的PWM控制第一个电机的速度;IOB12、IOB13控制第二个电机的方向,IOB9输入的PWM控制第二个电机的速度。

点击看大图

      LMD18200是美国国家半导体公司推出的专用于直流电动机驱动的H桥组件,同一芯片上集成有CMOS控制电路和DMOS功率器件。此种芯片瞬间驱动电流可达6A,正常工作电流可达3A,具有很强的驱动能力,无“shot-through”电流,而且此种芯片内部还具有过流保护的测量电路,只需要在LMD18200的8脚输出端测出电压和给定的电压比较即可保护电路过流,从而实现电路的过流保护功能。由LMD18200组成的电机驱动电路如图5所示。LMD18200的5脚为PWM 波输入端,通过改变PWM的占空比就可调节电机的速度,改变3脚的高低电平即可控制电机的正反转。此电路和以上几种驱动电路比较具有明显的优点,驱动功率大,稳定性好,实现方便,安全可靠。

点击看大图

2 .P W M 控制

     PWM(脉冲宽度调制)控制,通常 配合桥式驱动电路实现直流电机调速, 非常简单,且调速范围大,它的原理就 是直流斩波原理。如图1所示,若S3、S4 关断,S1、S2受PWM控制,假设高电平 导通,忽略开关管损耗,则在一个周期 内的导通时间为t,周期为T,波形如图 6,则电机两端的平均电压为: U="Vcc" t/ T=αVcc ,其中,α=t/T称为占空比,Vcc为电源电压(电源电压减去两个开关 管的饱和压降)。

点击在新窗口中浏览产品

      电机的转速与电机两端的电压成比例,而电机两端的电压与控制波形的占空比成正比,因此电机的速度与占空比成比例,占空比越大,电机转得越快,当占空比α=1时,电机转速最大。
     PWM控制波形的实现可以通过模拟 电路或数字电路实现,例如用555搭成的触发电路,但是,这种电路的占空比不能自动调节,不能用于自动控制小车的调 速。而目前使用的大多数单片机都可以直接输出这种PWM波形,或通过时序模拟输出,最适合小车的调速。我们使用的是凌阳公司的SPCE061单片机,它是16位单片机,频率最高达到49MHz,可提供2路PWM 直接输出,频率可调,占空比16级可调,控制电机的调速范围大,使用方便。SPCE061单片机有32个I/O口, 内部设有2个独立的计数器,完全可以模拟任意频率、占空比随意调节的PWM信号输出,用以控制电机调速。
     在实际制作过程中,我们认为控制信号的频率不需要太高,一般在400Hz以下为宜,占空比16级调节也完全可以满足调速要求,并且在小车行进的过程中,占空比不应该太高,在直线前进和转弯 的时候应该区别对待。若车速太快,则在 转弯的时候,方向不易控制;而车速太慢,则很浪费时间。这时图6可以根据具体情况慢慢调节。在2003年“简易智能电动车”的实际制作中,我们的小车驱动信号的占空比一般在8/16以下。

3.通过软件避免直通短路

     从前面的分析可知,桥式驱动电路中,由于开关管有开通和关断时间,因此存在上下桥臂直通短路的问题。直通短路的存在,容易使开关管发热,严重时烧毁开关管,同时也增加了开关管的能量损耗,浪费了小车宝贵的能量。由于现在的许多集成驱动芯片内部已经内置了死区保护(如LMD18200),这里主要介绍的是利用开关管等分立元件以及没有死区保护的集成芯片制作驱动电路时增加死区的方法。
     死区时间的问题,只有在正转变为反转的时候才存在,而在正转启动或反转启动的时候并没有,因此不需要修正。如果开关管的开通和关断时间非常小,或者在硬件电路中增加延时环节,都可以降低开关管的损耗和发热。当然,通过软件避免直通短路是最好的办法,它的操作简单,控制灵活。通过软件实现死区时间,就是在突然换向的时候,插入一个延时的环节,待开关管关断之后,再开通应该开通的开关管。图7为利用软件修正死区时间的流程图,在开关管每次换向的时候,不立即进行方向的切换,而是先使开关管关断一段时间,使其完全关断后再换向打开另外的开关管。这个关断时间由单片机软件延时实现。

4.总结

     以上主要分析了电机的全桥式驱动电路,这是直流电机调速使用最多的调速方法。目前市场上有很多种电机驱动的集成电路,效率高,电路简单,使用也比较广泛,但是其驱动方法大多与全桥式驱动一样。PWM控制方法配合桥式驱动电路,是目前直流电机调速最普遍的方法。

系统分类: 汽车电子
用户分类: 电机控制
标签: 无标签
来源: 转贴
发表评论 阅读全文(846) | 回复(5)

1

关于投票
直流电机的制动

DC MOTOR BRAKING

Ever have a need for your robot to stop quickly? Like who put that cliff/wall there anyways? Or perhaps maybe your robot loses control while going down hills? There are three ways to brake DC motors. Each way has it's own benefits and draw backs, so I will go over each for you to decide which is best.

Controls Method
This method requires an encoder placed onto a rotating part of your DC motor. You will have to write an algorithm that determines the current velocity of your motor, and sends a reverse command to your H-bridge until the final velocity equals zero. This method can let your robot balance motionless on a steep hill just by applying a reverse current to your motors.

Mechanical Method
The mechanical method is what is used on cars today. Basically you need something with very high friction and wear resistance, and then push it as strongly as possible to your wheel or axle. A servo actuated brake works well.

Electronic Method
This method is probably the least reliable, but the easiest to implement. The basic concept of this is that if you short the power and ground leads of your motor, the inductance created by your motor in one direction will power your motor in the opposite direction. Although your motor will still rotate, it will greatly resist the rotation. No controls or sensors or any circuits overheating. The disadvantage is that the effect of braking is determined by the motor you are using. Some motors brake better than others. The el-cheapo motors dont brake at all in my experience.

DC Electronic Breaking with MOSFET and Relay

So how do you short the leads when it is on a robot? Simple. Connect a MOSFET (transistor) and a relay as shown. The MOSFET turns on the relay, which creates a short between the motor leads. Turn the MOSFET on (set C high) with your microcontroller when you want to brake. Basically your motor will still have an H-bridge for normal control, but when you brake you turn the H-bridge off and use the braking circuit. And don't forget the heatsink and flyback diode! Important, or your circuit will melt/blow up.

系统分类: 工业控制
用户分类: 电机控制
标签: 无标签
来源: 整理
发表评论 阅读全文(577) | 回复(0)
总共 , 当前 /