Socket
Socket
Sign inDemoInstall

aerogel

Package Overview
Dependencies
15
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.0.4

scripts/hover.js

171

lib/copter.js

@@ -13,2 +13,3 @@ var

var MIN_THRUST = 10001;
var ε = 0.01; // the slop to tolerate in goals vs current state

@@ -24,3 +25,4 @@ var Copter = module.exports = function Copter(driver)

this.currentSetpoint = {};
this.goal =
this.telemetry = {};
this.goal =
{

@@ -30,3 +32,6 @@ roll: 0,

yaw: 0,
thrust: 0
thrust: 0,
x: 0,
y: 0,
z: 0
};

@@ -48,7 +53,6 @@ this.nextSetpoint =

{
var self = this,
deferred = P.defer();
var self = this;
self.copterStates.connect();
self.driver.connect(uri)
return self.driver.connect(uri)
.then(function()

@@ -60,14 +64,3 @@ {

self.copterStates.ready();
self.emit('ready');
deferred.resolve('ready');
})
.fail(function(err)
{
console.log(err);
self.emit('error', err);
deferred.reject(err);
})
.done();
return deferred.promise;
});
};

@@ -81,4 +74,6 @@

console.log('takeoff()');
this.copterStates.takeoff();
this.pulseTimer = setInterval(this.pulse.bind(this), 100);
// this.pulseTimer = setInterval(this.pulse.bind(this), 100);

@@ -151,9 +146,11 @@ var maxThrust = 39601;

{
self.thrust -= thrustStep;
if (self.thrust <= MIN_THRUST)
self.thrust = MIN_THRUST;
var thrust = self.thrust - thrustStep;
if (thrust <= MIN_THRUST)
thrust = MIN_THRUST;
// console.log('landing; thrust:', self.thrust);
// console.log('landing; thrust:', thrust);
self.goal.thrust = thrust;
self.thrust = thrust;
if (self.thrust === MIN_THRUST)
if (thrust === MIN_THRUST)
{

@@ -172,3 +169,3 @@ self.copterStates.landed();

{
this.copterStates.settle();
this.copterStates.stabilize();
};

@@ -201,7 +198,12 @@

})
.state('flying',
.state('taking-off',
{
initial: false,
enter: this.enterFlying.bind(this),
enter: this.enterTakeoff.bind(this),
})
.state('hovering',
{
initial: false,
enter: this.enterHovering.bind(this),
})
.state('moving',

@@ -218,15 +220,15 @@ {

})
.event('connect', 'setup', 'connected')
.event('ready', 'connected', 'waiting')
.event('takeoff', 'waiting', 'flying')
.event('move', 'flying', 'moving')
.event('settle', 'moving', 'flying')
.event('land', 'flying', 'landing')
.event('landed', 'landing', 'waiting')
.event('connect', 'setup', 'connected')
.event('ready', 'connected', 'waiting')
.event('takeoff', 'waiting', 'taking-off')
.event('stabilize', 'taking-off', 'hovering')
.event('move', 'hovering', 'moving')
.event('settle', 'moving', 'hovering')
.event('land', 'hovering', 'landing')
.event('landed', 'landing', 'waiting')
;
this.copterStates.onChange = function(current, previous)
{
console.log('STATE CHANGE:', previous, '-->', current);
console.log('STATE:', previous, '-->', current);
};

@@ -245,8 +247,13 @@ };

Copter.prototype.enterFlying = function()
Copter.prototype.enterTakeoff = function()
{
console.log('enter flying');
this.pulseTimer = setInterval(this.pulse.bind(this), 100);
this.goal.z = 0.5;
};
Copter.prototype.enterHovering = function()
{
this.goal.z = 0;
};
Copter.prototype.enterMoving = function()

