Re hlophisa taolo ea lentsoe ea copter re sebelisa Node.js le ARDrone

Re hlophisa taolo ea lentsoe ea copter re sebelisa Node.js le ARDrone

Thutong ena re tla sheba ho theha lenaneo bakeng sa drone e nang le taolo ea lentsoe e sebelisa Node.js le Web speech API. Copter - Parrot ARDrone 2.0.

Re hopotsa: bakeng sa babali bohle ba "Habr" - theolelo ea li-ruble tse 10 ha u ngolisa thupelong efe kapa efe ea Skillbox u sebelisa khoutu ea papatso ea "Habr".

Skillbox e khothaletsa: Tsela e sebetsang "Mobile Developer PRO".

Selelekela

Li-drones lia hlolla. Ke thabela ho bapala ka quad ea ka, ho nka linepe le livideo, kapa ho ithabisa feela. Empa likoloi tsa sefofane tse sa sebetsoeng (UAVs) li sebelisetsoa ho fetang feela boithabiso. Ba sebetsa libaesekopong, ho ithuta ka leqhoa, 'me ba sebelisoa ke sesole le baemeli ba lefapha la temo.

Thutong ena re tla sheba ho theha lenaneo le tla u lumella ho laola drone. ka ho sebedisa ditaelo tsa lentswe. Ee, mokopi o tla etsa seo o se laelang hore e se etse. Qetellong ea sengoloa ho na le lenaneo le itokiselitseng le video ea taolo ea UAV.

Tšepe

Re hloka tse latelang:

  • Parrot ARDrone 2.0;
  • Ethernet cable;
  • maekerofounu e ntle.

Nts'etsopele le tsamaiso li tla etsoa litsing tsa mosebetsi tse nang le Windows/Mac/Ubuntu. Ka bonna, ke sebelitse le Mac le Ubuntu 18.04.

Software

Khoasolla mofuta oa morao-rao oa Node.js ho tsoa ho saeteng ya semmuso.

E boetse e hlokahala mofuta oa morao-rao oa Google Chrome.

Ho utloisisa copter

Ha re leke ho utloisisa hore na Parrot ARDrone e sebetsa joang. Copter ena e na le li-motor tse 'ne.

Re hlophisa taolo ea lentsoe ea copter re sebelisa Node.js le ARDrone

Li-motor tse hanyetsanang li sebetsa ka tsela e le 'ngoe. Para e 'ngoe e bilika ho ea ka nako ea oache, e 'ngoe e bilika ho ea ka nako ea oache. Drone e tsamaea ka ho fetola angle ea tšekamelo e amanang le holim'a lefatše, e fetola lebelo la ho potoloha ha li-motor le metsamao e meng e mengata e ka tsamaisoang.

Re hlophisa taolo ea lentsoe ea copter re sebelisa Node.js le ARDrone

Joalokaha re ka bona setšoantšong se ka holimo, ho fetola mekhahlelo e sa tšoaneng ho lebisa phetohong ea ho tsamaea ha copter. Ka mohlala, ho fokotsa kapa ho eketsa lebelo la ho potoloha ha li-rotor tse letšehali le tse nepahetseng ho etsa moqolo. Sena se lumella drone ho fofela pele kapa morao.

Ka ho fetola lebelo le tsela ea likoloi, re beha li-angles tse sekame tse lumellang copter hore e tsamaee ka litsela tse ling. Ha e le hantle, bakeng sa morero oa hona joale ha ho hlokahale ho ithuta aerodynamics, o hloka feela ho utloisisa melao-motheo ea motheo.

Kamoo Parrot ARDrone e sebetsang kateng

Drone ke sebaka sa marang-rang sa Wi-Fi. E le hore u fumane le ho romela litaelo ho copter, u lokela ho hokahanya ntlha ena. Ho na le lisebelisoa tse ngata tse fapaneng tse u lumellang ho laola li-quadcopter. Tsohle li shebahala tjena:

Re hlophisa taolo ea lentsoe ea copter re sebelisa Node.js le ARDrone

Hang ha drone e hokahane, bula terminal le telnet 192.168.1.1 - ena ke IP ea copter. Bakeng sa Linux u ka e sebelisa Linux Busybox.

Mehaho ea kopo

