Drones yog amazing. Kuv yeej txaus siab ua si nrog kuv quad, thaij duab thiab yeeb yaj kiab, lossis tsuas yog muaj kev lom zem. Tab sis cov tsheb tsis muaj neeg tsav dav hlau (UAVs) yog siv rau ntau tshaj li kev lom zem xwb. Lawv ua hauj lwm hauv xinesmas, kawm glaciers, thiab siv los ntawm cov tub rog thiab cov neeg sawv cev ntawm kev ua liaj ua teb.
Hauv qhov kev qhia no peb yuav saib txog kev tsim cov kev pab cuam uas yuav tso cai rau koj los tswj lub drone. siv cov lus txib. Yog lawm, tus copter yuav ua qhov koj hais kom nws ua. Thaum kawg ntawm tsab xov xwm muaj qhov kev npaj ua tiav thiab yees duab ntawm UAV tswj.
Hlau
Peb xav tau cov hauv qab no:
Parrot ARDrone 2.0;
Ethernet cable;
zoo microphone.
Kev txhim kho thiab kev tswj hwm yuav ua tiav ntawm chaw ua haujlwm nrog Windows / Mac / Ubuntu. Tus kheej, kuv tau ua haujlwm nrog Mac thiab Ubuntu 18.04.
Software
Download tau qhov tseeb version ntawm Node.js los ntawm official site.
Cia peb sim nkag siab tias Parrot ARDrone ua haujlwm li cas. Lub copter no muaj plaub lub cev muaj zog.
Cov motors tawm tsam ua haujlwm tib yam. Ib khub tig clockwise, lwm counterclockwise. Lub drone txav los ntawm kev hloov lub kaum sab xis ntawm inclination txheeb ze rau saum npoo ntawm lub ntiaj teb, hloov qhov ceev ntawm kev sib hloov ntawm lub motors thiab ob peb lwm yam maneuverable txav.
Raws li peb tuaj yeem pom hauv daim duab saum toj no, kev hloov pauv ntau yam ua rau muaj kev hloov pauv ntawm kev txav ntawm lub copter. Piv txwv li, txo qis los yog nce kev sib hloov ceev ntawm sab laug thiab txoj cai rotors tsim ib yob. Qhov no tso cai rau lub drone ya mus rau pem hauv ntej lossis rov qab.
Los ntawm kev hloov qhov ceev thiab kev taw qhia ntawm cov motors, peb teem lub kaum sab xis uas tso cai rau lub copter txav mus rau lwm cov lus qhia. Qhov tseeb, rau qhov project tam sim no tsis tas yuav kawm txog aerodynamics, koj tsuas yog yuav tsum nkag siab cov ntsiab lus tseem ceeb.
Yuav ua li cas Parrot ARDrone ua haujlwm
Lub drone yog Wi-Fi hotspot. Yuav kom tau txais thiab xa cov lus txib mus rau lub copter, koj yuav tsum txuas mus rau qhov no. Muaj ntau ntau yam kev siv uas tso cai rau koj los tswj quadcopters. Txhua yam zoo li no:
Thaum lub drone txuas nrog, qhib lub davhlau ya nyob twg thiab telnet 192.168.1.1 - qhov no yog tus IP copter. Rau Linux koj tuaj yeem siv Linux Busybox.
Application architecture
Peb cov cai yuav muab faib ua cov nram qab no modules:
tus neeg siv interface nrog kev hais lus API rau lub suab tshawb pom;
lim cov lus txib thiab sib piv nrog tus qauv;
xa cov lus txib mus rau lub drone;
live video tshaj tawm.
API ua haujlwm tsuav yog muaj kev sib txuas hauv Is Taws Nem. Kom paub meej qhov no, peb ntxiv Ethernet kev twb kev txuas.
Nws yog lub sijhawm los tsim daim ntawv thov!
Code
Ua ntej, cia peb tsim ib daim nplaub tshev tshiab thiab hloov mus rau nws siv lub davhlau ya nyob twg.
Tom qab ntawd peb tsim qhov project Node siv cov lus txib hauv qab no.
Ua ntej, peb nruab qhov yuav tsum tau dependencies.
npm nruabβ
Peb yuav txhawb cov lus txib hauv qab no:
tshem tawm;
tsaws;
nce - lub drone nce ib nrab ib 'meter' thiab hovers;
down - ntog ib nrab ib 'meter' thiab khov;
mus rau sab laug - mus ib nrab ib 'meter' mus rau sab laug;
mus rau sab xis - mus ib nrab ib 'meter' mus rau sab xis;
Ntawm no yog cov cai uas tso cai rau koj lees txais cov lus txib, lim lawv thiab tswj lub 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);
Thiab ntawm no yog HTML thiab JavaScript code uas mloog cov neeg siv thiab xa cov lus txib mus rau Node server.
<!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>
Thiab kuj JavaScript code ua hauj lwm nrog lub suab commands, xa lawv mus rau lub Node server.
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'
});
};
Tua tawm daim ntawv thov
Qhov kev pab cuam tuaj yeem raug tso tawm raws li hauv qab no (nws yog ib qho tseem ceeb kom paub tseeb tias lub copter txuas nrog Wi-Fi thiab Ethernet cable txuas nrog lub computer).
Sau code thiab saib lub tshuab pib ua raws yuav ua rau koj txaus siab! Tam sim no peb tau xav txog yuav ua li cas qhia lub drone kom mloog cov lus txib. Qhov tseeb, muaj ntau qhov ua tau zoo: tus neeg siv lub ntsej muag lees paub, kev siv dav dav dav dav, paub piav tes piav taw thiab ntau ntxiv.
Koj tuaj yeem hais dab tsi los txhim kho qhov program?