{"id":13749294,"url":"https://github.com/felixge/node-ar-drone","last_synced_at":"2025-05-15T00:11:09.698Z","repository":{"id":4035011,"uuid":"5135922","full_name":"felixge/node-ar-drone","owner":"felixge","description":"A node.js client for controlling Parrot AR Drone 2.0 quad-copters.","archived":false,"fork":false,"pushed_at":"2019-11-02T16:04:50.000Z","size":551,"stargazers_count":1755,"open_issues_count":40,"forks_count":428,"subscribers_count":149,"default_branch":"master","last_synced_at":"2024-04-14T06:43:29.494Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://nodecopter.com/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/felixge.png","metadata":{"files":{"readme":"README.md","changelog":"Changes.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-07-21T18:50:20.000Z","updated_at":"2024-04-09T17:30:54.000Z","dependencies_parsed_at":"2022-08-02T23:46:17.855Z","dependency_job_id":null,"html_url":"https://github.com/felixge/node-ar-drone","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixge%2Fnode-ar-drone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixge%2Fnode-ar-drone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixge%2Fnode-ar-drone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felixge%2Fnode-ar-drone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/felixge","download_url":"https://codeload.github.com/felixge/node-ar-drone/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247517904,"owners_count":20951718,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T07:00:58.689Z","updated_at":"2025-04-06T17:07:03.391Z","avatar_url":"https://github.com/felixge.png","language":"JavaScript","funding_links":[],"categories":["JavaScript",":wrench: Tools","Projects"],"sub_categories":["Scientific Research"],"readme":"# ar-drone\n\n[![Build Status](https://secure.travis-ci.org/felixge/node-ar-drone.png)](http://travis-ci.org/felixge/node-ar-drone)\n\nAn implementation of the networking protocols used by the\n[Parrot AR Drone 2.0](http://ardrone2.parrot.com/). It appears that 1.0 drones are also [compatible](https://github.com/felixge/node-ar-drone/issues/11#issuecomment-9402270).\n\nInstall via Github to get the *latest* version:\n\n```bash\nnpm install git://github.com/felixge/node-ar-drone.git\n```\n\nOr, if you're fine with missing some cutting edge stuff, go for npm:\n\n```bash\nnpm install ar-drone\n```\n\n## Introduction\n\nThe AR Drone is an affordable, yet surprisingly capable quadcopter. The drone\nitself runs a proprietary firmware that can be controlled via WiFi using the official\nFreeFlight mobile app\n(available for [iOS](http://itunes.apple.com/us/app/freeflight/id373065271?mt=8) and [Android](https://play.google.com/store/apps/details?id=com.parrot.freeflight\u0026hl=en)).\n\nUnlike the firmware, the client protocol is open, and Parrot publishes an [SDK](https://projects.ardrone.org/projects/show/ardrone-api)\n(signup required to download) including a good amount of documentation and C\ncode. Their target audience seems to be mobile developers who can use this\nSDK to create games and other apps for people to have more fun with their drones.\n\nHowever, the protocol can also be used to receive video and sensor data, enabling\ndevelopers to write autonomous programs for the upcoming robot revolution.\n\n## Status\n\nThis module is still under [heavy development](CONTRIBUTING.md), so please don't be surprised if\nyou find some functionality missing or undocumented.\n\nHowever, the documented parts are tested and should work well for most parts.\n\n## Client\n\nThis module exposes a high level Client API that tries to support all drone\nfeatures, while making them easy to use.\n\nThe best way to get started is to create a `repl.js` file like this:\n\n```js\nvar arDrone = require('ar-drone');\nvar client  = arDrone.createClient();\nclient.createRepl();\n```\n\nUsing this REPL, you should be able to have some fun:\n\n```js\n$ node repl.js\n// Make the drone takeoff\ndrone\u003e takeoff()\ntrue\n// Wait for the drone to takeoff\ndrone\u003e clockwise(0.5)\n0.5\n// Let the drone spin for a while\ndrone\u003e land()\ntrue\n// Wait for the drone to land\n```\n\nNow you could write an autonomous program that does the same:\n\n```js\nvar arDrone = require('ar-drone');\nvar client  = arDrone.createClient();\n\nclient.takeoff();\n\nclient\n  .after(5000, function() {\n    this.clockwise(0.5);\n  })\n  .after(3000, function() {\n    this.stop();\n    this.land();\n  });\n```\n\nOk, but what if you want to make your drone to interact with something? Well,\nyou could start by looking at the sensor data:\n\n```js\nclient.on('navdata', console.log);\n```\n\nNot all of this is handled by the Client library yet, but you should at the\nvery least be able to receive `droneState` and `demo` data.\n\nA good initial challenge might be to try flying to a certain altitude based\non the `navdata.demo.altitudeMeters` property.\n\nOnce you have managed this, you may want to try looking at the camera image. Here\nis a simple way to get this as PngBuffers (requires a recent ffmpeg version to\nbe found in your `$PATH`):\n\n```js\nvar pngStream = client.getPngStream();\npngStream.on('data', console.log);\n```\n\nYour first challenge might be to expose these png images as a node http web\nserver. Once you have done that, you should try feeding them into the\n[opencv](https://npmjs.org/package/opencv) module.\n\n### Client API\n\n#### arDrone.createClient([options])\n\nReturns a new `Client` object. `options` include:\n\n* `ip`: The IP of the drone. Defaults to `'192.168.1.1'`.\n* `frameRate`: The frame rate of the PngEncoder. Defaults to `5`.\n* `imageSize`: The image size produced by PngEncoder. Defaults to `null`.\n\n#### client.createREPL()\n\nLaunches an interactive interface with all client methods available in the\nactive scope. Additionally `client` resolves to the `client` instance itself.\n\n#### client.getPngStream()\n\nReturns a `PngEncoder` object that emits individual png image buffers as `'data'`\nevents. Multiple calls to this method returns the same object. Connection lifecycle\n(e.g. reconnect on error) is managed by the client.\n\n#### client.getVideoStream()\n\nReturns a `TcpVideoStream` object that emits raw tcp packets as `'data'`\nevents. Multiple calls to this method returns the same object. Connection lifecycle\n(e.g. reconnect on error) is managed by the client.\n\n#### client.takeoff(callback)\n\nSets the internal `fly` state to `true`, `callback` is invoked after the drone\nreports that it is hovering.\n\n#### client.land(callback)\n\nSets the internal `fly` state to `false`, `callback` is invoked after the drone\nreports it has landed.\n\n#### client.up(speed) / client.down(speed)\n\nMakes the drone gain or reduce altitude. `speed` can be a value from `0` to `1`.\n\n#### client.clockwise(speed) / client.counterClockwise(speed)\n\nCauses the drone to spin. `speed` can be a value from `0` to `1`.\n\n#### client.front(speed) / client.back(speed)\n\nControls the pitch, which a horizontal movement using the camera\nas a reference point.  `speed` can be a value from `0` to `1`.\n\n#### client.left(speed) / client.right(speed)\n\nControls the roll, which is a horizontal movement using the camera\nas a reference point.  `speed` can be a value from `0` to `1`.\n\n#### client.stop()\n\nSets all drone movement commands to `0`, making it effectively hover in place.\n\n#### client.calibrate(device)\n\nAsks the drone to calibrate a device. Although the AR.Drone firmware\nonly supports one device that can be calibrated. This function also includes ftrim.\n\n**The Magnetometer**\n\nDevice: 0\n\nThe magnetometer can only be calibrated while the drone is flying, and\nthe calibration routine causes the drone to yaw in place a full 360\ndegrees.\n\n**FTRIM**\n\nDevice: 1\n\nFTRIM essentially resets the Yaw, Pitch, and Roll to 0. Be very cautious of using\nthis function and only calibrate while on flat surface. Never use while flying.\n\n#### client.config(key, value, callback)\n\nSends a config command to the drone. You will need to download the drone\n[SDK](https://projects.ardrone.org/projects/show/ardrone-api) to find a full list of commands in the `ARDrone_Developer_Guide.pdf`.\n\nFor example, this command can be used to instruct the drone to send all navdata.\n\n```js\nclient.config('general:navdata_demo', 'FALSE');\n```\n\n`callback` is invoked after the drone acknowledges the config request\nor if a timeout occurs.\n\nAlternatively, you can pass an options object containing the following:\n\n* `key`: The config key to set.\n* `value`: The config value to set.\n* `timeout`: The time, in milliseconds, to wait for an ACK from the drone.\n\nFor example:\n\n```\nvar callback = function(err) { if (err) console.log(err); };\nclient.config({ key: 'general:navdata_demo', value: 'FALSE', timeout: 1000 }, callback);\n```\n\n#### client.animate(animation, duration)\n\nPerforms a pre-programmed flight sequence for a given `duration` (in ms).\n`animation` can be one of the following:\n\n\n```js\n['phiM30Deg', 'phi30Deg', 'thetaM30Deg', 'theta30Deg', 'theta20degYaw200deg',\n'theta20degYawM200deg', 'turnaround', 'turnaroundGodown', 'yawShake',\n'yawDance', 'phiDance', 'thetaDance', 'vzDance', 'wave', 'phiThetaMixed',\n'doublePhiThetaMixed', 'flipAhead', 'flipBehind', 'flipLeft', 'flipRight']\n```\n\nExample:\n\n```js\nclient.animate('flipLeft', 1000);\n```\n\nPlease note that the drone will need a good amount of altitude and headroom\nto perform a flip. So be careful!\n\n#### client.animateLeds(animation, hz, duration)\n\nPerforms a pre-programmed led sequence at given `hz` frequency and `duration`\n(in sec!). `animation` can be one of the following:\n\n```js\n['blinkGreenRed', 'blinkGreen', 'blinkRed', 'blinkOrange', 'snakeGreenRed',\n'fire', 'standard', 'red', 'green', 'redSnake', 'blank', 'rightMissile',\n'leftMissile', 'doubleMissile', 'frontLeftGreenOthersRed',\n'frontRightGreenOthersRed', 'rearRightGreenOthersRed',\n'rearLeftGreenOthersRed', 'leftGreenRightRed', 'leftRedRightGreen',\n'blinkStandard']\n```\n\nExample:\n\n```js\nclient.animateLeds('blinkRed', 5, 2)\n```\n\n#### client.disableEmergency()\n\nCauses the emergency REF bit to be set to 1 until\n`navdata.droneState.emergencyLanding` is 0. This recovers a drone that has\nflipped over and is showing red lights to be flyable again and show green\nlights.  It is also done implicitly when creating a new high level client.\n\n#### Events\n\nA client will emit landed, hovering, flying, landing, batteryChange, and altitudeChange events as long as demo navdata is enabled.\n\nTo enable demo navdata use\n\n```js\nclient.config('general:navdata_demo', 'FALSE');\n```\n\nSee [documentation](docs/NavData.md) for ```navadata``` object\n\n## UdpControl\n\nThis is a low level API. If you prefer something simpler, check out the Client\ndocs.\n\nThe drone is controlled by sending UDP packets on port 5556. Because UDP\ndoes not guarantee message ordering or delivery, clients must repeatedly send\ntheir instructions and include an incrementing sequence number with each\ncommand.\n\nFor example, the command used for takeoff/landing (REF), with a sequence number\nof 1, and a parameter of 512 (takeoff) looks like this:\n\n```\nAT*REF=1,512\\r\n```\n\nTo ease the creation and sending of these packets, this module exposes an\n`UdpControl` class handling this task. For example, the following program will\ncause your drone to takeoff and hover in place.\n\n```js\nvar arDrone = require('ar-drone');\nvar control = arDrone.createUdpControl();\n\nsetInterval(function() {\n  // The emergency: true option recovers your drone from emergency mode that can\n  // be caused by flipping it upside down or the drone crashing into something.\n  // In a real program you probably only want to send emergency: true for one\n  // second in the beginning, otherwise your drone may attempt to takeoff again\n  // after a crash.\n  control.ref({fly: true, emergency: true});\n  // This command makes sure your drone hovers in place and does not drift.\n  control.pcmd();\n  // This causes the actual udp message to be send (multiple commands are\n  // combined into one message)\n  control.flush();\n}, 30);\n```\n\nNow that you are airborne, you can fly around by passing an argument to the\n`pcmd()` method:\n\n```js\ncontrol.pcmd({\n  front: 0.5, // fly forward with 50% speed\n  up: 0.3, // and also fly up with 30% speed\n});\n```\n\nThat's it! A full list of all `pcmd()` options can be found in the API docs\nbelow.\n\nWith what you have learned so far, you could create a simple program\nlike this:\n\n```js\nvar arDrone = require('ar-drone');\nvar control = arDrone.createUdpControl();\nvar start   = Date.now();\n\nvar ref  = {};\nvar pcmd = {};\n\nconsole.log('Recovering from emergency mode if there was one ...');\nref.emergency = true;\nsetTimeout(function() {\n  console.log('Takeoff ...');\n\n  ref.emergency = false;\n  ref.fly       = true;\n\n}, 1000);\n\nsetTimeout(function() {\n  console.log('Turning clockwise ...');\n\n  pcmd.clockwise = 0.5;\n}, 6000);\n\nsetTimeout(function() {\n  console.log('Landing ...');\n\n  ref.fly = false;\n  pcmd = {};\n}, 8000);\n\n\nsetInterval(function() {\n  control.ref(ref);\n  control.pcmd(pcmd);\n  control.flush();\n}, 30);\n```\n\n### UdpControl API\n\n#### arDrone.createUdpControl([options]) / new arDrone.UdpControl([options])\n\nCreates a new UdpControl instance where `options` can include:\n\n* `ip`: The drone IP address, defaults to `'192.168.1.1'`.\n* `port`: The port to use, defaults to `5556`.\n\n#### udpControl.raw(command, [arg1, arg2, ...])\n\nEnqueues a raw `AT*` command. This is useful if you want full control.\n\nFor example, a takeoff instructions be send like this:\n\n```js\nudpControl.raw('REF', (1 \u003c\u003c 9));\n```\n\n#### udpControl.ref([options])\n\nEnqueues a `AT*REF` command, options are:\n\n* `fly`: Set this to `true` for takeoff / staying in air, or `false` to initiate\n  landing / stay on the ground. Defaults to `false`.\n* `emergency`: Set this to `true` to set the emergency bit, or `false` to not\n  set it. Details on this can be found in the official SDK Guide. Defaults to\n  `false`.\n\n#### udpControl.pcmd([options])\n\nEnqueues a `AT*PCMD` (progressive) command, options are:\n\n* `front` or `back`: Fly towards or away from front camera direction.\n* `left` or/ `right`: Fly towards the left or right of the front camera.\n* `up` or `down`: Gain or reduce altitude.\n* `clockwise` or `counterClockwise`: Rotate around the center axis.\n\nThe values for each option are the speed to use for the operation and can range\nfrom 0 to 1. You can also use negative values like `{front: -0.5}`, which is\nthe same as `{back: 0.5}`.\n\n#### udpControl.flush()\n\nSends all enqueued commands as an UDP packet to the drone.\n\n## Video\n\n@TODO Document the low level video API.\n\n## Navdata\n\n@TODO Document the low level navdata API.\n\n## Environment variables\n\n* DEFAULT_DRONE_IP\n\n## Camera access\n\nYou can access the head camera and the bottom camera, you just have to change\nthe config:\n\n```javascript\n// access the head camera\nclient.config('video:video_channel', 0);\n\n// access the bottom camera\nclient.config('video:video_channel', 3);\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelixge%2Fnode-ar-drone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffelixge%2Fnode-ar-drone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelixge%2Fnode-ar-drone/lists"}