2
1

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 1 year has passed since last update.

【備忘録】Raspberry Pi の立ち上げ時にMAVProxyを自動で起動する

Last updated at Posted at 2022-06-17

はじめに

これまで MAVProxy を介して複数の端末に情報を転送したり、RTK情報を転送する方法について試してきました。
MAVproxy経由でRTK情報を転送することでQGCでNTRIPが使えるようになり便利なツールだなと思いましたが、ターミナルからコマンドを打ち込んでいくのが手間になってきました。
もしRaspberry Pi の立ち上げ時にMAVProxyを自動で起動できれば楽なのにな。。。
という所から挑戦した次第です。

参考にしたのはこちらです。

解説もしっかりされていますので、ソフトかじったことのある人であればイメージしやすいかと思います。

手順

1.設定ファイルを作成する
2.スクリプトに権限を付与する
3.パスをコピーする
4.設定ファイルが動くか確認する
5.起動時に動くように設定する
6.再起動して確認する

1. 設定ファイルを作成する

権限の関係でうまく動かなかい場合がありますので注意が必要です。
私の場合はユーザー権限にして パスを/home/pi/.local/bin/ としたら上手く動きました。

sudo nano ~/startup_mav.sh で起動スクリプトを作成します。
記入が終わりましたら ctrl+XY で保存します

startup_mav.sh

#!/bin/bash
export LOCALAPPDATA="LOCALAPPDATA"
screen -L -Logfile vehicle_proxy.log -S vehicle_proxy -d -m bash -c "/home/pi/.local/bin/mavproxy.py --force-connected --master=/dev/ttyACM* --out=AAA.AAA.AA.A:14550 --out=BBB.BBB.BB.B:14550"

起動時に NTRIP サーバへアクセスしたい場合は以下を追加します。

--cmd='module load ntrip;ntrip set casterXXX;ntrip set mountpoint XXX;ntrip set username XXX;ntrip set password XXX;ntrip start'

※ 名称はstartup_mav.shとしていますが自由につけてください
※ AAA.AAA.AA.AはPCのIPを記載します
※ BBB.BBB.BB.BはスマートフォンのIPを記載します
※ ttyACM*はautopilotと接続しているシリアルポートを記載します
  確認方法 ⇒ https://qiita.com/m2_labo/items/7823fb26197fa5f5ff23

NTRIP情報
XXXXはNTRIP配信先の情報を入力します。
MAVProxy起動時に こちら で紹介したコマンドを行自動的に実行しています。

2. スクリプトに権限を付与する

参考元の(rc.localで動かす)方法
sudo chmod +x ~/startup_mav.sh

私の場合 crontab(ユーザー権限)で動かす為、以下の様にし対応しています。
sudo chmod 777 startup_mav.sh

3. パスをコピーする

echo $(pwd)"/startup_mav.sh"

4. 設定ファイルが動くか確認する

bash startup_mav.sh 等を打ち込んで起動時に通信が開始されるか確認する
パスが通っているので ./startup_mav.sh でも走ると思われます

5. 起動時に動くように設定する

私の場合 rc.local (root権限)ではうまく走らなかったので、crontab(ユーザー権限)で動かしています。
こちらを参考に入力を行っています

crontab -e と打ち込むと編集ができます。
'@reboot /home/pi/startup_mav.sh` を最下段に追加します。

crontab

# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

@reboot /home/pi/startup_mav.sh

6. 再起動して確認する

一度電源を落としてからしばらく放置させ電源を入れます。
起動が完了したタイミングで地上局を立ち上げると、自動的に接続が行われていれば成功です。
上手くいかない場合は、時間をおいて何回か試してください。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?