Commit e8477e03 authored by TJ Horner's avatar TJ Horner

a fix

parent 27b42d7e
......@@ -23,7 +23,7 @@ class Drone {
enable() {
this.enabled = true
this.sendInterval = setInterval(() => { this._sendMessage() }, 100)
this.sendInterval = setInterval(() => { this._sendMessage() }, 50)
}
disable() {
......@@ -35,16 +35,21 @@ class Drone {
_buildMessage() {
var message = [ 0x66 ]
message.push(this.leftRight)
message.push(this.throttle)
message.push(this.forwardBackward)
message.push(this.turn)
message.push(this.currentCommand)
if(this.currentCommand === 0)
message.push(this.leftRight ^ this.throttle ^ this.forwardBackward ^ this.turn)
else
if(this.currentCommand === 0) {
message.push(this.leftRight)
message.push(this.forwardBackward)
message.push(this.throttle)
message.push(this.turn)
message.push(0)
message.push(this.leftRight ^ this.forwardBackward ^ this.throttle ^ this.turn)
} else {
message.push(0x80)
message.push(0x80)
message.push(0x80)
message.push(0x80)
message.push(this.currentCommand)
message.push(this.currentCommand)
}
message.push(0x99)
......@@ -52,6 +57,7 @@ class Drone {
}
_sendMessage() {
console.log(this._buildMessage())
this.socket.send(this._buildMessage(), 50000, "192.168.0.1")
}
......@@ -59,7 +65,7 @@ class Drone {
// Send the command for 1 second-ish
if(this.currentCommand === 0) {
this.currentCommand = cmd
setTimeout(() => { this.currentCommand = 0 }, 1000)
setTimeout(() => { this.currentCommand = 0 }, 500)
}
}
......
{
"name": "dronelib",
"version": "1.0.0",
"version": "1.0.1",
"description": "Control your Chinese drone from Node.js",
"main": "index.js",
"scripts": {
......
......@@ -3,4 +3,14 @@ const Drone = require('./lib/Drone')
const drone = new Drone()
drone.enable()
\ No newline at end of file
drone.enable()
setTimeout(() => {
drone.takeOff()
drone.forwardBackward = 254
}, 2000)
setTimeout(() => {
drone.forwardBackward = 128
drone.land()
}, 4000)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment