2013年7月10日 星期三

比例控制 Proportional control (P)

我們可以使用比例控制去讓機器人滑順地停止。概念是將電力和差距呈比例關係。差距是目標位置減現在位置(測量值)。電力大小為差距的大小的比例值而機器人移動方向為差距的正負。當差距等於零時,機器人靜止。當差距為正時,機器人向前。當差距為負時,機器人向後。我們使用角度感應器來測量差距。

電力式:電力 = 常數×差距 = 常數×(目標 - 測量) = K * (target - measurement)

We can use the Proportional control (P) to let the robot smooth stop.  The concept is that we can let the power be controlled proportionally by distance(error).  The distance is defined as the target position minus now position(measurement).  The magnitude of power is proportion of the magnitude of distance and The direction of the robot is the direction of distance.  If the distance is zero, the robot is static.  If the distance is positive, the robot moves forward.  If the distance is negative, the robot moves backward. We use degrees sensor to measure the distance.

The power formula is:  Power = constant × distance = K * (target - measurement)

Example:

task main()
{
int power,K,target,measurement;
K = 1;
target = 1000;
measurement = MotorRotationCount(OUT_A);
while(1)
{
measurement = MotorRotationCount(OUT_A);
power = K * (target - measurement);
OnFwd(OUT_AC,power);
}
}