From 4e0a6e16724a224f1b952676c70875d252c92f97 Mon Sep 17 00:00:00 2001 From: Edgar O Silva Date: Wed, 11 Dec 2013 14:43:04 -0600 Subject: [PATCH 1/6] Added example for beaglebone servo. --- examples/bbb_servo.coffee | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 examples/bbb_servo.coffee diff --git a/examples/bbb_servo.coffee b/examples/bbb_servo.coffee new file mode 100644 index 0000000..0ee6e2b --- /dev/null +++ b/examples/bbb_servo.coffee @@ -0,0 +1,20 @@ +Cylon = require '../..' + +Cylon.robot + connection: { name: 'beaglebone', adaptor: 'beaglebone' } + device: { name: 'servo', driver: 'servo', pin: 'P9_14' } + + work: (my) -> + + 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() From 3c1efe6f32b0a54be4e667cb57b3ff62b973df0f Mon Sep 17 00:00:00 2001 From: Edgar O Silva Date: Wed, 11 Dec 2013 16:51:43 -0600 Subject: [PATCH 2/6] Update the pin for the correct bbb header. --- examples/bbb_led_brightness.coffee | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/bbb_led_brightness.coffee b/examples/bbb_led_brightness.coffee index 7ebbe0b..1378b5a 100644 --- a/examples/bbb_led_brightness.coffee +++ b/examples/bbb_led_brightness.coffee @@ -2,11 +2,8 @@ Cylon = require('..') # Initialize the robot Cylon.robot - connection: - name: 'beaglebone', adaptor: 'beaglebone' - - device: - name: 'led', driver: 'led', pin: 11 + connection: { name: 'beaglebone', adaptor: 'beaglebone' } + device: { name: 'led', driver: 'led', pin: 'P9_14' } work: (my) -> # we do our thing here From 3f6b5cfd416e0dd8fe0846a0438f9cc266e07bbf Mon Sep 17 00:00:00 2001 From: Edgar O Silva Date: Wed, 11 Dec 2013 16:55:11 -0600 Subject: [PATCH 3/6] Fix incorrect require. --- examples/bbb_servo.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/bbb_servo.coffee b/examples/bbb_servo.coffee index 0ee6e2b..e0882d6 100644 --- a/examples/bbb_servo.coffee +++ b/examples/bbb_servo.coffee @@ -1,4 +1,4 @@ -Cylon = require '../..' +Cylon = require '..' Cylon.robot connection: { name: 'beaglebone', adaptor: 'beaglebone' } From fef740533cbbd0e682fd06cfa9516ae9248dd155 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Wed, 18 Dec 2013 12:26:21 -0800 Subject: [PATCH 4/6] Add tests for Adaptor class --- test/dist/specs/adaptor.spec.js | 44 ++++++++++++++++++++++++++++-- test/src/specs/adaptor.spec.coffee | 35 ++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/test/dist/specs/adaptor.spec.js b/test/dist/specs/adaptor.spec.js index 38853cf..07c4c29 100644 --- a/test/dist/specs/adaptor.spec.js +++ b/test/dist/specs/adaptor.spec.js @@ -1,13 +1,51 @@ (function() { 'use strict'; + var EventEmitter; + source("adaptor"); + EventEmitter = require('events').EventEmitter; + describe("Adaptor", function() { - var adaptor; + var adaptor, conn; + conn = new EventEmitter; 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); diff --git a/test/src/specs/adaptor.spec.coffee b/test/src/specs/adaptor.spec.coffee index 1760ade..3649575 100644 --- a/test/src/specs/adaptor.spec.coffee +++ b/test/src/specs/adaptor.spec.coffee @@ -1,8 +1,37 @@ -'use strict'; +'use strict' source "adaptor" +EventEmitter = require('events').EventEmitter 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 From dbcc05a13c09a9c227b3004f808c3c6ea8e5e189 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Wed, 18 Dec 2013 13:02:18 -0800 Subject: [PATCH 5/6] Add tests for Driver class --- test/dist/specs/driver.spec.js | 52 ++++++++++++++++++++++++++----- test/src/specs/driver.spec.coffee | 37 ++++++++++++++++++++-- 2 files changed, 80 insertions(+), 9 deletions(-) diff --git a/test/dist/specs/driver.spec.js b/test/dist/specs/driver.spec.js index d09b368..f89ed82 100644 --- a/test/dist/specs/driver.spec.js +++ b/test/dist/specs/driver.spec.js @@ -1,17 +1,55 @@ (function() { 'use strict'; + var EventEmitter; + source("driver"); + EventEmitter = require('events').EventEmitter; + describe("Driver", function() { - var driver; + var device, driver; + device = new EventEmitter; + device.connection = 'connect'; driver = new Cylon.Driver({ - name: 'max', - device: { - connection: 'connect', - pin: 13 - } + name: 'TestDriver', + device: device + }); + 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); diff --git a/test/src/specs/driver.spec.coffee b/test/src/specs/driver.spec.coffee index 1850cd7..027e9e2 100644 --- a/test/src/specs/driver.spec.coffee +++ b/test/src/specs/driver.spec.coffee @@ -1,8 +1,41 @@ 'use strict'; source "driver" +EventEmitter = require('events').EventEmitter 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 From 336b11a8d45d03801f31c353ab249fbe1aaf1c95 Mon Sep 17 00:00:00 2001 From: Edgar O Silva Date: Thu, 19 Dec 2013 23:16:13 -0600 Subject: [PATCH 6/6] Added comments and safety instructions to servo example. --- examples/bbb_servo.coffee | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/examples/bbb_servo.coffee b/examples/bbb_servo.coffee index e0882d6..65df378 100644 --- a/examples/bbb_servo.coffee +++ b/examples/bbb_servo.coffee @@ -6,6 +6,21 @@ Cylon.robot 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