ロボットアームを作ってみた‼ (プログラム編)
ロボットアームを組み終え、いよいよArduinoにプログラムを書き込み動かしてみたいと思います‼
まだ組み立てが終わってない方は、一つ前の記事、「ロボットアームを作ってみた‼(組み立て編)」をご覧ください。
※モーターの線はまだArduinoに配線しないようにしましょう。(モーター破損防止のため)
今回プログラムの参考にしたのはこちらの動画になります↓
それでは早速、やってみましょう!
①「開発環境」
※既に整っている方はこの章は飛ばしましょう。
Arduino IDEをというソフトを使います。
まだダウンロードされてない方は、下記のサイトの①をご参考にして、開発環境を整えましょう。
Arduino IDEでESP-WROOM-02(ESP8266)とESP-WROOM-32を使えるようにする!(Windows10)
②「プログラミング」
今回は参考動画に記載があったプログラムをそのままコピペさせていただきました。
有難いことにこれで手間なく無事動きます‼
参考動画に記載があったリンク↓一様貼っておきます。(こちらはダウンロードしなくても、下記のコードをコピペするだけで多分動くはずです。)
Link: https://drive.google.com/file/d/1vOdU…
※コードを書き込んだあと、サーボモーターが初期値に高速で移動するためアームが暴れます。
このとき、サーボモーターの初期値がズレているとアームが無理な挙動をしてサーボモーターが壊れる可能性があるので、モーターの線はまだ配線しないようにしましょう。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
/* This code for MeArm robot using joystick shield with arduino uno Please use orginal arduino uno I use power adaptor 12v Don't forget to adjust the servo position in 0 degree or 180 degree when attaching the servo horn Make sure the linkages are smooth, you can enlarge diameter */ #include <Servo.h> Servo servo_x; // create servo object to control a servo Servo servo_y; // create servo object to control a servo Servo servo_z; // create servo object to control a servo Servo servo_grip; // create servo object to control a servo // Declare the pins for the Button int x_pin = A0; int y_pin = A1; int z_pin = A2; int grip_pin = A3; int x_pos; // variable to store the servo position int y_pos; // variable to store the servo position int z_pos; // variable to store the servo position int grip_pos; // variable to store the servo position void setup() { Serial.begin(9600); // Define pin as input and activate the internal pull-up resistor //setup servo servo_x.attach(11); // attaches the servo x servo_y.attach(10); // attaches the servo y servo_z.attach(9); // attaches the servo z servo_grip.attach(5); // attaches the servo grip //origin position x_pos = 90; y_pos = 90; z_pos = 175; grip_pos = 0; servo_x.write(x_pos); servo_y.write(y_pos); servo_z.write(z_pos); servo_grip.write(grip_pos); } void loop() { // Read the value of the input int val_x = analogRead(x_pin); int val_y = analogRead(y_pin); int val_z = analogRead(z_pin); int val_grip = analogRead(grip_pin); delay(15); // joystick X======================================== if (val_x < 400) { if (x_pos < 180) { x_pos = x_pos + 1; servo_x.write(x_pos); } } else if (val_x > 750) { if (x_pos > 0) { x_pos = x_pos - 1; servo_x.write(x_pos); } } // joystick X======================================== // joystick Y======================================== if (val_y < 400) { if (y_pos < 120) { y_pos = y_pos + 1; servo_y.write(y_pos); } } else if (val_y > 750) { if (y_pos > 0) { y_pos = y_pos - 1; servo_y.write(y_pos); //check z pos if (z_pos < 150) { if (z_pos < 175) { z_pos = z_pos + 1; servo_z.write(z_pos); } } } } // joystick Y======================================== // joystick Z======================================== if (val_z < 400) { if (z_pos < 175) { z_pos = z_pos + 1; servo_z.write(z_pos); } } else if (val_z > 750 && y_pos > 40) { if (z_pos > 90) { z_pos = z_pos - 1; servo_z.write(z_pos); } } // joystick Z======================================== // joystick grip======================================== if (val_grip < 400) { if (grip_pos < 30) { grip_pos = grip_pos + 1; servo_grip.write(grip_pos); } } else if (val_grip > 750) { if (grip_pos > 0) { grip_pos = grip_pos - 1; servo_grip.write(grip_pos); } } // joystick grip======================================== Serial.print("x_axis: "); Serial.print(x_pos); Serial.print(", y_axis: "); Serial.print(y_pos); Serial.print(", z_axis: "); Serial.println(z_pos); Serial.print(", grip_axis: "); Serial.println(grip_pos); } |
| 軸名 | 役割 | モーターの取り付け位置 |
| X | 土台の回転(Base) | ロボットの一番底にある、アーム全体を左右(水平)に旋回させるサーボ |
| Y | 肩の前後(Shoulder) | 土台のすぐ上にある、アーム全体を前後に傾けるサーボ |
| Z | 肘の上下(Elbow) | アームの中央関節にある、先端部を上下に移動させるサーボ |
| Grip | 爪の開閉(Gripper) | アームの先端についている、物を挟む/開くためのサーボ |
Arduino及びジョイスティックの配線は次の様になります。
X→D11(1) Y→D10(2) Z→9(3) Grip→D5(4)
X軸から繋ぎ、実際に動作を確認してみましょう。ズレていたらサーボモーターのネジを外し、位置を変え調整しましょう。
すべての調整が終われば完成です‼
※無理に動かそうとしたり、モーターに異音が発生した場合は直ぐに停止させましょう。サーボモーターが壊れてしまうため。
調整も終わったらここで、すべてのネジロックをしちゃいましょう!
(自分は調整前にネジロックをしてしまったためかなり大変な思いをしました‼(笑))
③「結果」
想像以上に操作が難しい‼
でも、アームだけとはいえ本格的なロボットを作った達成感はあり良いです!
以上、ご閲覧ありがとうございました♪

1件のコメント