LoginSignup
2
0

More than 3 years have passed since last update.

openFrameworksからTelloドローンを操縦する

Posted at

はじめに

以前からProcessingやmicrobitなどからTelloドローンを操作する実験をやってきました.
今回はopenFrameworksからTelloを操縦したいと思います.

アドオンを作ってみた(ofxTello)

Processingの時と同様にUDP通信でコマンドを送って操縦するのですが,毎回コマンドを全て実装するのがめんどくさかったので,コマンドを簡単に実装できるようにaddonを作りました.
addonを作るのが初めてだったのであまり良い設計とは言えませんがとりあえず簡単に使えるようにはなっています.

ofxTello

ofxTello使い方

まずはofxTelloを自身のoF環境のaddonsにクローンしてきます.
次にProjectGeneratorでプロジェクトを作成する際に,クローンしてきたofxTelloとofxNetworkをアドオンに追加します.
スクリーンショット 2020-08-15 17.04.26.png

コード

プログラムを実行する前に,TelloのWiFiに接続しておいてください.

ofApp.hpp
#pragma once
#include "ofMain.h"
#include "ofxTello.h"

class ofApp : public ofBaseApp{
    public:
        void setup();
        void update();
        void draw();
        void exit();
        void keyPressed(int key);

    ofxTello tello;
    int distance, angle, speed;
};

ofApp.cpp
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
    distance = 50;
    angle = 45;
    speed = 50;
    tello.connect();
}
//--------------------------------------------------------------
void ofApp::update(){
    tello.receiveUpdate();
    if(tello.getReceiveMessage().length() > 0){
        cout << tello.getReceiveMessage() << endl;
    }
}
//--------------------------------------------------------------
void ofApp::draw(){
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    if(key == 't'){
        tello.takeoff();
    } else if(key == 'l'){
        tello.land();
    } else if(key == 'w'){
        tello.foward(distance);
    } else if(key == 's'){
        tello.back(distance);
    } else if(key == 'a'){
        tello.left(distance);
    } else if(key == 'd'){
        tello.right(distance);
    } else if(key == OF_KEY_UP){
        tello.up(distance);
    } else if(key == OF_KEY_DOWN){
        tello.down(distance);
    } else if(key == OF_KEY_RIGHT){
        tello.cw(angle);
    } else if(key == OF_KEY_LEFT){
        tello.ccw(angle);
    }
}
//--------------------------------------------------------------
void ofApp::exit(){
    tello.close();
}

コマンド送信時にTelloからの返信をtello.receiveUpdate()で常に受け取る感じです.
ストリーミング機能はopencvを使った方法で実装出来そうですが,今のところこのアドオンには実装していません.

使いづらい点,わかりづらい点などありましたら,コメントでよろしくお願いします.

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