|
1 |
| -# Tello Ruby gem |
| 1 | +# Fly Tello with Ruby! |
2 | 2 |
|
3 |
| -🚧 In development 🚧 |
| 3 | +This gem will let you fly the [Tello drone](https://www.ryzerobotics.com/tello) using Ruby. |
| 4 | + |
| 5 | +## Your first flight |
| 6 | + |
| 7 | +If you don't already have one, get a Tello drone! A [number of retailers](https://www.ryzerobotics.com/where-to-buy) carry them for $99 USD. (You _can_ also use the [test server](#test-server) packaged with this gem to simulate commands, but that's not nearly as fun.) |
| 8 | + |
| 9 | +Install the Ruby gem: |
| 10 | + |
| 11 | +``` |
| 12 | +$ gem install tello |
| 13 | +``` |
| 14 | + |
| 15 | +The gem comes with a command-line utility, also named `tello`. We can use it to launch an interactive console (IRB, or [Pry](http://pryrepl.org) if installed) and send commands to the drone. Go ahead and start the console: |
| 16 | + |
| 17 | +``` |
| 18 | +$ tello console |
| 19 | +``` |
| 20 | + |
| 21 | +Now, set the drone on the ground clear of any objects (including yourself) and press the button to turn it on. Wait for it to boot up, until the status light is blinking yellow. |
| 22 | + |
| 23 | +**Linux and Windows users:** Connect to the drone's Wi-Fi manually (the network name should start with `TELLO-`). For macOS users, this will happen automatically with the next command. |
| 24 | + |
| 25 | +In your interactive console, connect to the drone like so (the `>` here is just to note it's a Ruby prompt — don't type that): |
| 26 | + |
| 27 | +```ruby |
| 28 | +> connect |
| 29 | +``` |
| 30 | + |
| 31 | +If you've successfully connected to the drone, you should see a "ready to fly" message. You're now ready to take flight! |
| 32 | + |
| 33 | +```ruby |
| 34 | +> takeoff |
| 35 | +``` |
| 36 | + |
| 37 | +The drone should now be hovering. At this point, you can run all sorts of flight commands, described in the next section. Before we learn about all of them, let's have some fun. Stand clear of the drone and do a back flip: |
| 38 | + |
| 39 | +```ruby |
| 40 | +> flip :backward |
| 41 | +``` |
| 42 | + |
| 43 | +Nice! For now, let's land the drone and learn about what else it can do. |
| 44 | + |
| 45 | +```ruby |
| 46 | +> land |
| 47 | +``` |
| 48 | + |
| 49 | +## Flight commands |
| 50 | + |
| 51 | +This gem comes packed with commands you can send to the Tello drone. Let's go through each one. |
| 52 | + |
| 53 | +### `connect` |
| 54 | + |
| 55 | +The first command you'll run is `connect`. This will establish a network connection to the drone and prepare it for further commands. If already connected, `connect` will try to re-establish a connection (helpful for troubleshooting). If you need to, you can also use the `disconnect` command to break the connection. |
| 56 | + |
| 57 | +### `takeoff` |
| 58 | + |
| 59 | +Use this command to take flight! The drone will soon hover in place. |
| 60 | + |
| 61 | +### `land` |
| 62 | + |
| 63 | +Slowly descend to the ground and stop all rotors. |
| 64 | + |
| 65 | +### `stop` |
| 66 | + |
| 67 | +Immediately stop all rotors. This is like the "kill switch" for the drone, useful in emergencies. Be careful: the drone will fall from the sky and could get damaged. |
| 68 | + |
| 69 | +### `up`, `down`, `left`, `right`, `forward`, `backward` |
| 70 | + |
| 71 | +These are essential movement commands. Each one takes the distance the drone should move as a parameter, from 20 to 500 cm, for example: |
| 72 | + |
| 73 | +```ruby |
| 74 | +up 50 # ascend 50 cm |
| 75 | +down 100 # descend 1 meter |
| 76 | +left 250 # fly to the left 250 cm |
| 77 | +right 75 # fly to the right 75 cm |
| 78 | +forward 500 # fly forwards 5 m |
| 79 | +backward 200 # fly backwards 2 m |
| 80 | +``` |
| 81 | + |
| 82 | +### `cw`, `ccw` |
| 83 | + |
| 84 | +These commands rotate the drone clockwise or counterclockwise, from 1 to 3600 degrees, for example: |
| 85 | + |
| 86 | +```ruby |
| 87 | +cw 90 # turn toward the right |
| 88 | +cw 360 # turn toward the right in a full circle |
| 89 | +ccw 180 # turn toward the left, facing in the opposite direction |
| 90 | +ccw 3600 # spin around 10 times |
| 91 | +``` |
| 92 | + |
| 93 | +### `flip` |
| 94 | + |
| 95 | +Make the drone do a flip in a given direction, for example: |
| 96 | + |
| 97 | +```ruby |
| 98 | +flip :left |
| 99 | +flip :right |
| 100 | +flip :forward |
| 101 | +flip :backward |
| 102 | + |
| 103 | +# Or use this shorthand for the direction |
| 104 | +flip :l |
| 105 | +flip :r |
| 106 | +flip :f |
| 107 | +flip :b |
| 108 | +``` |
| 109 | + |
| 110 | +### `speed` |
| 111 | + |
| 112 | +Get or set the speed of the drone, in cm/s (centimeters per second). Without parameters, it will simply return the speed. To set the speed used during movement commands, provide a value from 10 to 100 as a parameter, for example: |
| 113 | + |
| 114 | +```ruby |
| 115 | +speed # get the current speed in cm/s |
| 116 | +speed 75 # set the drone speed to 75 cm/s |
| 117 | + |
| 118 | +speed 100 # set speed to 1 m/s |
| 119 | +forward 300 # fly forwards 3 meters in 3 seconds |
| 120 | +``` |
| 121 | + |
| 122 | +### `go` |
| 123 | + |
| 124 | +The drone can also be given a precise location to move, based on a 3D coordinate system. The `go` command tells the drone to move to an _x, y, z_ position at a given speed. The coordinate values must be between 20 and 500 cm, while the speed must be between 10 and 100 cm/s, for example: |
| 125 | + |
| 126 | +```ruby |
| 127 | +# Parameters: x, y, z, speed |
| 128 | +go 100, 200, 50, 10 |
| 129 | +``` |
| 130 | + |
| 131 | +### `curve` |
| 132 | + |
| 133 | +Fly in a curve, where the coordinates are between 20 and 500 cm, and speed is between 10 and 100 cm/s, for example: |
| 134 | + |
| 135 | +```ruby |
| 136 | +# Parameters: x1, y1, z1, x2, y2, z2, speed |
| 137 | +curve 50, 100, 100, 25, 50, 75, 25 |
| 138 | +``` |
| 139 | + |
| 140 | +### `rc` |
| 141 | + |
| 142 | +Send remote controller values via four channels, each between -100 and 100, for example: |
| 143 | + |
| 144 | +```ruby |
| 145 | +# Parameters: left/right, forward/backward, up/down, yaw |
| 146 | +rc 0, 50, -25, 100 |
| 147 | +``` |
| 148 | + |
| 149 | +### `height` |
| 150 | + |
| 151 | +Get the height of the drone in cm. |
| 152 | + |
| 153 | +### `attitude` |
| 154 | + |
| 155 | +Get the [inertial measurement unit (IMU)](https://en.wikipedia.org/wiki/Inertial_measurement_unit) attitude data. Example response: `"pitch:-8;roll:3;yaw:2;"` |
| 156 | + |
| 157 | +### `acceleration` |
| 158 | + |
| 159 | +Get the IMU angular acceleration data. Example response: `"agx:-138.00;agy:-51.00;agz:-989.00;"` |
| 160 | + |
| 161 | +### `baro` |
| 162 | + |
| 163 | +Get the barometer value. |
| 164 | + |
| 165 | +### `tof` |
| 166 | + |
| 167 | +Get the distance from the [time-of-flight (TOF) camera](https://en.wikipedia.org/wiki/Time-of-flight_camera). |
| 168 | + |
| 169 | +### `time` |
| 170 | + |
| 171 | +Get the flight time. |
| 172 | + |
| 173 | +### `battery` |
| 174 | + |
| 175 | +Get the battery level. |
| 176 | + |
| 177 | +### `temp` |
| 178 | + |
| 179 | +Get the temperature range of the drone in celsius. |
| 180 | + |
| 181 | +### `wifi` |
| 182 | + |
| 183 | +Get the Wi-Fi signal-to-noise ratio (SNR). Provide parameters to set the SSID and password, for example: |
| 184 | + |
| 185 | +```ruby |
| 186 | +# Get the SNR |
| 187 | +wifi |
| 188 | + |
| 189 | +# Set the SSID with password |
| 190 | +wifi ssid: 'my-drone', pass: '12345' |
| 191 | +``` |
| 192 | + |
| 193 | +### `state` |
| 194 | + |
| 195 | +Get the state of the entire drone represented as a hash. Select a specific value by using one of the following keys: `:pitch`, `:roll`, `:yaw`, `:vgx`, `:vgy`, `:vgz`, `:templ`, `:temph`, `:tof`, `:h`, `:bat`, `:baro`, `:time`, `:agx`, `:agy`, `:agz` |
| 196 | + |
| 197 | +### `send` |
| 198 | + |
| 199 | +Finally, you can send raw command strings to the Tello drone (this is what we use internally for all the commands above). Refer to the [Tello SDK documentation](https://www.ryzerobotics.com/tello/downloads) for a listing of available commands. For example: |
| 200 | + |
| 201 | +```ruby |
| 202 | +send 'command' |
| 203 | +send 'height?' |
| 204 | +send 'up 50' |
| 205 | +``` |
| 206 | + |
| 207 | +## Test server |
| 208 | + |
| 209 | +You can simulate a connection to a Tello by running a test server at the command line, like so: |
| 210 | + |
| 211 | +``` |
| 212 | +$ tello server |
| 213 | +``` |
| 214 | + |
| 215 | +Then, open a new terminal window and run: |
| 216 | + |
| 217 | +``` |
| 218 | +$ tello console --test |
| 219 | +``` |
| 220 | + |
| 221 | +Now, run Tello commands just like you would when connected to a real drone. |
| 222 | + |
| 223 | +## Gem development |
| 224 | + |
| 225 | +Run `rake` to build this gem and install locally. |
| 226 | + |
| 227 | +To release a new version: |
| 228 | + |
| 229 | +1. Update the version number in [`version.rb`](lib/tello/version.rb), commit changes |
| 230 | +2. Create a [new release](https://github.com/blacktm/tello/releases) in GitHub, with tag in the form `v#.#.#` |
| 231 | +3. Run `rake` to build the gem, then push it to [rubygems.org](https://rubygems.org) with `gem push tello-#.#.#.gem` |
| 232 | +4. 🎉 |
0 commit comments