From 1243827ba4e65f3098782520f989f6c93291a6c6 Mon Sep 17 00:00:00 2001 From: Filippo Bergamasco Date: Mon, 18 Jan 2016 19:50:31 +0100 Subject: [PATCH 1/2] navigation data are now stored and updated in drone object gps/pitch/yaw/roll/altitude packets are parsed and stored in drone object upon received. Additionally, "navdata" event is emitted. --- lib/bebop.js | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/lib/bebop.js b/lib/bebop.js index 40e5946..84b9127 100644 --- a/lib/bebop.js +++ b/lib/bebop.js @@ -212,6 +212,74 @@ Bebop.prototype._packetReceiver = function(message) { this._writePacket(this._createARStreamACK(arstreamFrame)); } + if( networkFrame.id === constants.BD_NET_DC_NAVDATA_ID ) { + var commandProject = networkFrame.data.readUInt8(0), + commandClass = networkFrame.data.readUInt8(1), + commandId = networkFrame.data.readUInt16LE(2); + + // Attitude + if( commandProject==1 && commandClass == 4 && commandId == 6 ) { + + var _roll = networkFrame.data.readFloatLE(4), + _pitch = networkFrame.data.readFloatLE(8), + _yaw = networkFrame.data.readFloatLE(12); + + this.navData.attitude = { + roll: _roll, + pitch: _pitch, + yaw: _yaw + } + } + + // Speed + if( commandProject==1 && commandClass == 4 && commandId == 5 ) { + + var _vx = networkFrame.data.readFloatLE(4), + _vy = networkFrame.data.readFloatLE(8), + _vz = networkFrame.data.readFloatLE(12); + + this.navData.speed = { + vx: _vx, + vy: _vy, + vz: _vz + } + } + + // Altitude + if( commandProject==1 && commandClass == 4 && commandId == 8 ) { + + var _altitude = networkFrame.data.readDoubleLE(4); + this.navData.altitude = _altitude; + } + + // GPS + if( commandProject==1 && commandClass == 4 && commandId == 4 ) { + var _lat = networkFrame.data.readDoubleLE(4), + _lon = networkFrame.data.readDoubleLE(12), + _alt = networkFrame.data.readDoubleLE(20); + + this.navData.pos = { + lat: _lat, + lon: _lon, + alt: _alt + }; + } + + // Camera + if( commandProject==1 && commandClass == 25 && commandId == 0 ) { + var _tilt = networkFrame.data.readUInt8(4), + _pan = networkFrame.data.readUInt8(5); + + this.navData.cam = { + tilt: _tilt, + pan: _pan + }; + } + + + this.emit("navdata", this.navData ); + } + // // libARCommands/Sources/ARCOMMANDS_Decoder.c#ARCOMMANDS_Decoder_DecodeBuffer // From b73b4cf9bd12c39256a2022d9f730eeddc67a019 Mon Sep 17 00:00:00 2001 From: Filippo Bergamasco Date: Mon, 30 May 2016 10:16:28 +0200 Subject: [PATCH 2/2] Movement vector can now be directly updated --- bin/updateCommands.js | 0 lib/bebop.js | 13 +++++++++++++ 2 files changed, 13 insertions(+) mode change 100644 => 100755 bin/updateCommands.js diff --git a/bin/updateCommands.js b/bin/updateCommands.js old mode 100644 new mode 100755 diff --git a/lib/bebop.js b/lib/bebop.js index 58b0937..76a13ca 100644 --- a/lib/bebop.js +++ b/lib/bebop.js @@ -535,6 +535,19 @@ Bebop.prototype.counterClockwise = function(val) { return this; }; +Bebop.prototype.setPCMD = function ( lr_mov, fw_bw_mov, up_down_mov, yaw_rot ) { + this._pcmd.flag = 1; + this._pcmd.roll = Math.max( -100, Math.min(lr_mov, 100 ) ); + this._pcmd.pitch = Math.max( -100, Math.min(fw_bw_mov,100)); + this._pcmd.gaz = Math.max( -100, Math.min(up_down_mov,100)); + this._pcmd.yaw = Math.max( -100, Math.min(yaw_rot,100)); + return this; +} + +Bebop.prototype.getPCMD = function() { + return [ this._pcmd.roll || 0, this._pcmd.pitch || 0, this._pcmd.gaz || 0, this._pcmd.yaw || 0 ]; +} + Bebop.prototype.stop = Bebop.prototype.level = function() { this._pcmd = { flag: 0,