Organization of new examples and literate/js versions of each

This commit is contained in:
Andrew Stewart 2013-11-28 12:34:15 -08:00
parent 2c52db8086
commit b7e4d4b489
10 changed files with 212 additions and 36 deletions

View File

@ -1,4 +1,4 @@
Cylon = require '..'
Cylon = require '../..'
Cylon.robot
connection:
@ -8,12 +8,9 @@ Cylon.robot
name: 'drone', driver: 'crazyflie'
work: (my) ->
#my.drone.setParam('flightmode.althold', true)
my.drone.on 'start', ->
my.drone.takeoff()
after 10.seconds(), ->
my.drone.land()
after 15.seconds(), ->
my.drone.stop()
after 10.seconds(), -> my.drone.land()
after 15.seconds(), -> my.drone.stop()
.start()

View File

@ -0,0 +1,22 @@
var Cylon = require('../..');
Cylon.robot({
connection: {
name: 'crazyflie',
adaptor: 'crazyflie',
port: "radio://1/10/250KPS"
},
device: {
name: 'drone',
driver: 'crazyflie'
},
work: function(my) {
my.drone.on('start', function() {
my.drone.takeoff();
after(10..seconds(), function() { my.drone.land(); });
after(15..seconds(), function() { my.drone.stop(); });
});
}
}).start();

View File

@ -0,0 +1,38 @@
# Crazyflie
For this Cylon demo, we're going to connect to a Crazyflie, and then make it
take off and land. Before we get started, make sure you've got the
`cylon-crazyflie` adaptor installed.
To start us off, let's import Cylon:
Cylon = require '../..'
Now that we've got that set up, we can start defining our robot:
Cylon.robot
We'll be using one connection and one device for this robot, both using the
crazyflie adaptor. We'll be connecting to the Crazyflie using the CrazyRadio.
connection:
name: 'crazyflie', adaptor: 'crazyflie', port: "radio://1/10/250KPS"
device:
name: 'drone', driver: 'crazyflie'
With the parts in place, we can start defining our robot's work.
work: (my) ->
When our drone is ready, we'll make it takeoff. After ten seconds, we'll tell it
to land, and five seconds after that to stop.
my.drone.on 'start', ->
my.drone.takeoff()
after 10.seconds(), -> my.drone.land()
after 15.seconds(), -> my.drone.stop()
With all that done, we can start up the robot and get the Crazyflie flying:
.start()

View File

@ -1,17 +1,13 @@
Cylon = require('..')
Cylon = require '../..'
# Initialize the robot
Cylon.robot
connection:
name: 'raspi', adaptor: 'raspi', port: '/dev/ttyACM0'
device:
name: 'led', driver: 'led', pin: 11
connection: { name: 'raspi', adaptor: 'raspi', port: '/dev/ttyACM0' }
device: { name: 'led', driver: 'led', pin: 11 }
work: (my) ->
# we do our thing here
brightness = 0
fade = 5
every 0.05.seconds(), ->
brightness += fade
my.led.brightness(brightness)

View File

@ -0,0 +1,17 @@
var Cylon = require('../..');
Cylon.robot({
connection: { name: 'raspi', adaptor: 'raspi', port: '/dev/ttyACM0' },
device: { name: 'led', driver: 'led', pin: 11 },
work: function(my) {
var brightness = 0;
var fade = 5;
every(0.05.seconds(), function() {
brightness += fade;
my.led.brightness(brightness);
if ((brightness === 0) || (brightness === 255)) { fade = -fade; }
});
}
}).start();

View File

@ -0,0 +1,42 @@
# Raspberry Pi - LED Brightness
For this example, we'll be using an LED on a Raspberry Pi board, and modifying it's
brightness to make it fade in and out. Before we start, make sure you've got the
`cylon-raspi` module installed.
Let's start by importing Cylon:
Cylon = require '../..'
Once we've got that, we can start defining our robot:
Cylon.robot
We'll be using a Raspberry Pi as our connection. As well, we'll let our robot
know about the LED we'll be modifying, on pin #11 of the Raspberry Pi.
connection: { name: 'raspi', adaptor: 'raspi', port: '/dev/ttyACM0' }
device: { name: 'led', driver: 'led', pin: 11 }
Next up, we'll define our robot's work:
work: (my) ->
We'll set some variables here: brightness will represent the LED's brightness,
from 1-255, and 'fade' will be the brightness change on each tick.
brightness = 0
fade = 5
Every 50 milliseconds, we'll be incrementing the brightness by `fade`'s value,
setting the LED to that brightness, and reversing `fade`'s value if brightness
hits 0 or 255.
every 0.05.seconds(), ->
brightness += fade
my.led.brightness(brightness)
fade = -fade if (brightness is 0) or (brightness is 255)
And with that done, we can now start our robot.
.start()

View File

@ -1,22 +0,0 @@
Cylon = require('..')
# Initialize the robot
Cylon.robot
connection:
name: 'raspi', adaptor: 'raspi', port: '/dev/ttyACM0'
device:
name: 'servo', driver: 'servo', pin: 11
work: (my) ->
# we do our thing here
work: (my) ->
angle = 30
increment = 40
every 1.seconds(), ->
angle += increment
my.servo.angle(angle)
console.log("Current Angle => #{ my.servo.currentAngle() }")
increment = -increment if (angle is 30) or (angle is 150)
.start()

View File

@ -0,0 +1,20 @@
Cylon = require '../..'
Cylon.robot
connection: { name: 'raspi', adaptor: 'raspi', port: '/dev/ttyACM0' }
device: { name: 'servo', driver: 'servo', pin: 11 }
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()

View File

@ -0,0 +1,18 @@
var Cylon = require('../..');
Cylon.robot({
connection: { name: 'raspi', adaptor: 'raspi', port: '/dev/ttyACM0' },
device: { name: 'servo', driver: 'servo', pin: 11 },
work: function(my) {
var angle = 30;
var increment = 40;
every(1..seconds(), function() {
angle += increment;
my.servo.angle(angle);
Logger.info("Current Angle: " + (my.servo.currentAngle()));
if ((angle === 30) || (angle === 150)) { increment = -increment; }
});
}
}).start();

View File

@ -0,0 +1,48 @@
# Raspberry Pi - Servo
For this example, similar in structure to the led_brightness example, we're
going to take a Raspberry Pi, and modify the angle of an attached servo such
that it's continually turning back and forth.
Before we get started, make sure to have the `cylon-raspi` module installed.
First, let's require Cylon:
Cylon = require '../..'
Now we can start defining our robot:
Cylon.robot
We'll be connecting to an Raspberry Pi, and using a servo attached to the
Raspberry Pi on pin 11.
connection: { name: 'raspi', adaptor: 'raspi', port: '/dev/ttyACM0' }
device: { name: 'servo', driver: 'servo', pin: 11 }
We'll start defining the work for our robot next:
work: (my) ->
We'll define variables to hold our servo's angle, and the rate at which that
angle will change:
angle = 30
increment = 40
Every second, we'll increment the `angle`, set the servo to run at that angle,
and log the angle we're running at to the console. We'll also make sure to
change the increment if the angle is at the upper/lower bounds of the values
supported:
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)
And with all that done, we can now start our robot:
.start()