スマホで動くロボットアームを作る
続き
ESP-32のスターター キットに入っているステッピングモーターを回します。
2048パルスで1回転。モーター自体は32パルスで1回転で1:64のギヤで減速
小っちゃなロボットアームならこのモーターでも作れそうな速度感と分解能
esp32で駆動の様子
このプログラムを使用
int outPorts[] = {14, 27, 26, 25};
void setup() {
// set pins to output
for (int i = 0; i < 4; i++) {
pinMode(outPorts[i], OUTPUT);
}
}
void loop()
{
// Rotate a full turn
moveSteps(true, 32 * 64, 3);
delay(1000);
// Rotate a full turn towards another direction
moveSteps(false, 32 * 64, 3);
delay(1000);
}
//Suggestion: the motor turns precisely when the ms range is between 3 and 20
void moveSteps(bool dir, int steps, byte ms) {
for (unsigned long i = 0; i < steps; i++) {
moveOneStep(dir); // Rotate a step
delay(constrain(ms,3,20)); // Control the speed
}
}
void moveOneStep(bool dir) {
// Define a variable, use four low bit to indicate the state of port
static byte out = 0x01;
// Decide the shift direction according to the rotation direction
if (dir) { // ring shift left
out != 0x08 ? out = out << 1 : out = 0x01;
}
else { // ring shift right
out != 0x01 ? out = out >> 1 : out = 0x08;
}
// Output singal to each port
for (int i = 0; i < 4; i++) {
digitalWrite(outPorts[i], (out & (0x01 << i)) ? HIGH : LOW);
}
}
void moveAround(bool dir, int turns, byte ms){
for(int i=0;i<turns;i++)
moveSteps(dir,32*64,ms);
}
void moveAngle(bool dir, int angle, byte ms){
moveSteps(dir,(angle*32*64/360),ms);
}
正逆転360度を繰り返すプログラムですがこの方式だと1つのステッピングモーターに付き4本の信号線が必要になるので5軸で20本、6軸で24本と多いのとプログラムも複雑になりそうなので「少し賢くなったプロッター」でも使った1つに付き2本の信号線で行けるドライバのA4988を使って行こうと思います。
A4988は注文済み
実際に5個のモーターを動かしながらどのようにしてコントロールするかを考えるのに必要
早くほしい所です。
と、言ってもコントロール方法など何も決まっていませんが!
また、更新します。