2013-11-29 04:34:15 +08:00
|
|
|
# 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:
|
|
|
|
|
2014-03-27 08:06:26 +08:00
|
|
|
var Cylon = require('../..');
|
2013-11-29 04:34:15 +08:00
|
|
|
|
|
|
|
Now that we've got that set up, we can start defining our robot:
|
|
|
|
|
2014-03-27 08:06:26 +08:00
|
|
|
Cylon.robot({
|
2013-11-29 04:34:15 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2014-11-26 08:01:31 +08:00
|
|
|
connections: {
|
|
|
|
crazyflie: { adaptor: 'crazyflie', port: "radio://1/10/250KPS" }
|
2014-03-27 08:06:26 +08:00
|
|
|
},
|
2013-11-29 04:34:15 +08:00
|
|
|
|
2014-11-26 08:01:31 +08:00
|
|
|
devices: {
|
|
|
|
drone: { driver: 'crazyflie' }
|
2014-12-14 08:19:25 +08:00
|
|
|
},
|
2013-11-29 04:34:15 +08:00
|
|
|
|
|
|
|
With the parts in place, we can start defining our robot's work.
|
|
|
|
|
2014-03-27 08:06:26 +08:00
|
|
|
work: function(my) {
|
2013-11-29 04:34:15 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2014-03-27 08:06:26 +08:00
|
|
|
my.drone.on('start', function() {
|
2013-11-29 04:34:15 +08:00
|
|
|
my.drone.takeoff()
|
2014-03-27 08:06:26 +08:00
|
|
|
after((10).seconds(), my.drone.land);
|
|
|
|
after((15).seconds(), my.drone.stop);
|
|
|
|
});
|
|
|
|
}
|
2013-11-29 04:34:15 +08:00
|
|
|
|
|
|
|
With all that done, we can start up the robot and get the Crazyflie flying:
|
|
|
|
|
2014-03-27 08:06:26 +08:00
|
|
|
}).start();
|