This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

7.c. Advanced Line Following with 3pi: PID Control (Pololu 3pi Robot User’s Guide) 日本語訳【非公式】

Last updated at Posted at 2019-05-18

これは Pololu 3pi Robot User’s Guide ≫ 7.c. Advanced Line Following with 3pi: PID Control の非公式日本語訳です。
目次
前: 7.b. A Simple Line-Following Algorithm for 3pi
次: 8. Example Project #2: Maze Solving

7.c. Advanced Line Following with 3pi: PID Control

A more advanced line following program for the 3pi is available in the folder examples\atmegaxx8\3pi-linefollower-pid.

3piのより高度なライン追跡プログラムは examples\atmegaxx8\3pi-linefollower-pid にあります。

Note: An Arduino-compatible version of this sample program can be downloaded as part of the Pololu Arduino Libraries (see Section 5.g).

注意:このサンプルプログラムのArduino互換バージョンは Pololu Arduino Libraries の一部としてダウンロードできます(Section 5.gを参照)。

The technique used in this example program, known as PID control, addresses some of the problems that you might have noticed with the previous example, and it should allow you to greatly increase your robot’s line following speed. Most importantly, PID control uses continuous functions to compute the motor speeds, so that the jerkiness of the previous example can be replaced by a smooth response. PID stands for Proportional, Integral, Derivative; these are the three input values used in a simple formula to compute the speed that your robot should turn left or right.

このプログラム例で使用されているPID制御と呼ばれる手法は、先の例で気付いたかもしれないいくつかの課題への取り組んでいるため、ロボットのライン追跡スピードを大幅に向上することができます。最も重要なこととして、PID制御は連続関数を使ってモーター速度を計算するため、先の例のぎこちなさを滑らかな応答に置き換えることができます。PIDは比例、積分、微分を内包します。これらは、ロボットが左右に曲がる際の速度を計算するための簡単な数式で使用される3つの入力値です。

  • The proportional value is approximately proportional to your robot’s position with respect to the line. That is, if your robot is precisely centered on the line, we expect a proportional value of exactly 0. If it is to the left of the line, the proportional term will be a positive number, and to the right of the line, it will be negative. This is computed from the result returned by read_line() simply by subtracting 2000.
  • The integral value records the history of your robot’s motion: it is a sum of all of the values of the proportional term that were recorded since the robot started running.
  • The derivative is the rate of change of the proportional value. We compute it in this example as the difference of the last two proportional values.
  • 比例値は、ラインに対するロボットの位置にほぼ比例します。つまり、ロボットが正確にラインの中央にある場合、比例値はちょうど0になることを期待します。ロボットがラインの左側にある場合は比例項は正の値になり、ラインの右側にある場合は負の値になります。これはread_line()の戻り値から単純に2000を引いて計算されます。

  • 積分値は、ロボットの動作の履歴を記録します。これはロボットが動作を開始してから記録された比例項のすべての値の合計です。

  • 微分値(導関数)は比例値の変化率です。この例では、直近の2つの比例値の差として計算します。

Here is the section of code that computes the PID input values:

これはPIDの入力値を計算するスニペットです。

libpololu-avr\examples\atmega328p\3pi-linefollower-pid\test.c
// Get the position of the line.  Note that we *must* provide
// the "sensors" argument to read_line() here, even though we
// are not interested in the individual sensor readings.
unsigned int position = read_line(sensors,IR_EMITTERS_ON);

// The "proportional" term should be 0 when we are on the line.
int proportional = ((int)position) - 2000;

// Compute the derivative (change) and integral (sum) of the
// position.
int derivative = proportional - last_proportional;
integral += proportional;

// Remember the last position.
last_proportional = proportional;

Note that we cast the variable position to an int type in the formula for proportional. An unsigned int can only store positive values, so the expression position-2000, without casting, would lead to a negative overflow. In this particular case, it actually wouldn’t affect the results, but it is always a good idea to use casting to avoid unexpected behavior.

proportionalの計算式で変数positionをint型にキャストしていることに注意して下さい。unsigned int は正の値しか格納できないため、キャストしないで式position-2000を実行すると負のオーバーフローが発生します。このケースでは、実際には結果に影響しませんが、予期しない動作を避けるためにキャストを使用することは常に良い考えです。

Each of these input values provides a different kind of information. The next step is a simple formula that combines all of the values into one variable, which is then used to determine the motor speeds:

これらの入力値はそれぞれ異なる種類の情報を提供します。次のステップは、すべての値を1つの変数にまとめる簡単な式です。この変数を使用して、モーターの速度を決定します。

libpololu-avr\examples\atmega328p\3pi-linefollower-pid\test.c
// Compute the difference between the two motor power settings,
// m1 - m2.  If this is a positive number the robot will turn
// to the right.  If it is a negative number, the robot will
// turn to the left, and the magnitude of the number determines
// the sharpness of the turn.
int power_difference = proportional/20 + integral/10000 + derivative*3/2;

// Compute the actual motor settings.  We never set either motor
// to a negative value.
const int max = 60;
if(power_difference > max)
    power_difference = max;
if(power_difference < -max)
    power_difference = -max;

if(power_difference < 0)
    set_motors(max+power_difference, max);
else
    set_motors(max, max-power_difference);

The values 1/20, 1/10000, and 3/2 represent adjustable parameters that determine how your 3pi will react to the line. The particular values chosen for this example were somewhat arbitrarily picked, and while they work sufficiently for typical line following, there is plenty of room to improve them. In general, increasing these PID parameters will make power_difference larger, causing stronger reactions, while decreasing them will make the reactions weaker. It’s up to you to think about the different values and experiment with your robot to determine what effect each parameter has. This example gives the motors a maximum speed of 100, which is a safe initial value. Once you have adjusted the parameters to work well at a speed of 100, try increasing the speed. You’ll probably need to readjust the parameters as the maximum speed increases. By gradually increasing the maximum speed and tuning the parameters, see if you can get your 3pi to run as fast as possible! We have been able to run 3pis with a maximum speed of 255 on courses with 6"-radius curves, all by finding the right PID parameters.

1/201/100003/2は3piがラインにどのように反応するかを決定する調整パラメタです。この例で採用された値はやや恣意的に選ばれており、典型的なライン追跡にとって十分に作用しますが、改善の余地が十分あります。一般的にこれらのPIDパラメタを大きくするとpower_differenceが大きくなって強い反応性を引き起こし、パラメタを小さくすると反応性が弱くなります。それぞれのパラメタがどのように作用するかを判断する為に、いろいろな値を検討し、ロボットを使って実験するはあなた次第です。この例ではモーターに最高速度100を安全な初期値として与えます。速度100でうまく動作するようにパラメタを調整したら、速度を上げてみてください。最高速度を上げると、おそらくパラメタを再調整する必要があります。最高速度を徐々に上げてパラメタを調整することで、3piをできる限り速く走行できることを確認してください。適切なPIDパラメタを見つけることで、私たちは半径6インチのカーブを持つコースで最高速度255で3piを走行することができました。

Please see Section 2 of the 3pi robot videos gallery for videos of 3pi line followers using tuned PID and higher maximum speeds.

調整されたPID制御で最高速度でラインを追跡する3piのビデオは3pi robot videosギャラリーのSection 2を参照してください。

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up