@@ -301,31 +308,48 @@ {

var EPSILON = 0.01;
function deltaToGoal(current, goal)
{
var diff = current - goal;
if (Math.abs(diff) > ε)
return diff;
return 0;
}
Copter.prototype.handleStabilizerTelemetry = function(data)
{
this.stabilizer = data;
var roll = 0,
pitch = 0,
yaw = 0,
thrust = this.goal.thrust;
this.telemetry.stabilizer = data;
var thrustDelta = deltaToGoal(data.thrust, this.goal.thrust);
var rollDelta = deltaToGoal(data.roll, this.goal.roll);
var pitchDelta = deltaToGoal(data.pitch, this.goal.pitch);
var yawDelta = deltaToGoal(data.yaw, this.goal.yaw);
switch (this.copterStates.currentState())
{
case 'flying':
/*
var diff = data.yaw - this.goal.yaw;
if (Math.abs(diff) > EPSILON)
yaw = diff;
else
yaw = 0;
case 'taking-off':
case 'moving':
case 'hovering':
// this.roll = this.roll + rollDelta;
// this.pitch = this.pitch + pitchDelta;
// this.yaw = this.goal.yaw + yawDelta;
// this.thrust = this.goal.thrust;
break;
diff = data.pitch - this.goal.pitch;
if (Math.abs(diff) > EPSILON)
pitch = diff;
else
pitch = 0;
default:
// console.log('stabilizer:', data);
break;
}
};
this.yaw = yaw;
this.pitch = pitch;
*/
Copter.prototype.handleMotorTelemetry = function(data)
{
// console.log('motor:', data);
this.telemetry.motor = data;
switch (this.copterStates.currentState())
{
case 'taking-off':
var thrustDelta = deltaToGoal(data.thrust, this.goal.thrust);
this.goal.thrust += thrustDelta;
this.thrust = this.goal.thrust;
// console.log('thrust delta:', thrustDelta);
break;

@@ -339,2 +363,15 @@

Copter.prototype.handleAccTelemetry = function(data)
{
// console.log('acc:', data);
this.telemetry.acc = data;
};
Copter.prototype.shutdown = function()
{
return this.driver.close();
};
// property boilerplate
Copter.prototype.setPitch = function(p)

@@ -371,19 +408,1 @@ {

Copter.prototype.handleMotorTelemetry = function(data)
{
// console.log('motor:', data);
};
Copter.prototype.handleAccTelemetry = function(data)
{
// console.log('acc:', data);
};
Copter.prototype.shutdown = function()
{
return this.driver.close();
};
// property boilerplate

@@ -95,3 +95,6 @@ // Crazy Real Time Protocol Driver

for (var i = 0; i < result.length; i++)
{
copters.push(util.format('radio://1/%d/%s', result[i], CrazyDriver.DATARATE[datarate]));
console.log(copters[i]);
}

@@ -110,3 +113,3 @@ return copters;

var pieces = parsed.pathname.split('/');
// prefered usb device is at parsed.hostname
// preferred usb device is at parsed.hostname

@@ -146,3 +149,3 @@ if (pieces.length === 3)

CrazyDriver.prototype.status = function()
CrazyDriver.prototype.version = function()
{

@@ -231,2 +234,3 @@ if (!this.radio)

// telemetry, which the Crazy protocol calls "logging"
var ttime;

@@ -236,2 +240,3 @@ CrazyDriver.prototype.startTelemetry = function()

console.log('starting telemetry');
ttime = Date.now();
var self = this;

@@ -257,2 +262,3 @@ this.telemetryDeferred = P.defer();

{
console.log('telemetry ready; elapsed=', (Date.now() - ttime));
if (!this.telemetryDeferred) return;

@@ -259,0 +265,0 @@ this.telemetryDeferred.resolve('OK');

@@ -24,7 +24,2 @@ // Crazyradio should offer a method to take data in, format it properly

// --------------------------------------------
// chainable write methods
// This is sugar so you never have to resize your buffer & to track how many
// bytes we need to write over the radio.
Crazypacket.readType = function(buffer, type, offset)

@@ -38,9 +33,9 @@ {

case 'uint16_t':
return buffer.readUInt16(offset);
return buffer.readUInt16LE(offset);
case 'uint32_t':
return buffer.readUInt32(offset);
return buffer.readUInt32LE(offset);
case 'uint64_t':
return buffer.readUInt64(offset);
return buffer.readUInt64LE(offset);

@@ -51,9 +46,9 @@ case 'int8_t':

case 'int16_t':
return buffer.readInt16(offset);
return buffer.readInt16LE(offset);
case 'int32_t':
return buffer.readInt32(offset);
return buffer.readInt32LE(offset);
case 'int64_t':
return buffer.readInt64(offset);
return buffer.readInt64LE(offset);

@@ -72,3 +67,2 @@ case 'float':

Crazypacket.prototype.writeType = function(type, value)

@@ -114,2 +108,7 @@ {

// --------------------------------------------
// chainable write methods
// This is sugar so you never have to resize your buffer & to track how many
// bytes we need to write over the radio.
Crazypacket.prototype.resizeBuffer = function()

@@ -116,0 +115,0 @@ {

@@ -63,2 +63,3 @@ var

this.pingTimer = null;
this.pingInterval = null;
};

@@ -123,3 +124,4 @@ util.inherits(Crazyradio, events.EventEmitter);

this.pingTimer = setTimeout(this.ping(), 5000);
// Last-ditch heartbeat to get data from the copter every second.
this.pingInterval = setInterval(this.ping.bind(this), 1000);

@@ -313,3 +315,3 @@ return this.reset();

this.pingTimer = setTimeout(this.ping(), 500);
this.pingTimer = setTimeout(this.ping(), 100);

@@ -316,0 +318,0 @@ var ack = new Crazypacket.Ack(buf);

@@ -70,2 +70,3 @@ // Parameters, aka Crazyflie copter settings.

console.log('requesting value for param', name);
var parameter = this.variables[name];

@@ -133,3 +134,3 @@ this.driver.getParameter(parameter.id);

param.value = Crazypacket.readType(payload, param.type, 1);
param.value = Crazypacket.readType(payload, DataTypes[param.type], 1);

@@ -171,4 +172,2 @@ var deferreds = this.getDeferreds[name];

console.log('param: '+item.id, item.fullname);
if (item.id < this.total)

@@ -175,0 +174,0 @@ this.driver.requestParameter(item.id + 1);

@@ -73,3 +73,3 @@ // See the logging section here:

console.log('telemetry: ' + item.fullname, item.id, item.type);
// console.log('telemetry: ' + item.fullname, item.id, item.type);
this.variables[item.fullname] = item;

@@ -137,3 +137,4 @@

default:
console.log('got telemetry but not ready for it yet; id=', payload[0]);
// console.log('got telemetry but not ready for it yet; id=', payload[0]);
break;
}

@@ -213,3 +214,3 @@ };

{ fetchAs: 7, type: this.variables['stabilizer.yaw'].type, id: this.variables['stabilizer.yaw'].id },
// { storage: 7, type: this.variables['stabilizer.thrust'].type, id: this.variables['stabilizer.thrust'].id },
{ fetchAs: 5, type: this.variables['stabilizer.thrust'].type, id: this.variables['stabilizer.thrust'].id },
],

@@ -267,5 +268,6 @@ };

{
roll: payload.readFloatLE(4),
pitch: payload.readFloatLE(8),
yaw: payload.readFloatLE(12)
roll: payload.readFloatLE(4),
pitch: payload.readFloatLE(8),
yaw: payload.readFloatLE(12),
thrust: payload.readInt16LE(16)
};

@@ -272,0 +274,0 @@ this.emit('stabilizer', update);

{
"name": "aerogel",
"version": "0.0.3",
"version": "0.0.4",
"description": "CrazyFlie control software",

@@ -5,0 +5,0 @@ "author": "C J Silverio <ceejceej@gmail.com>",

@@ -8,3 +8,3 @@ aerogel

[![NPM](https://nodei.co/npm/aerogel.png)](https://nodei.co/npm/aerogel/)
[![NPM](https://nodei.co/npm/aerogel.png)](http://nodei.co/npm/aerogel/)

@@ -39,11 +39,11 @@ ## Installation

{
if (copters.length === 0)
{
console.error('No copters found! Is your copter turned on?');
process.exit(1);
}
if (copters.length === 0)
{
console.error('No copters found! Is your copter turned on?');
process.exit(1);
}
var uri = copters[0];
console.log('Using copter at', uri);
return uri;
var uri = copters[0];
console.log('Using copter at', uri);
return uri;
})

@@ -57,2 +57,4 @@ .then(function(uri) { return copter.connect(uri); })

Look at the [examples](examples/) directory for more.
## Telemetry

@@ -62,10 +64,8 @@

`copter.handleStabilizerTelemetry()` gets an object with three orientation fields:
`copter.handleStabilizerTelemetry()` gets an object with three orientation fields: `roll`, `pitch`, `yaw`.
- `roll`
- `pitch`
- `yaw`
`copter.handleMotorTelemetry()` gets an object with the state of the four motors: `m1`, `m2`, `m3`, and `m4`.
`copter.handleAccTelemetry()` gets an object with the state of the accelerometer: `x`, `y`, and `z`. The accelerometer data is available only for 10DOF copters with tip-of-tree firmware.
## API

@@ -72,0 +72,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc