Quadcopter logo

Drone School

Introduction to Drone Programming: Setting-Up Node.js


Introduction

The programming environment used for this project is Node.js. Scripts are written in JavaScript which are then passed to Node.js for execution. This was selected due to the availability of a simple SDK for Node.js, and the simplicity of the programming language. This guide assumes that teachers and students are already familiar with JavaScript programming at a basic level — such as control structures (loops, if statements), data types (strings, integers, booleans, arrays) along with using and implementing functions.

A great resource for those unfamiliar with JavaScript is the Head First JavaScript Programming book. This is the textbook used in our Year 9 IT course, allowing our students to learn JavaScript before embarking on the drone programming unit of work. The first four chapters of the book cover most of the required knowledge for drone programming.

Installing Node.js

Node.js is a cross-platform environment and works on a wide variety of operating systems, including OS X, Windows, and Linux. These instructions will focus on installation for a Mac running OS X, although they are equally applicable (with a few minor changes here and there) to other platforms too.

To start, visit https://nodejs.org and download Node.js — there should be a large button on the website to download the required version for your operating system. Once downloaded, double-click and run the installer to install Node.js on the computer.

Testing Node.js

With Node.js successfully installed we should run a test to ensure it's working correctly. Open a Terminal window by going to Spotlight (the magnifying glass next to the clock, in the top right-hand corner of the screen) and type "Terminal" and open the Terminal application.

At the command line, type node which will open an interactive Node.js session. Here you can type JavaScript commands and they will be immediately executed, similar to the JavaScript Console in Chrome and other browsers. In the session, type:

console.log("Testing 123");

You should see the text printed back out, as shown in the screen shot below:

[NODE SCREEN SHOT HERE]

Assuming all worked you can exit from the Node.js session by pressing CTRL + C twice.

Installing the node-ar-drone package

Once Node.js has been installed you need to use the npm (Node Package Manager) tool to install the node-ar-drone package, which provides the API and networking protocols for the computer to connect and send commands to the AR.Drone.

Create a new folder on your computer where you will keep all your drone scripts. In this example, we will assume this folder is on your desktop and called ~/Desktop/ar-drone-scripts.

Switch to the folder and then get the latest version of the package from the GitHub repo, by typing the following command:

npm install git://github.com/felixge/node-ar-drone.git

Note, in our experience npm does not work through many school content filters, so you may need to seek assistance from your IT department or ask the students to download this package from home. As an alternative, once it has been downloaded to one computer you can simply copy the folder containing the package to other computers.