はじめに
1台目はこちらです。touch-sp.hatenablog.com
不評であったため2台目を作りました。
1台目は左右独立した後輪とボールキャスターでできていました。左右の後輪の回転速度を調整すればカーブや旋回ができます。
残念ながら大きな問題を抱えていてそれが直進安定性です。左右の後輪を同じように回転させるようにしてもどうしても完全一致してくれないのが問題でした。
2台目を作るときは左右独立はやめようと決めていました。そうするとどうやって曲がるのか?ステアリング機構を備える必要があります。
そこが今回一番苦労した点です。
完成品の画像
使用したもの
Arduino Uno R3 ×2 XBee ZB(S2C)ワイヤアンテナ型 ×2 XBeeシールド(スイッチサイエンス製) ×2 デュアルモータードライバDRV8835 サーボモーター (型番不明) タミヤ ユニバーサルプレート タミヤ ユニバーサルアーム タミヤ ユニバーサルプレート用スライドアダプター タミヤ 3速クランクギヤーボックスセット タミヤ バギー工作基本セット(4個のホイールと前輪のシャフトのみこのセットから使用)
その他、6Vニッケル水素電池(モーター、サーボ用)、9V電池用ボックス(Arduino用)、可変抵抗、キーボード用キーなど。
Arduinoスケッチ
コントローラー側
const int buttonON = LOW; const int buttonPin_1 = 8; const int buttonPin_2 = 9; const int buttonPin_3 = 10; const int potPin = A0; int potVal; int myangle; int angle_previous; void setup() { pinMode(buttonPin_1, INPUT_PULLUP); pinMode(buttonPin_2, INPUT_PULLUP); pinMode(buttonPin_3, INPUT_PULLUP); angle_previous = 90; Serial.begin(9600); } void loop() { if(digitalRead(buttonPin_1) == buttonON){ Serial.write(0); } if(digitalRead(buttonPin_2) == buttonON){ Serial.write(1); } if(digitalRead(buttonPin_3) == buttonON){ Serial.write(2); } potVal = analogRead(potPin); myangle = map(potVal, 0, 1023, 65, 115); if(abs(angle_previous - myangle) >10){ Serial.write(myangle); angle_previous = myangle; } }
車側
#include <Servo.h> Servo myServo; const int servo_pin = 5; const int mode_pin = 7; const int motor_enbl = 9; const int motor_phase = 10; void setup() { pinMode(mode_pin, OUTPUT); //modeはHIGH digitalWrite(mode_pin, HIGH); pinMode(motor_enbl, OUTPUT); pinMode(motor_phase, OUTPUT); //motorはストップ digitalWrite(motor_phase, HIGH); analogWrite(motor_enbl, 0); myServo.attach(servo_pin); myServo.write(90); Serial.begin(9600); } void loop() { if(Serial.available()>0){ int read_serial; read_serial = Serial.read(); //ストップ if(read_serial==1){ analogWrite(motor_enbl, 0); } //前進 if(read_serial==0){ digitalWrite(motor_phase, HIGH); analogWrite(motor_enbl, 255); } //後進 if(read_serial==2){ digitalWrite(motor_phase, LOW); analogWrite(motor_enbl, 255); } //サーボ if(read_serial >=65 && read_serial <= 115){ myServo.write(read_serial); } } }
最後に
子供のためにということで始めましたが結局自分が楽しんでいます。2022年8月15日追記
続きの記事を書きました。touch-sp.hatenablog.com