Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/oldmakers/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340
倒立振子を作る

https://blog.with2.net/link/?1965529

倒立振子を作る

https://blog.with2.net/link/?1965529

Arduinoでの電子工作次号機は倒立振子としました。前号で紹介した参考サイトの他にも探しているうちに色々と見つかってきました。

倒立振子の製作例には大きく分けてモータの種類によってふたつに分かれるようです。

DCモータ(減速機付き)を使うか、ステッピングモータを使うかです。ステッピングモータはCモータ(減速機付き)のようなバックラッシュがないので安定した制御が出来るようです。ステッピングモータは低速域でのトルクが大きいので、低速ではステッピングモータが適しており、ネット上での作例を見てみるとステッピングモータを使った作例のほうが安定した動作をしているようです。

となればステッピングモータ式を製作ということになるのですが、今回はDCモータ方式を製作します。理由はネットのsketch例ではDCモータ方式は古典的なPID制御を採用しているのでOLDMAKERとしては昔取った杵柄ということもあってとっつき易いのです。

今回の製作にあたって実際に参考にしたのはSainsmart InstaBotsというところから販売されている製品です。

http://www.instructables.com/id/InstaBots-Upright-Rover/

sketchはオープンソースで下記のURLで公開されています。

https://s3-ap-northeast-1.amazonaws.com/sain-amzn/20/20-011-403/20-011-403.zip

ところで、PID制御とはということで昔の教科書を引っ張り出してきて復習してみました。
P…比例(Proportional)
I…積分(Integral)
D…微分(Derivative)
目標値との差(偏差)に比例して修正する比例動作(Proportional Action:P)と、過去の偏差の累積値を元に修正する積分動作(Integral Action:I)と、偏差の変化の速度を元に修正する微分動作(Derivative:D)で制御をする方式で、古典的な手法です。

倒立振子では機体が真直ぐに立っている状態を目標値とすれば、そこからの傾き角度が偏差ということになります。その偏差を目標値に修正すべくPIDの三要素で修正するわけですがPIDのどの要素を重視するかによって偏差の修正のし易さが変わってきます。比例制御だけに頼ると残留偏差が残ります、残留偏差をなくすべく積分制御を取り入れるが応答時間が遅くなるのと外乱への対応が難しくなる問題がでてきます。そこで微分制御を加えて急激な変化には早く修正するようにしてより早く、より正確に偏差を修正しようということです。

なんとか思い出してきました。

それでPIDのどの要素をどれだけ効かせるかという塩梅を係数としてかけてやるということです。

操作量=Kp×偏差+Ki×偏差の累積値+Kd×前回偏差との差
(比例項)  (積分項)   (微分項)

記号で表すと

 MVn = MVn-1 + ΔMVn
ΔMV
n = Kp(en-en-1) + Ki en + Kd((en-en-1) – (en-1-en-2))

MVn、MVn-1:今回、前回操作量  ΔMVn:今回操作量差分
en,en-1,en-2:今回、前回、前々回の偏差

次の疑問はKp,Ki,Kdはどうやって決めるかということですが、簡単です。OLDMAKERSの世界では試行錯誤あるのみです。自動制御の世界ではステップ応答法、限界感度やオートチューニングなどと色々あるようですが、筆者の結論は試行錯誤です。

これで理論武装はひとまず出来たのでハードの構想にとりかかります。

参考にするInstaBotsの倒立振子と同じく

    • モータドライバはL298N
  • ジャイロセンサはMPU6050

モータはタミヤのダブルギヤボックスとします。

回路図を描いてみました。

倒立の確認が目標なのでInstaBotsのsketchからリモコン関連の命令文は削除しておきます。そのままでも問題ありませんが、後の理解が簡単になるので。

途中の製作工程は省略して本体は完成しました。

さて、試運転です。

Kp,Ki,Kdの値はとりあえずInstaBotsで使われている値を入れてみます。不安定ではありますが倒立しています。もう少し苦労するかとは思っていたのですがいささか拍子抜けの感でもあります。ここから各係数の値を前後に変化させながら挙動がどうなるのかを試行錯誤していきます。

結論として、

  • Kp = 15
  • Ki = 0.1
  • Kd = 250

で落ち着きました。主に効果のある係数はKdのようです。100~700ぐらいまで試してみました。

倒立の具合をご覧ください。

PID部分のsketchは以下のようにしました。

void myPID(){
kp =15 ;
kd =250;
ki = 0.1;

unsigned long now = millis(); 注:ここから6行はフィルター
float dt = (now – preTime) / 1000.0;
preTime = now;
float K = 0.8;
float A = K / (K + dt);
f_angle = A * (f_angle + omega * dt) + (1 – A) * r_angle;  注:フィルタ通過後の値
timeChange = (now – lastTime);
if(timeChange >= SampleTime){
Input = f_angle;
error = Input;  注:比例制御
errSum += error * timeChange; 注:積分制御
dErr = (error – lastErr) / timeChange; 注:微分制御
Output = kp * error + ki * errSum + kd * dErr;
LOutput = Output ;
ROutput = Output ;
lastErr = error;
lastTime = now;
}
}

シェアする

フォローする