2013-11-28 03:34:27 +08:00
|
|
|
# Hello
|
|
|
|
|
|
|
|
For this exceedingly simple example, we're going to define a robot that has no
|
|
|
|
devices, no connections, and just demonstrates the tools for performing work on
|
|
|
|
an interval, and after a timeout.
|
|
|
|
|
|
|
|
Let's start by importing Cylon:
|
|
|
|
|
2014-03-27 08:06:26 +08:00
|
|
|
var Cylon = require('../..');
|
2013-11-28 03:34:27 +08:00
|
|
|
|
|
|
|
Now we can define our robot:
|
|
|
|
|
2014-03-27 08:06:26 +08:00
|
|
|
Cylon.robot({
|
2014-11-26 06:39:24 +08:00
|
|
|
name: 'test',
|
|
|
|
|
2014-11-26 08:01:31 +08:00
|
|
|
connections: {
|
|
|
|
loopback: { adaptor: 'loopback' }
|
|
|
|
},
|
|
|
|
|
|
|
|
devices: {
|
|
|
|
ping: { driver: 'ping' }
|
|
|
|
},
|
2013-11-28 03:34:27 +08:00
|
|
|
|
|
|
|
For work, it's going to print a message to the console every second, and another
|
2014-11-26 06:39:24 +08:00
|
|
|
message after five seconds have elapsed.
|
2013-11-28 03:34:27 +08:00
|
|
|
|
2014-11-26 06:39:24 +08:00
|
|
|
work: function(my) {
|
|
|
|
every((1).seconds(), function(){
|
2014-01-04 09:18:09 +08:00
|
|
|
console.log("Hello, human!")
|
2014-11-26 06:39:24 +08:00
|
|
|
console.log(my.ping.ping());
|
2014-03-27 08:06:26 +08:00
|
|
|
});
|
2013-11-28 03:34:27 +08:00
|
|
|
|
2014-11-26 06:39:24 +08:00
|
|
|
after((5).seconds(), function(){
|
2014-08-01 07:45:18 +08:00
|
|
|
console.log("I've been at your command for 5 seconds now.")
|
2014-03-27 08:06:26 +08:00
|
|
|
});
|
|
|
|
}
|
2013-11-28 03:34:27 +08:00
|
|
|
|
|
|
|
Simple as can be. Now that we're done, let's start the robot:
|
|
|
|
|
2014-03-27 08:06:26 +08:00
|
|
|
}).start();
|