1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

mbedとrosでドローンを飛ばす(3)~xbeeと加速度センサ(bmi088)の設定~

Last updated at Posted at 2020-11-16

こんにちは。takopiyoです。今回はxbeeの設定と、加速度センサを使えるようにします。

xbeeの設定を行う

xbeeの設定するためにxctuを使います。
https://www.youtube.com/watch?v=cxNGPb4Mnpg
を参考にインストールしました。
.runファイルを実行するときに

sudo -s

コマンドで管理者権限がある状態で実行しないと、eclipseのエラーが出ました。
(参考)
https://www.digi.com/support/forum/54212/

インストール後下のコマンドで実行してみましたが、エラーがでているようです。

sudo -s
sudo /opt/Digi/XCTU-NG/app

(略)
(XCTU:12045): GLib-CRITICAL **: 10:44:08.720: g_base64_encode_step: assertion 'in != NULL' failed

(XCTU:12045): IBUS-WARNING **: 10:44:09.400: The owner of /home/takeshi/.config/ibus/bus is not root!

(XCTU:12045): Gtk-WARNING **: 10:44:09.431: Negative content height -1 (allocation 5, extents 3x3) while allocating gadget (node progressbar, owner GtkProgressBar)

guiは表示されますが、ボタンが反応せず使えませんでした。
ここを参考にすれば直せるかもしれませんが、cutecomを使う方法を見つけたので、そっちでやることにしました。


このブログを参考に、cutecomで2つのxbeeのボードレートを115200に変更し、送信先ビットの設定を行いました。

xbeeとpc、それぞれとシリアル通信を行うmbedのプログラムをここを参考に
作製し、無線通信ができることを確認しました。

xbee_test.cpp

# include "mbed.h"
 
Serial xbee(p9, p10); //Creates a variable for serial comunication through pin 9 and 10
 
DigitalOut rst1(p11); //Digital reset for the XBee, 200ns for reset
 
DigitalOut myled(LED3);//Create variable for Led 3 on the mbed
DigitalOut myled2(LED4);//Create variable for Led 4 on the mbed
 
Serial pc(USBTX, USBRX);//Opens up serial communication through the USB port via the computer
 
int main() {
    rst1 = 0; //Set reset pin to 0
    myled = 0;//Set LED3 to 0
    myled2= 0;//Set LED4 to 0
    wait_ms(1);//Wait at least one millisecond
    rst1 = 1;//Set reset pin to 1
    wait_ms(1);//Wait another millisecond
    xbee.baud(115200);
    pc.baud(115200);
 
    while (1) {//Neverending Loop
        if (pc.readable()) {//Checking for serial comminication
            myled = !myled; //Turn Led 3 Off
            xbee.putc(pc.getc()); //XBee write whatever the PC is sending
        }
        if (xbee.readable()){
            myled2 = !myled2;   
            pc.putc(xbee.getc());
        }
    }
}

xbeeでros通信を行う

~/ros/lib/ros_lib/ros/node_handle.hを以下のように変更します。

ros.h
(変更前)
Hardware hardware_{};
(変更後)
namespace ros
Hardware hardware_{p9, p10, 115200};

launchファイルのパラメータを変更して実行します。

joy.launch
<?xml version="1.0"?>
<launch>

  <node name="joy_node" pkg="joy" type="joy_node"/>
  <node name="joy_state_publisher" pkg="drone_mbed" type="joy_state_publisher"/>

  <node pkg="rosserial_python" type="serial_node.py" name="serial_node">
    <param name="port" value="/dev/ttyUSB1"/>
    <param name="baud" value="115200"/>
  </node>

</launch>

~結果~
無線通信ができて、joyスティックから速度の操作が行えました。
しかしすぐにモータの挙動がおかしくなりました。duty比を更新するとモータの挙動自体は変化しますが、途切れ途切れの回転になったり、一つのモータだけが回転したり、よくわからない動きをしました。
ターミナルを確認すると

[ERROR] : Mismatched protocol version in packet: lost sync or rosserial_python is from different ros release than the rosserial client

というエラーが出ていたり、クライアントの同期が失われたというエラーが出たりしました。
とりあえず今はxbee経由で回転を制御できることが確認できればいいので、これの解決は後回しにします。
奇跡的に全く同じエラーが出ている人がいらっしゃったので、これを参考に修正する予定です。
https://hogepad.com/mbedrosserial%E3%81%AEbuffe-rsize%E3%82%92%E5%A4%89%E6%9B%B4%E3%81%99%E3%82%8B

加速度センサーを動かしてみる

https://www.switch-science.com/catalog/5343/
センサの基盤の裏のic2アドレスを決めるジャンパをdefaultで行いました。
プログラムはこれを使います。
https://os.mbed.com/teams/altb_pmic/code/Test_BMI088/log/577a6606809f/BMI088.h/

ピンの名前をLPC1768の名前に変更し,コンパイルして実行しました。
mbedからのシリアル出力を確認したところ、このプログラムの作者の方も言っているとおり、並進方向の加速度が出力されません。これを解決して使えるようにします。

arduinoのライブラリをmbedに移植する

これによるとarduinoのライブラリがあるようです。

これを移植します。(並進方向に問題があるライブラリもこれを移植しようとしてたみたいです。)
githubのプログラムを参考にしながら、並進方向の実装を修正を加えて動くようにしました。↓
https://os.mbed.com/users/takepiyo/code/BMI088/

ここを参考に、ターミナルで出力を確認できました。(cutecomだと文字化けしてうまく表示できませんでした。)

acc: 0.0790 0.3233 9.7663
gyr: -0.0170 0.0447 -0.0639
temp: 8087
acc: 0.0701 0.3054 9.7860
gyr: 0.0000 0.0000 0.0000
temp: 8087
acc: 0.0647 0.3377 9.7789
gyr: -0.1747 -0.0128 -0.0788
temp: 8087

これですべてのモジュールを単体で動かすことができました。次回はユニバーサル基板を用いて回路を組んでいきます。
ここまで読んでいただきありがとうございました。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?