Merge branch 'master' into 72-i2c-support
This commit is contained in:
commit
c357b646dd
|
@ -0,0 +1,35 @@
|
||||||
|
Cylon = require '..'
|
||||||
|
|
||||||
|
Cylon.robot
|
||||||
|
connection: { name: 'beaglebone', adaptor: 'beaglebone' }
|
||||||
|
device: { name: 'servo', driver: 'servo', pin: 'P9_14' }
|
||||||
|
|
||||||
|
work: (my) ->
|
||||||
|
|
||||||
|
# Be carefull with your servo angles or you might DAMAGE the servo!
|
||||||
|
# Cylon uses a 50hz/s (20ms period) frequency and a Duty Cycle
|
||||||
|
# of 0.5ms to 2.5ms to control the servo angle movement.
|
||||||
|
#
|
||||||
|
# This means:
|
||||||
|
# 1. 0.5ms == 0 degrees
|
||||||
|
# 2. 1.5ms == 90 degrees
|
||||||
|
# 3. 2.5ms == 180 degrees
|
||||||
|
# (It is usually safe to start with a 90 degree angle, 1.5ms duty
|
||||||
|
# cycle in most servos)
|
||||||
|
#
|
||||||
|
# Please review your servo datasheet to make sure of correct
|
||||||
|
# angle range and the Freq/MS Duty cycle it requires.
|
||||||
|
# If more servo support is needed leave us a comment, raise an
|
||||||
|
# issue or help us add more support.
|
||||||
|
angle = 30
|
||||||
|
increment = 40
|
||||||
|
|
||||||
|
every 1.seconds(), ->
|
||||||
|
angle += increment
|
||||||
|
my.servo.angle angle
|
||||||
|
|
||||||
|
Logger.info "Current Angle: #{my.servo.currentAngle()}"
|
||||||
|
|
||||||
|
increment = -increment if (angle is 30) or (angle is 150)
|
||||||
|
|
||||||
|
.start()
|
|
@ -2,11 +2,8 @@ Cylon = require('..')
|
||||||
|
|
||||||
# Initialize the robot
|
# Initialize the robot
|
||||||
Cylon.robot
|
Cylon.robot
|
||||||
connection:
|
connection: { name: 'beaglebone', adaptor: 'beaglebone' }
|
||||||
name: 'beaglebone', adaptor: 'beaglebone'
|
device: { name: 'led', driver: 'led', pin: 'P9_14' }
|
||||||
|
|
||||||
device:
|
|
||||||
name: 'led', driver: 'led', pin: 11
|
|
||||||
|
|
||||||
work: (my) ->
|
work: (my) ->
|
||||||
# we do our thing here
|
# we do our thing here
|
||||||
|
|
|
@ -1,13 +1,51 @@
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
var EventEmitter;
|
||||||
|
|
||||||
source("adaptor");
|
source("adaptor");
|
||||||
|
|
||||||
|
EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
describe("Adaptor", function() {
|
describe("Adaptor", function() {
|
||||||
var adaptor;
|
var adaptor, conn;
|
||||||
|
conn = new EventEmitter;
|
||||||
adaptor = new Cylon.Adaptor({
|
adaptor = new Cylon.Adaptor({
|
||||||
name: 'adapt'
|
name: 'TestAdaptor',
|
||||||
|
connection: conn
|
||||||
|
});
|
||||||
|
it("provides a 'connect' method that accepts a callback", function() {
|
||||||
|
var spy;
|
||||||
|
expect(adaptor.connect).to.be.a('function');
|
||||||
|
spy = sinon.spy();
|
||||||
|
adaptor.connect(function() {
|
||||||
|
return spy();
|
||||||
|
});
|
||||||
|
return spy.should.have.been.called;
|
||||||
|
});
|
||||||
|
it("tells the connection to emit the 'connect' event when connected", function() {
|
||||||
|
var spy;
|
||||||
|
spy = sinon.spy();
|
||||||
|
adaptor.connection.on('connect', function() {
|
||||||
|
return spy();
|
||||||
|
});
|
||||||
|
adaptor.connect(function() {});
|
||||||
|
return spy.should.have.been.called;
|
||||||
|
});
|
||||||
|
it("provides a 'disconnect' method", function() {
|
||||||
|
return expect(adaptor.disconnect).to.be.a('function');
|
||||||
|
});
|
||||||
|
it("provides a default empty array of commands", function() {
|
||||||
|
return expect(adaptor.commands()).to.be.eql([]);
|
||||||
|
});
|
||||||
|
it("saves the provided name in the @name variable", function() {
|
||||||
|
return expect(adaptor.name).to.be.eql("TestAdaptor");
|
||||||
|
});
|
||||||
|
it("saves the provided connection in the @connection variable", function() {
|
||||||
|
return expect(adaptor.connection).to.be.eql(conn);
|
||||||
|
});
|
||||||
|
return it("contains a reference to itself in the @self variable", function() {
|
||||||
|
return expect(adaptor.self).to.be.eql(adaptor);
|
||||||
});
|
});
|
||||||
return it('needs tests');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
|
@ -1,17 +1,55 @@
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
var EventEmitter;
|
||||||
|
|
||||||
source("driver");
|
source("driver");
|
||||||
|
|
||||||
|
EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
describe("Driver", function() {
|
describe("Driver", function() {
|
||||||
var driver;
|
var device, driver;
|
||||||
|
device = new EventEmitter;
|
||||||
|
device.connection = 'connect';
|
||||||
driver = new Cylon.Driver({
|
driver = new Cylon.Driver({
|
||||||
name: 'max',
|
name: 'TestDriver',
|
||||||
device: {
|
device: device
|
||||||
connection: 'connect',
|
});
|
||||||
pin: 13
|
it("provides a 'start' method that accepts a callback", function() {
|
||||||
}
|
var spy;
|
||||||
|
expect(driver.start).to.be.a('function');
|
||||||
|
spy = sinon.spy();
|
||||||
|
driver.start(function() {
|
||||||
|
return spy();
|
||||||
|
});
|
||||||
|
return spy.should.have.been.called;
|
||||||
|
});
|
||||||
|
it("tells the device to emit the 'start' event when started", function() {
|
||||||
|
var spy;
|
||||||
|
spy = sinon.spy();
|
||||||
|
driver.device.on('start', function() {
|
||||||
|
return spy();
|
||||||
|
});
|
||||||
|
driver.start(function() {});
|
||||||
|
return spy.should.have.been.called;
|
||||||
|
});
|
||||||
|
it("provides a 'stop' method", function() {
|
||||||
|
return expect(driver.stop).to.be.a('function');
|
||||||
|
});
|
||||||
|
it("provides a default empty array of commands", function() {
|
||||||
|
return expect(driver.commands()).to.be.eql([]);
|
||||||
|
});
|
||||||
|
it("saves the provided name in the @name variable", function() {
|
||||||
|
return expect(driver.name).to.be.eql("TestDriver");
|
||||||
|
});
|
||||||
|
it("saves the provided device in the @device variable", function() {
|
||||||
|
return expect(driver.device).to.be.eql(device);
|
||||||
|
});
|
||||||
|
it("saves the provided device connection in the @device variable", function() {
|
||||||
|
return expect(driver.connection).to.be.eql('connect');
|
||||||
|
});
|
||||||
|
return it("contains a reference to itself in the @self variable", function() {
|
||||||
|
return expect(driver.self).to.be.eql(driver);
|
||||||
});
|
});
|
||||||
return it('needs tests');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
|
@ -1,8 +1,37 @@
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
source "adaptor"
|
source "adaptor"
|
||||||
|
EventEmitter = require('events').EventEmitter
|
||||||
|
|
||||||
describe "Adaptor", ->
|
describe "Adaptor", ->
|
||||||
adaptor = new Cylon.Adaptor(name: 'adapt')
|
conn = new EventEmitter
|
||||||
|
adaptor = new Cylon.Adaptor
|
||||||
|
name: 'TestAdaptor'
|
||||||
|
connection: conn
|
||||||
|
|
||||||
it 'needs tests'
|
it "provides a 'connect' method that accepts a callback", ->
|
||||||
|
expect(adaptor.connect).to.be.a 'function'
|
||||||
|
spy = sinon.spy()
|
||||||
|
adaptor.connect(-> spy())
|
||||||
|
spy.should.have.been.called
|
||||||
|
|
||||||
|
it "tells the connection to emit the 'connect' event when connected", ->
|
||||||
|
spy = sinon.spy()
|
||||||
|
adaptor.connection.on 'connect', -> spy()
|
||||||
|
adaptor.connect(->)
|
||||||
|
spy.should.have.been.called
|
||||||
|
|
||||||
|
it "provides a 'disconnect' method", ->
|
||||||
|
expect(adaptor.disconnect).to.be.a 'function'
|
||||||
|
|
||||||
|
it "provides a default empty array of commands", ->
|
||||||
|
expect(adaptor.commands()).to.be.eql []
|
||||||
|
|
||||||
|
it "saves the provided name in the @name variable", ->
|
||||||
|
expect(adaptor.name).to.be.eql "TestAdaptor"
|
||||||
|
|
||||||
|
it "saves the provided connection in the @connection variable", ->
|
||||||
|
expect(adaptor.connection).to.be.eql conn
|
||||||
|
|
||||||
|
it "contains a reference to itself in the @self variable", ->
|
||||||
|
expect(adaptor.self).to.be.eql adaptor
|
||||||
|
|
|
@ -1,8 +1,41 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
source "driver"
|
source "driver"
|
||||||
|
EventEmitter = require('events').EventEmitter
|
||||||
|
|
||||||
describe "Driver", ->
|
describe "Driver", ->
|
||||||
driver = new Cylon.Driver(name: 'max', device: {connection: 'connect', pin: 13})
|
device = new EventEmitter
|
||||||
|
device.connection = 'connect'
|
||||||
|
driver = new Cylon.Driver
|
||||||
|
name: 'TestDriver'
|
||||||
|
device: device
|
||||||
|
|
||||||
it 'needs tests'
|
it "provides a 'start' method that accepts a callback", ->
|
||||||
|
expect(driver.start).to.be.a 'function'
|
||||||
|
spy = sinon.spy()
|
||||||
|
driver.start(-> spy())
|
||||||
|
spy.should.have.been.called
|
||||||
|
|
||||||
|
it "tells the device to emit the 'start' event when started", ->
|
||||||
|
spy = sinon.spy()
|
||||||
|
driver.device.on 'start', -> spy()
|
||||||
|
driver.start(->)
|
||||||
|
spy.should.have.been.called
|
||||||
|
|
||||||
|
it "provides a 'stop' method", ->
|
||||||
|
expect(driver.stop).to.be.a 'function'
|
||||||
|
|
||||||
|
it "provides a default empty array of commands", ->
|
||||||
|
expect(driver.commands()).to.be.eql []
|
||||||
|
|
||||||
|
it "saves the provided name in the @name variable", ->
|
||||||
|
expect(driver.name).to.be.eql "TestDriver"
|
||||||
|
|
||||||
|
it "saves the provided device in the @device variable", ->
|
||||||
|
expect(driver.device).to.be.eql device
|
||||||
|
|
||||||
|
it "saves the provided device connection in the @device variable", ->
|
||||||
|
expect(driver.connection).to.be.eql 'connect'
|
||||||
|
|
||||||
|
it "contains a reference to itself in the @self variable", ->
|
||||||
|
expect(driver.self).to.be.eql driver
|
||||||
|
|
Loading…
Reference in New Issue