Merge master and multiple examples
This commit is contained in:
parent
95aa7f8962
commit
8ccf93ce40
|
@ -6,15 +6,14 @@ bots = [
|
||||||
{ port: '/dev/cu.Sphero-BRG', name: 'Louie' }
|
{ port: '/dev/cu.Sphero-BRG', name: 'Louie' }
|
||||||
]
|
]
|
||||||
|
|
||||||
SpheroRobot =
|
class SpheroRobot
|
||||||
connection:
|
connection: { name: 'Sphero', adaptor: 'sphero' }
|
||||||
name: 'Sphero', adaptor: 'sphero'
|
|
||||||
|
|
||||||
work: (my) ->
|
work: (my) ->
|
||||||
Logger.info "Robot #{my.name} is now working!"
|
Logger.info "Robot #{my.name} is now working!"
|
||||||
|
|
||||||
for bot in bots
|
for bot in bots
|
||||||
robot = Object.create(SpheroRobot)
|
robot = new SpheroRobot
|
||||||
robot.connection.port = bot.port
|
robot.connection.port = bot.port
|
||||||
robot.name = bot.name
|
robot.name = bot.name
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
// Generated by CoffeeScript 1.6.3
|
|
||||||
var Cylon = require('../..');
|
var Cylon = require('../..');
|
||||||
|
|
||||||
var bots = [
|
var bots = [
|
||||||
|
@ -7,17 +6,22 @@ var bots = [
|
||||||
{ port: '/dev/cu.Sphero-BRG', name: 'Louie' }
|
{ port: '/dev/cu.Sphero-BRG', name: 'Louie' }
|
||||||
];
|
];
|
||||||
|
|
||||||
var SpheroRobot = {
|
var SpheroRobot = (function() {
|
||||||
connection: { name: 'Sphero', adaptor: 'sphero' },
|
function SpheroRobot() {}
|
||||||
|
|
||||||
work: function(my) {
|
SpheroRobot.prototype.connection = { name: 'Sphero', adaptor: 'sphero' };
|
||||||
|
|
||||||
|
SpheroRobot.prototype.work = function(my) {
|
||||||
Logger.info("Robot " + my.name + " is now working!");
|
Logger.info("Robot " + my.name + " is now working!");
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
return SpheroRobot;
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
for (var i = 0; i < bots.length; i++) {
|
for (var i = 0; i < bots.length; i++) {
|
||||||
var bot = bots[i];
|
var bot = bots[i];
|
||||||
var robot = Object.create(SpheroRobot);
|
var robot = new SpheroRobot;
|
||||||
|
|
||||||
robot.connection.port = bot.port;
|
robot.connection.port = bot.port;
|
||||||
robot.name = bot.name;
|
robot.name = bot.name;
|
||||||
|
|
|
@ -24,16 +24,15 @@ a base robot and change it's attributes as needed.
|
||||||
{ port: '/dev/cu.Sphero-BRG', name: 'Louie' }
|
{ port: '/dev/cu.Sphero-BRG', name: 'Louie' }
|
||||||
]
|
]
|
||||||
|
|
||||||
Now we can define our cleverly-named `SpheroRobot` object. This will be the base
|
Now we can define our cleverly-named `SpheroRobot` class. This will be the base
|
||||||
object for all three of the robots.
|
class for all three of the robots.
|
||||||
|
|
||||||
SpheroRobot =
|
class SpheroRobot
|
||||||
|
|
||||||
Every robot needs to connect to a Sphero. We're doing this using the
|
Every robot needs to connect to a Sphero. We're doing this using the
|
||||||
`cylon-sphero` adaptor.
|
`cylon-sphero` adaptor.
|
||||||
|
|
||||||
connection:
|
connection: { name: 'Sphero', adaptor: 'sphero' }
|
||||||
name: 'Sphero', adaptor: 'sphero'
|
|
||||||
|
|
||||||
We'll just give our robots some basic work so we can tell they're actually
|
We'll just give our robots some basic work so we can tell they're actually
|
||||||
working:
|
working:
|
||||||
|
@ -43,12 +42,12 @@ working:
|
||||||
|
|
||||||
And that's all we need for that.
|
And that's all we need for that.
|
||||||
|
|
||||||
Next up, we'll create Cylon robots by making a duplicate of the `SpheroRobot`
|
Next up, we'll create Cylon robots by making an instance of the `SpheroRobot`
|
||||||
object, and modifying the attributes that are unique to each robot. After the
|
class, and modifying the attributes that are unique to each robot. After the
|
||||||
customized robot is ready, we'll feed it into Cylon.
|
customized robot is ready, we'll feed it into Cylon.
|
||||||
|
|
||||||
for bot in bots
|
for bot in bots
|
||||||
robot = Object.create(SpheroRobot)
|
robot = new SpheroRobot
|
||||||
robot.connection.port = bot.port
|
robot.connection.port = bot.port
|
||||||
robot.name = bot.name
|
robot.name = bot.name
|
||||||
|
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
Cylon = require '../..'
|
|
||||||
|
|
||||||
bots = [
|
|
||||||
{ name: 'Huey' },
|
|
||||||
{ name: 'Dewey' },
|
|
||||||
{ name: 'Louie' }
|
|
||||||
]
|
|
||||||
|
|
||||||
class ChattyRobot
|
|
||||||
connection: { name: 'loopback', adaptor: 'loopback' }
|
|
||||||
device: { name: 'ping', driver: 'ping' }
|
|
||||||
|
|
||||||
hello: (my) ->
|
|
||||||
Logger.info "#{my.name}: #{my.ping.ping()}"
|
|
||||||
|
|
||||||
work: (my) ->
|
|
||||||
every 1.seconds(), ->
|
|
||||||
my.hello(my)
|
|
||||||
|
|
||||||
for bot in bots
|
|
||||||
robot = new ChattyRobot
|
|
||||||
robot.name = bot.name
|
|
||||||
Cylon.robot robot
|
|
||||||
|
|
||||||
Cylon.start()
|
|
|
@ -1,40 +0,0 @@
|
||||||
var bot, bots, robot, _i, _len;
|
|
||||||
|
|
||||||
var Cylon = require('../..');
|
|
||||||
|
|
||||||
bots = [
|
|
||||||
{ name: 'Huey' },
|
|
||||||
{ name: 'Dewey' },
|
|
||||||
{ name: 'Louie' }
|
|
||||||
];
|
|
||||||
|
|
||||||
var ChattyRobot = (function() {
|
|
||||||
function ChattyRobot() {}
|
|
||||||
|
|
||||||
ChattyRobot.prototype.connection = { name: 'loopback', adaptor: 'loopback' };
|
|
||||||
ChattyRobot.prototype.device = { name: 'ping', driver: 'ping' };
|
|
||||||
|
|
||||||
ChattyRobot.prototype.hello = function(my) {
|
|
||||||
Logger.info("" + my.name + ": " + (my.ping.ping()));
|
|
||||||
};
|
|
||||||
|
|
||||||
ChattyRobot.prototype.work = function(my) {
|
|
||||||
every((1).seconds(), function() {
|
|
||||||
my.hello(my);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return ChattyRobot;
|
|
||||||
|
|
||||||
})();
|
|
||||||
|
|
||||||
for (var i = 0; i < bots.length; i++) {
|
|
||||||
var bot = bots[i];
|
|
||||||
var robot = new ChattyRobot;
|
|
||||||
|
|
||||||
robot.name = bot.name;
|
|
||||||
|
|
||||||
Cylon.robot(robot);
|
|
||||||
}
|
|
||||||
|
|
||||||
Cylon.start();
|
|
Loading…
Reference in New Issue