LoginSignup
8
5

More than 5 years have passed since last update.

セグウェイを自作してみた ~電子回路組立編~

Last updated at Posted at 2016-11-08

シリーズ目次


この分野では門外漢の私が、「電子制御」をまったく勉強せずに
セグウェイを作ってみようと思います。

配線図

arduino.png

基本的にモーターシールド と arduino は 全部接続する(わからないから)
ただし 下表の ピン はジャイロセンサーにつなぐ

arduino ジャイロセンサー 上図
3.3v VCC 赤線
GND GND 緑線
A5 SCL 青線
A4 SDA 黒線
  1. モーターの動力は, 12V のバッテリー×2
  2. arduino の 動力は, モバイルバッテリーから供給するため

始動するには
1. バッテリーとモーターシールドの間の「こたつスイッチ」と
2. モバイルバッテリーのスイッチを

ON にして始動します。

テスト

上図の状態で arduino に 以下の プログラムを 入れて
ジャイロセンサーのログを取ってみます。

ジャイロセンサーの制御のために下記のモジュールを使います。
これは、arduino に標準で入っていないので、
下記の URL を参考に 各環境に モジュールを追加してください

MPU-6050 Accelerometer + Gyro

test.ino
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"

/*  MPU-6050 Accelerometer + Gyro */
MPU6050 accelgyro;

void setup() {

    Wire.begin();
    Serial.begin(9600);

    // initialize device
    accelgyro.initialize();
    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");

}

void loop() {

  int16_t ax, ay, az;
  int16_t gx, gy, gz;
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
  float acc_x = ax / 16384.0;
  float acc_y = ay / 16384.0; 
  float acc_z = az / 16384.0; 
  float rate_X = atan2(acc_x, acc_z) * 360 / 2.0 / PI; 
  float rate_Y = atan2(acc_y, acc_z) * 360 / 2.0 / PI;
  float rate_Z = atan2(acc_x, acc_y) * 180 / 2.0 / PI;

  Serial.print(rate_X);
  Serial.print("\t"); 
  Serial.print(rate_Y);
  Serial.print("\t"); 
  Serial.print(rate_Z);
  Serial.print("\t"); 
  Serial.println("");
 }

ログです。

MPU6050 connection successful
Initializing Mortor Driver digital pins...
3.80    -2.61   62.21   
4.21    -2.29   59.24   
3.96    -2.11   59.01   
4.10    -2.42   60.26   
3.86    -2.58   61.87   
3.46    -2.83   64.63   
4.27    -2.49   60.12   
3.84    -2.40   60.95   
4.26    -2.19   58.56   
4.01    -2.33   60.09   
3.95    -2.30   60.09       
4.12    -2.50   60.62       
3.65    -2.47   62.04       
3.86    -2.14   59.49       
3.87    -2.55   61.66       
4.10    -2.40   60.14       
3.74    -2.94   64.09       
3.89    -2.22   59.84       
3.85    -2.22   59.97       
3.81    -3.00   64.11       
3.96    -2.01   58.46       

ジャイロセンサーを傾けてみて
ログの下表の値が思い通りに変化していたら 成功です。

rate_X rate_Y rate_Z
3.80 -2.61 62.21
4.21 -2.29 59.24
3.96 -2.11 59.01
4.10 -2.42 60.26
3.86 -2.58 61.87

ジャイロセンサーについて

上表のログでは、短いので 分かりにくいですが
何もしなくても ジャイロセンサーの値は 動いています。

静止状態の rate_X のログ
log.png

これを いちいちモーターに出力命令として送出していたら
モーター静止することができません
((((;゚Д゚))))ガクガクブルブル

ですので、プログラム側で、滑らかにする処理が必要であることがわかりました


次回は、プログラム編についてお届けします。

8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5