サーボモーターの速度を変更する必要があるプロジェクトに取り組んでいます。私が使用しているハードウェアは Arduino Mega 2560 ボードで、Servo.h ライブラリを使用してサーボを制御しています。サーボは o から 180 度まで回転します。プロジェクトで 12 個のサーボ モーターを使用しており、それらを同時に制御する必要があります。方法はありますか?
5 に答える
delay()
しばらくの間またはforループで関数を使用できます
例:
Servo s;
s.attach(9);
for(int i=0 ; i<180 ; i++)
{
s.write(i);
delay(10); //10 milisecond
}
それらがすべて同じ程度である場合は、以下のコードを試してください。
最上部(「{}」の間ではない) :
#include <Servo.h>
Servo S1;
Servo S2;
Servo S3;
Servo S4;
Servo S5;
Servo S6;
Servo S7;
Servo S8;
Servo S9;
Servo S10;
Servo S11;
Servo S12;
これを入れてください Setup
:
S1.attach(1);
S2.attach(2);
S3.attach(3);
S4.attach(4);
S5.attach(5);
S6.attach(6);
S7.attach(7);
S8.attach(8);
S9.attach(9);
S10.attach(10);
S11.attach(11);
S12.attach(12);
ピン番号を変更する必要があります。
これをどこにでも置くだけです(「{}」の間ではなく):
void TurnServos(int toDegree){
servosAt = S1.read;
if(servosAt == toDegree){
}
if(servosAt > toDegree){
while(S1.read > toDegree){
int currentToDegree = S1.read - 1;
S1.write(currentToDegree);
S2.write(currentToDegree);
S3.write(currentToDegree);
S4.write(currentToDegree);
S5.write(currentToDegree);
S6.write(currentToDegree);
S7.write(currentToDegree);
S8.write(currentToDegree);
S9.write(currentToDegree);
S10.write(currentToDegree);
S11.write(currentToDegree);
S12.write(currentToDegree);
delay(10); //Adjust this to make it faster or slower.
}
}
if(servosAt < toDegree){
while(S1.read < toDegree){
int currentToDegree = S1.read + 1;
S1.write(currentToDegree);
S2.write(currentToDegree);
S3.write(currentToDegree);
S4.write(currentToDegree);
S5.write(currentToDegree);
S6.write(currentToDegree);
S7.write(currentToDegree);
S8.write(currentToDegree);
S9.write(currentToDegree);
S10.write(currentToDegree);
S11.write(currentToDegree);
S12.write(currentToDegree);
delay(10); //Adjust this to make it faster or slower.
}
}
}
void ClearServos(){
int startDegree = 90; //Change this number to anything you want.
S1.write(startDegree);
S2.write(startDegree);
S3.write(startDegree);
S4.write(startDegree);
S5.write(startDegree);
S6.write(startDegree);
S7.write(startDegree);
S8.write(startDegree);
S9.write(startDegree);
S10.write(startDegree);
S11.write(startDegree);
S12.write(startDegree);
}
使い方:サーボをいじる前
にsetup
、セットアップに入れるように言った部分の後で、使用ClearServos();
するサーボを準備するために使用します。(必ずしもそうとは限りませんが、そのまま使用した場合どうなるかはわかりませんがS1.read
、サーボの位置がずれていれば問題は解決します。問題なければ回避できますが、私は可能であればそれを使用する必要があると思います。) それらはすべて 90 度に回転します。startDegree
(90度は の変数で変更できますvoid ClearServos
。)
それらを回すには、 を使用しますTurnServos(90);
。90 は、回転させたい角度です。
Mega または 12 サーボを持っていないため、これをテストしていません。これは巨大なため、エラーに気付いた場合はコメントしてください。私はこれに多くの時間を費やしたので、お役に立てば幸いです。:)
たぶん、サーボモーターの前にいくつかの抵抗をサーボの VCC ピンに直列に接続して、電圧を下げることができます。したがって、それを遅くします。ただし、これにより、サーボが「一定の」速度になります。
別の方法としては、サーボ VCC 接続の間にトランジスタを配置し、ベース ピンに PWM を設定して電流を調整する (速度を調整する) こともできますが、間にマルチプレクサを使用していない場合は、サーボごとに追加のピンが必要になります。設計が少し複雑になる可能性があります。
90-null に最も近い delayMicroseconds(value) は、タイムラプス リグのパンとキャリッジの両方の 360 サーボで最も遅く、メカニカル シャッター クリッカー (ミニ標準サーボ) に合わせてシュート ムーブ シュートします。
サーボライブラリのWriteMicroseconds(...)関数は、サーボ速度を設定します。
詳細については、をクリックしてください