Khoutu ea rona e tla aroloa ka li-module tse latelang:

  • sehokelo sa mosebelisi se nang le puo ea API bakeng sa ho lemoha lentsoe;
  • ho sefa litaelo le ho bapisa le maemo;
  • ho romela litaelo ho drone;
  • khaso ea video e phelang.

API e sebetsa ha feela ho na le khokahano ea Marang-rang. Ho netefatsa sena, re kenya khokahano ea Ethernet.

Ke nako ea ho etsa kopo!

Khoutu

Taba ea pele, ha re theheng foldara e ncha 'me re e fetohele ho eona re sebelisa terminal.

Ebe re theha morero oa Node re sebelisa litaelo tse ka tlase.

Ntlha ea pele, re kenya lisebelisoa tse hlokahalang.

npm kenya 

Re tla tšehetsa litaelo tse latelang:

  • e ea tloha;
  • ho lulisa;
  • holimo - drone e phahama halofo ea mitha le hovers;
  • tlase - e oela halofo ea mithara ebe e hoama;
  • ka ho le letšehali - ho ea halofo ea mitha ka ho le letšehali;
  • ka ho le letona - ho ea halofo ea mitha ho ea ka ho le letona;
  • ho potoloha - ho potoloha ho ea ka nako ea 90 likhato;
  • ho ea pele - ho ea pele halofo ea mithara;
  • morao - khutlela halofo ea mithara;
  • Ema.

Mona ke khoutu e u lumellang ho amohela litaelo, ho li sefa le ho laola drone.

const express = require('express');
const bodyparser = require('body-parser');
var arDrone = require('ar-drone');
const router = express.Router();
const app = express();
const commands = ['takeoff', 'land','up','down','goleft','goright','turn','goforward','gobackward','stop'];
 
var drone  = arDrone.createClient();
// disable emergency
drone.disableEmergency();
// express
app.use(bodyparser.json());
app.use(express.static(__dirname + '/public'));
 
router.get('/',(req,res) => {
    res.sendFile('index.html');
});
 
router.post('/command',(req,res) => {
    console.log('command recieved ', req.body);
    console.log('existing commands', commands);
    let command = req.body.command.replace(/ /g,'');
    if(commands.indexOf(command) !== -1) {
        switch(command.toUpperCase()) {
            case "TAKEOFF":
                console.log('taking off the drone');
                drone.takeoff();
            break;
            case "LAND":
                console.log('landing the drone');
                drone.land();
            break;
            case "UP":
                console.log('taking the drone up half meter');
                drone.up(0.2);
                setTimeout(() => {
                    drone.stop();
                    clearTimeout();
                },2000);
            break;
            case "DOWN":
                console.log('taking the drone down half meter');
                drone.down(0.2);
                setTimeout(() => {
                    drone.stop();
                    clearTimeout();
                },2000);
            break;
            case "GOLEFT":
                console.log('taking the drone left 1 meter');
                drone.left(0.1);
                setTimeout(() => {
                    drone.stop();
                    clearTimeout();
                },1000);
            break;
            case "GORIGHT":
                console.log('taking the drone right 1 meter');
                drone.right(0.1);
                setTimeout(() => {
                    drone.stop();
                    clearTimeout();
                },1000);
            break;
            case "TURN":
                console.log('turning the drone');
                drone.clockwise(0.4);
                setTimeout(() => {
                    drone.stop();
                    clearTimeout();
                },2000);
            break;
            case "GOFORWARD":
                console.log('moving the drone forward by 1 meter');
                drone.front(0.1);
                setTimeout(() => {
                    drone.stop();
                    clearTimeout();
                },2000);
            break;
            case "GOBACKWARD":
                console.log('moving the drone backward 1 meter');
                drone.back(0.1);
                setTimeout(() => {
                    drone.stop();
                    clearTimeout();
                },2000);
            break;
            case "STOP":
                drone.stop();
            break;
            default:
            break;    
        }
    }
    res.send('OK');
});
 
app.use('/',router);
 
app.listen(process.env.port || 3000);

Hona ke khoutu ea HTML le JavaScript e mamelang mosebelisi mme e romela taelo ho seva sa Node.

