Hands-On: Flying Drones with Scratch

May 22, 2018 0 Comments

Hands-On: Flying Drones with Scratch

 

 

I’ll admit it. I have a lot of drones. Sitting at my desk I can count no fewer than ten in various states of flight readiness. There are probably another half dozen in the garage. Some of them cost almost nothing. Some cost the better part of a thousand bucks. But I recently bought a drone for $100 that is both technically interesting and has great potential for motivating kids to learn about programming. The Tello is a small drone from a company you’ve never heard of (Ryze Tech), but it has DJI flight technology onboard and you can program it via an API. What’s more exciting for someone learning to program than using it to fly a quadcopter?

For $100, the Tello drone is a great little flyer. I’d go as far as saying it is the best $100 drone I’ve ever seen. Normally I don’t suggest getting a drone with no GPS since the price on those has come down. But the Tello optical sensor does a great job of keeping the craft stable as long as there is enough light for it to see. In addition, the optical sensor works indoors unlike GPS.

But if that was all there was to it, it probably wouldn’t warrant a Hackaday post. What piqued my interest was that you can program the thing using a PC. In particular, they use Scratch — the language built at MIT for young students. However, the API is usable from other languages with some work.

Information about the programming environment is rather sparse, so I dug in to find out how it all worked.

Programming Setup

As with a lot of hardware programming tasks, setting up the toolchain is the most frustrating part. You need to use the offline version of Scratch which requires Adobe Air. I had trouble getting this to work on a Linux system so I  finally gave up and installed it on a Windows laptop.

Scratch, though, is just part of it. You also need to install nodejs and a few files from Ryze Tech (PDF). The Ryze files are installed via a hidden menu command accessed by holding shift while clicking “File”. You are then greeted with the “Import Experimental HTTP Extension,” option. Once this is complete you’ll wind up with some blocks in the “More Blocks” category shown here. Tello acts as a WiFi access point and control is established when you connect to it with your computer and run the nodejs server from the command prompt.

There is API documentation (PDF) available if you’d like to look under the hood. From reading the API documentation, I learned the move units are in centimeters and some have minimums as well as maximums. The blocks will let you set any value you want, though. It just won’t have the desired effect.

A Simple Program

I put together a quick little Scratch program. It just runs a simple pattern and adds some sound effects (from the PC, not the drone). I immediately discovered a gotcha.

The blocks simply issue commands, but there is no feedback. For example, if you send a fly forward command followed by a rotate command, the rotate command will fall on deaf ears. You must give the drone time to execute each command. From Scratch, I didn’t see a way to wait for the response, so you simply have to guess how long something is going to take.

You can probably puzzle most of this out. The top block tells the program to start when you press the Go flag (part of the Scratch environment). The purple launch and landing sounds are just recordings located on the computer. The gold boxes are all for control.

Talking through this program: the drone takes off, moves forward in 3 spurts, rotates 180 degrees, then moves forward in 4 spurts. Then it backs up the last spurt and lands.

Fly blocks have a minimum distance of 20 cm. In my program, I set a “fly up” block to 10 to test this. The drone won’t respond to this block unless you change that to at least 20. If you find your commands are not being executed, it may be worth reading the API documentation I mentioned before to see if you are within the minimum and maximum ranges for each block.

How’s it Work?

It works. This drone uses an optical sensor for position awareness. This is not GPS, it’s more like how an optical mouse sensor works. You can see the optical sensors on the underside of the Tello as the drone files over the New York skyline (sort of) in the picture to the left.

If you don’t have a lot of light for the optical sensors, all bets are off. But if you do, it works pretty well. The rotation seems spot on. There was a little drifting around, so the takeoff and landing were not always exactly in the same spot, but it was close.

So it did work. I’m not sure it would be ideal for a beginner since the set up is frustrating and the lack of feedback can be confusing. For exciting kids about programming, you’d be better served with Lego Mindstorms or some similar offering.

For those that do have experience with coding, you may want to investigate the non-Scratch bindings. There are other bindings to the API, like programming Tello using Go which we covered last month. And there’s also the secret API the official applications use, which has been decoded by a community effort.

For $100, even if you don’t care about programming them these drones are great little fliers. Add a $30 Bluetooth controller and they get better (the Bluetooth connects to your phone, not the drone). When they start getting discounted for half the price they’ll be no-brainers.


Tag cloud