LoginSignup
1
1

More than 3 years have passed since last update.

Parrot MamboをMac(Mojave)から操作する - 2019版

Last updated at Posted at 2019-07-22

Parrot manboを飛ばすのにrolling-spiderというライブラリーをベースにした記事がいくつかあるのですが、2019/7の私の環境では動作しなかったため、改めていくつかのライブラリーを試してみました。
nobleというBluetoothライブラリーが最新Mac、最新Xcode、最新Node.jsでの動作で追いついていないようで、このあたりは気が向いたらまた調査します。

前提

Node.jsのバージョンによっても動かなくなる可能性があるため、簡単にNode.jsのバージョンが切り替えられるよう、Node.jsのバージョン管理システムnodebrewなどを利用してNode.jsを入れることを推奨します。nodebrew、Node.jsのインストールは割愛します。

筆者は、Node.js v8.16.0にて動作確認できました。

ドローンは、以下のFPVなしのParront manboです。

minidrone for Node.jsのインストール

以下のコマンドでライブラリーをインストール。

npm install minidrone

ついでに、サンプルで temporal を利用しているのでそちらもnpmインストール。


npm install temporal

サンプル・コードで飛ばす

以下のコードをfirstFlight.jsとして作成。

const minidrone = require('minidrone');
const temporal = require('temporal');
const drone = new minidrone.Drone();

drone.connect(function() {
  drone.setup(function() {
    drone.flatTrim();
    drone.startPing();
    drone.flatTrim();
    console.log('Connected to drone', drone.name);

    temporal.queue([
      {
        delay: 2000,
        task: function() {
          drone.takeOff()
          drone.flatTrim()
        },
      },
      {
        delay: 2000,
        task: function() {
          drone.forward({ steps: 30 }, function(){console.log('forward 30', drone.name);})
          drone.flatTrim();
        },
      },
      {
        delay: 2000,
        task: function() {
          drone.backward({ steps: 30 }, function(){console.log('backward 30', drone.name);})
        },
      },
      {
        delay: 2000,
        task: function() {
          drone.land()
        },
      },
      {
        delay: 2000,
        task: function() {
          temporal.clear()
          process.exit(0)
        },
      },
    ]);
  })
});

forward,backwardという関数は、2つめの引数のcallback関数を省略するとエラーになりました。

以下のコマンドで飛ばす。

node firstFlight.js

離陸、前進、後退、着陸したら成功です。お疲れ様でした。

もっといろいろな飛行をさせたい

公式のAPIを見てみましょう。https://github.com/jongear/minidrone

参考

他に試したmambo制御ライブラリーたち。

ライブラリー名 URL 2019/7テスト結果
Mini Drone for Node.js https://github.com/jongear/minidrone 本記事参照
Rolling Spider for Node.js https://github.com/voodootikigod/node-rolling-spider インストール(ビルド)エラー。
Minidrone-js https://github.com/Mechazawa/minidrone-js 応答しない。Bluetooth接続できない?
pdrone https://github.com/algolia/pdrone 応答しない。Bluetooth接続できない?
1
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
1
1