<!DOCTYPE html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Voice Controlled Notes App</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/shoelace-css/1.0.0-beta16/shoelace.css">
        <link rel="stylesheet" href="styles.css">
 
    </head>
    <body>
        <div class="container">
 
            <h1>Voice Controlled Drone</h1>
            <p class="page-description">A tiny app that allows you to control AR drone using voice</p>
 
            <h3 class="no-browser-support">Sorry, Your Browser Doesn't Support the Web Speech API. Try Opening This Demo In Google Chrome.</h3>
 
            <div class="app">
                <h3>Give the command</h3>
                <div class="input-single">
                    <textarea id="note-textarea" placeholder="Create a new note by typing or using voice recognition." rows="6"></textarea>
                </div>    
                <button id="start-record-btn" title="Start Recording">Start Recognition</button>
                <button id="pause-record-btn" title="Pause Recording">Pause Recognition</button>
                <p id="recording-instructions">Press the <strong>Start Recognition</strong> button and allow access.</p>
 
            </div>
 
        </div>
 
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script src="script.js"></script>
 
    </body>
</html>

Hape le khoutu ea JavaScript ho sebetsa ka litaelo tsa lentsoe, ho li romella ho seva sa Node.

try {
 var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
 var recognition = new SpeechRecognition();
 }
 catch(e) {
 console.error(e);
 $('.no-browser-support').show();
 $('.app').hide();
 }
// other code, please refer GitHub source
recognition.onresult = function(event) {
// event is a SpeechRecognitionEvent object.
// It holds all the lines we have captured so far.
 // We only need the current one.
 var current = event.resultIndex;
// Get a transcript of what was said.
var transcript = event.results[current][0].transcript;
// send it to the backend
$.ajax({
 type: 'POST',
 url: '/command/',
 data: JSON.stringify({command: transcript}),
 success: function(data) { console.log(data) },
 contentType: "application/json",
 dataType: 'json'
 });
};

Ho qala ts'ebeliso

Lenaneo le ka qalisoa ka tsela e latelang (ho bohlokoa ho etsa bonnete ba hore copter e hokahane le Wi-Fi le thapo ea Ethernet e hokahane le komporo).

Bula localhost:3000 ho sebatli ebe o tobetsa Qala Recognition.

Re hlophisa taolo ea lentsoe ea copter re sebelisa Node.js le ARDrone

Re leka ho laola drone mme re thabile.

Ho phatlalatsa video ho tsoa ho drone

Morerong, theha faele e ncha 'me u kopitse khoutu ena moo:

const http = require("http");
const drone = require("dronestream");
 
const server = http.createServer(function(req, res) {
 
require("fs").createReadStream(__dirname + "/public/video.html").pipe(res);
 });
 
drone.listen(server);
 
server.listen(4000);

Hona ke khoutu ea HTML, re e beha ka har'a foldara ea sechaba.

<!doctype html>
 <html>
 <head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8">
 <title>Stream as module</title>
 <script src="/dronestream/nodecopter-client.js" type="text/javascript" charset="utf-8"></script>
 </head>
 <body>
 <h1 id="heading">Drone video stream</h1>
 <div id="droneStream" style="width: 640px; height: 360px"> </div>
 
<script type="text/javascript" charset="utf-8">
 
new NodecopterStream(document.getElementById("droneStream"));
 
</script>
 
</body>
</html>

Qala le ho hokela ho localhost:8080 ho sheba video ho tsoa kh'amera e ka pele.

Re hlophisa taolo ea lentsoe ea copter re sebelisa Node.js le ARDrone

Litlhahiso Tse Thusang

  • Fofisetsa sefofane sena sa sefofane ka tlung.
  • Kamehla beha sekoaelo sa tšireletso holim'a drone ea hau pele e tloha.
  • Sheba hore na betri e tjhajilwe.
  • Haeba drone e sebetsa ka mokhoa o makatsang, e tšoare fatše 'me u e phenye. Ketso ena e tla kenya copter ka mokhoa oa tšohanyetso 'me li-rotor li tla emisa hang-hang.

Ho lokile khoutu le demo

PHELELA MOTEMO

DOWNLOAD

Ho etsahetse!

Ho ngola khoutu ebe u shebella mochini o qala ho mamela ho tla u thabisa! Joale re bone mokhoa oa ho ruta drone ho mamela litaelo tsa lentsoe. Ha e le hantle, ho na le menyetla e mengata: ho lemoha sefahleho sa basebelisi, lifofane tse ikemetseng, ho lemoha boitšisinyo le tse ling tse ngata.

U ka etsa tlhahiso efe ho ntlafatsa lenaneo?

Skillbox e khothaletsa:

Source: www.habr.com

Eketsa ka tlhaloso