Using Cylon.js at CoderDojo WNY
CoderDojo is a Meetup group for kids to learn to code. They bring their ideas and adult developers help usher them along the way to teach them how to develop and to reach the goals they set for themselves.
At the Buffalo chapter of CoderDojo, we often have side projects to expose the students to other aspects of programming. At the most recent meeting, we brought Parrot AR Drones and allowed the kids an opportunity to manipulate scripts in an attempt to make a drone takeoff, move to a landing space.
This experiment involved a few factors outside of the code, like trying to measure how far the landing zone was from the takeoff site, calculating for any obstacles (including human traffic) and how outside influences, like a vent in the travel lane, would affect landing. The kids attacked the problem with a ferocious logic and soon appointed jobs. Each got a chance to change the code after making their observations.
We began with the following sample Cylon.js script, using Node.js as our motivator:
var Cylon = require('cylon');
Cylon.robot({
connection: { name: 'ardrone', adaptor: 'ardrone', port: '192.168.1.1' },
device: {name: 'drone', driver: 'ardrone'},
work: function(my) {
my.drone.takeoff();
after((10).seconds(), function() {
my.drone.land();
});
after((15).seconds(), function() {
my.drone.stop();
});
}
}).start();
This code is provided in the AR Drone repo for Cylon.js and we used it as a testing script to prove we were able to connect to the drone correctly. Naturally, once we had that, the kids wanted to ensure the drone could do “cool stunts” and one of our students added the following line:
after((5).seconds(), function() {
my.drone.animate(‘flipLeft’, 15);
});
Producing the following result:
One the flexibility of the drone was established, the kids were off to the races. The first portion of their experiments involved speed and time. The commands are given in order in Cylon.js and therefore sequence must be taken into account.
The code to move forward involves a speed factor that will propel the drone a certain distance depending how long the command stays active. The range for speed is 0.0 to 1, meaning 1 is 100% of the possible push to move forward. The students decided 0.1 was a good place to start to see if it was enough.
after((7).seconds(), function(){
my.drone.front(0.1);
});
After much experimentation (and goofing with other functions like clockwise rotation and vzDance) the students were able to get the drone to fly to the landing zone, perform a backflip and land successfully with the following final code:
var Cylon = require('cylon');
Cylon.robot({< connection: { name: 'ardrone', adaptor: 'ardrone', port: '192.168.1.1' },
device: {name: 'drone', driver: 'ardrone'},
work: function(my) {
my.drone.takeoff();
after((7).seconds(), function(){
my.drone.front(0.1);
});
after((11).seconds(), function() {
my.drone.animate('flipBehind', 5)
});
after((13).seconds(), function() {
my.drone.land();
});
after((15).seconds(), function() {
my.drone.stop();
});
}
}).start();
http://www.youtube.com/watch?v=47vZxogZyu8&feature=youtu.be
Although the chasis fell off and we slightly overshot the target, after 2 hours, we felt like it was a success.
The use of Cylon.js made this easy and straightforward. The kids were able to pick it up and run with it and their feeling of accomplishment was shown in the cheers and “w00ts” around the hall.
Share your thoughts with @engineyard on Twitter