Skip to content

Commit 4876947

Browse files
committed
Initial implementation
1 parent 571b06c commit 4876947

15 files changed

+960
-6
lines changed

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2018 Tom Black ([blacktm.com](http://www.blacktm.com))
3+
Copyright © 2018 Tom Black ([blacktm.com](http://www.blacktm.com))
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

README.md

+231-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,232 @@
1-
# Tello Ruby gem
1+
# Fly Tello with Ruby!
22

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. 🎉

Rakefile

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require_relative 'lib/tello/colorize'
2+
require_relative 'lib/tello/version'
3+
4+
# Helpers
5+
6+
def print_task(task)
7+
print "\n", "==> ".blue, task.bold, "\n\n"
8+
end
9+
10+
def run_cmd(cmd)
11+
puts "==> #{cmd}\n"
12+
system cmd
13+
end
14+
15+
# Tasks
16+
17+
task default: 'all'
18+
19+
desc "Uninstall gem"
20+
task :uninstall do
21+
print_task "Uninstalling"
22+
run_cmd "gem uninstall tello --executables"
23+
end
24+
25+
desc "Build gem"
26+
task :build do
27+
print_task "Building"
28+
run_cmd "gem build tello.gemspec --verbose"
29+
end
30+
31+
desc "Install gem"
32+
task :install do
33+
print_task "Installing"
34+
run_cmd "gem install tello-#{Tello::VERSION}.gem --local --verbose"
35+
end
36+
37+
desc "Uninstall, build, install, and test"
38+
task :all do
39+
Rake::Task['uninstall'].invoke
40+
Rake::Task['build'].invoke
41+
Rake::Task['install'].invoke
42+
end

bin/tello

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env ruby
2+
require 'tello/colorize'
3+
require 'tello/version'
4+
5+
# Check Command-line Arguments #################################################
6+
7+
usage = "Fly the Tello drone with Ruby!".bold + "\n
8+
Usage: tello <command> <options>
9+
[-v|--version]
10+
11+
Summary of commands and options:
12+
console Open an interactive Tello console
13+
--test Start the console in test mode
14+
server Start the test server
15+
-v|--version Prints the installed version\n\n"
16+
17+
if ARGV.delete '--test' then $tello_testing = true end
18+
19+
case ARGV[0]
20+
when 'console'
21+
require 'tello/cli/console'
22+
when 'server'
23+
require 'tello/cli/server'
24+
when '-v', '--version'
25+
puts Tello::VERSION
26+
else
27+
puts usage
28+
end

lib/tello.rb

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Tello module and requires
2+
3+
module Tello
4+
# Flag for testing
5+
attr_accessor :testing, :os, :ip, :port
6+
7+
def self.testing; @testing end
8+
def self.testing=(t); @testing=(t) end
9+
def self.os; @os end
10+
11+
# Set the operating system
12+
case RUBY_PLATFORM
13+
when /darwin/
14+
@os = :macos
15+
when /linux/
16+
@os = :linux
17+
when /mingw/
18+
@os = :windows
19+
end
20+
end
21+
22+
require 'tello/colorize'
23+
require 'tello/state'
24+
require 'tello/wifi'
25+
require 'tello/client'
26+
require 'tello/dsl'
27+
28+
# Add DSL
29+
extend Tello::DSL

lib/tello/cli/console.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env ruby
2+
3+
if $tello_testing
4+
puts "⚠️ Test mode enabled"
5+
r_module = 'tello/cli/testing'
6+
else
7+
r_module = 'tello'
8+
end
9+
10+
puts "Ready to receive Tello commands. Type \"exit\" to quit."
11+
12+
if system('pry -v &>/dev/null')
13+
system("pry -r #{r_module}")
14+
else
15+
system("irb -r #{r_module}")
16+
end

0 commit comments

Comments
 (0)