tello 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/telloedu +28 -0
- data/lib/tello/cli/console.rb +1 -1
- data/lib/tello/cli/server.rb +5 -3
- data/lib/tello/client.rb +30 -14
- data/lib/tello/dsl.rb +50 -6
- data/lib/tello/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ab973b7f0a89ed6d888a5a24d6a4cd7feb5192e450f626fd65ccd4a7ee94d76
|
4
|
+
data.tar.gz: 235b92463fdf1af2521eda73b8d52c418e7b78468aa27b489530e5df541bbe73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d76340288cb1a675daeb6ab6006ad77067d601c775a5cdeac8071b62508a47e5b845a94be6c16cbdaa91519a86ad949305856217bebd77110f9bfca91f297e5
|
7
|
+
data.tar.gz: 47346e4b18d8e7e5cfd6b78e36e11a9d9796e3c73b5ebd750a09b7c0cf91167de02fe3d9ebeac4482f6a495d450b220d172c0c411412fcf38256ca40ef42b6b2
|
data/bin/telloedu
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'tello/colorize'
|
3
|
+
require 'tello/version'
|
4
|
+
|
5
|
+
# Check Command-line Arguments #################################################
|
6
|
+
$edu = 'EDU'
|
7
|
+
usage = "Fly the Tello#{$edu} drone with Ruby!".bold + "\n
|
8
|
+
Usage: tello#{$edu.to_s.downcase} <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
|
data/lib/tello/cli/console.rb
CHANGED
data/lib/tello/cli/server.rb
CHANGED
@@ -9,7 +9,8 @@ server.bind('localhost', PORT)
|
|
9
9
|
|
10
10
|
puts "Starting Tello test server...".bold, "Listening on udp://localhost:#{PORT}"
|
11
11
|
|
12
|
-
|
12
|
+
bye = false
|
13
|
+
while (not bye) do
|
13
14
|
msg, addr = server.recvfrom(100)
|
14
15
|
puts "#{"==>".green} Received: \"#{msg}\", from #{addr[3]}:#{addr[1]}"
|
15
16
|
|
@@ -44,8 +45,9 @@ loop do
|
|
44
45
|
when 'wifi?'
|
45
46
|
#=> snr
|
46
47
|
res = "90\r\n"
|
47
|
-
when '
|
48
|
-
res =
|
48
|
+
when 'bye!'
|
49
|
+
res = 'good bye!'
|
50
|
+
bye = true
|
49
51
|
else
|
50
52
|
#=> 'ok' or 'error'
|
51
53
|
res = 'ok'
|
data/lib/tello/client.rb
CHANGED
@@ -8,13 +8,21 @@ module Tello
|
|
8
8
|
|
9
9
|
class << self
|
10
10
|
|
11
|
-
# Create a
|
12
|
-
def connect(ssid = nil)
|
11
|
+
# Create a UDP connection
|
12
|
+
def connect(ssid = nil, ip = nil, bind_port=8890)
|
13
13
|
|
14
14
|
# Connect to Tello wifi
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
if ssid.to_s.upcase == 'AP'
|
16
|
+
unless valid_ipv4?(ip)
|
17
|
+
puts "Error: Cannot connect to Tello#{$edu} in AP mode due to invalid IPv4: '#{ip}'"
|
18
|
+
return false
|
19
|
+
end
|
20
|
+
else
|
21
|
+
if !Tello::Wifi.connect(ssid)
|
22
|
+
puts "Error: Could not connect to Tello#{$edu} 😢"
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
ip = '192.168.10.1'
|
18
26
|
end
|
19
27
|
|
20
28
|
# If already connected, disconnect
|
@@ -23,13 +31,16 @@ module Tello
|
|
23
31
|
disconnect
|
24
32
|
end
|
25
33
|
|
34
|
+
p({ssid: ssid, ip: ip})
|
35
|
+
|
26
36
|
# Set IP and port numbers
|
27
|
-
@ip = Tello.testing ? 'localhost' :
|
37
|
+
@ip = (Tello.testing ? 'localhost' : ip)
|
28
38
|
@port = 8889
|
29
39
|
|
30
40
|
# Create UDP client, bind to a previous source IP and port if availble
|
31
41
|
@client = UDPSocket.new unless @client
|
32
42
|
if @source_ip && @source_port
|
43
|
+
p({source_ip: @source_ip, source_port: @source_port})
|
33
44
|
@client.bind(@source_ip, @source_port)
|
34
45
|
end
|
35
46
|
|
@@ -41,7 +52,7 @@ module Tello
|
|
41
52
|
# Create server to get Tello state
|
42
53
|
unless @state_server
|
43
54
|
@state_server = UDPSocket.new
|
44
|
-
@state_server.bind('0.0.0.0',
|
55
|
+
@state_server.bind('0.0.0.0', bind_port)
|
45
56
|
end
|
46
57
|
|
47
58
|
# Check to see if test server is up
|
@@ -50,8 +61,8 @@ module Tello
|
|
50
61
|
@client.send('command', 0)
|
51
62
|
sleep 0.5
|
52
63
|
unless read_nonblock
|
53
|
-
puts "\n#{'Error:'.error} Could not find Tello test server.",
|
54
|
-
|
64
|
+
puts "\n#{'Error:'.error} Could not find Tello#{$edu} test server.",
|
65
|
+
"Did you run `tello#{$edu.to_s.downcase} server` in another terminal window?"
|
55
66
|
return false
|
56
67
|
end
|
57
68
|
puts "connected!"
|
@@ -69,10 +80,10 @@ module Tello
|
|
69
80
|
begin
|
70
81
|
@client.send('command', 0)
|
71
82
|
rescue Errno::EADDRNOTAVAIL
|
72
|
-
puts "#{'Error:'.error} No response from Tello! Try reconnecting."
|
83
|
+
puts "#{'Error:'.error} No response from Tello#{$edu}! Try reconnecting."
|
73
84
|
@ping.exit
|
74
85
|
end
|
75
|
-
sleep
|
86
|
+
sleep(14.5)
|
76
87
|
end
|
77
88
|
end
|
78
89
|
|
@@ -85,7 +96,8 @@ module Tello
|
|
85
96
|
end
|
86
97
|
end
|
87
98
|
|
88
|
-
puts "Ready to fly! 🚁"
|
99
|
+
puts "Ready to fly! 🚁"
|
100
|
+
true
|
89
101
|
end
|
90
102
|
|
91
103
|
# Get Tello connection status
|
@@ -93,7 +105,7 @@ module Tello
|
|
93
105
|
if @connected
|
94
106
|
true
|
95
107
|
else
|
96
|
-
puts "Tello is not yet connected. Run `connect` first."
|
108
|
+
puts "Tello#{$edu} is not yet connected. Run `connect` first."
|
97
109
|
false
|
98
110
|
end
|
99
111
|
end
|
@@ -146,7 +158,11 @@ module Tello
|
|
146
158
|
if res then res.to_i else res end
|
147
159
|
end
|
148
160
|
|
149
|
-
|
161
|
+
def valid_ipv4?(ip)
|
162
|
+
## May be improved further
|
163
|
+
(ip.to_s) =~ /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/
|
164
|
+
end
|
150
165
|
|
166
|
+
end
|
151
167
|
end
|
152
168
|
end
|
data/lib/tello/dsl.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Tello::DSL
|
2
2
|
# Define Tello domain-specific language
|
3
|
+
require 'timeout'
|
3
4
|
|
4
5
|
module Tello
|
5
6
|
module DSL
|
7
|
+
TIMEOUT_SEC = 6 # Needs to be tweaked after more testing
|
6
8
|
|
7
9
|
# Warn Linux and Windows users to manually connect to Wi-Fi, for now
|
8
10
|
unless Tello.os == :macos
|
@@ -11,8 +13,8 @@ module Tello
|
|
11
13
|
end
|
12
14
|
|
13
15
|
# Connect to the drone
|
14
|
-
def connect
|
15
|
-
Tello::Client.connect
|
16
|
+
def connect(ssid=nil, ip=nil, bind_port=nil)
|
17
|
+
Tello::Client.connect(ssid, ip, bind_port)
|
16
18
|
end
|
17
19
|
|
18
20
|
# Is the drone connected?
|
@@ -27,7 +29,24 @@ module Tello
|
|
27
29
|
|
28
30
|
# Send a native Tello command to the drone
|
29
31
|
def send(s)
|
30
|
-
|
32
|
+
puts s
|
33
|
+
begin
|
34
|
+
### WARNING: Ruby Timeout considered harmful (according to Dr. Google)
|
35
|
+
Timeout::timeout(TIMEOUT_SEC) { Tello::Client.send(s) }
|
36
|
+
rescue
|
37
|
+
err = $!.to_s
|
38
|
+
puts err unless err == 'execution expired'
|
39
|
+
puts "timeout after #{TIMEOUT_SEC} seconds"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def ap_mode(ssid, passwd)
|
44
|
+
if ssid.to_s.strip.size == 0
|
45
|
+
puts 'Cannot set AP mode when SSID is empty'
|
46
|
+
return false
|
47
|
+
end
|
48
|
+
cmd = "ap #{ssid.to_s} #{passwd.to_s}"
|
49
|
+
send(cmd)
|
31
50
|
end
|
32
51
|
|
33
52
|
# Check if value is within the common movement range
|
@@ -36,14 +55,14 @@ module Tello
|
|
36
55
|
end
|
37
56
|
|
38
57
|
# Takeoff and land
|
39
|
-
[:takeoff, :land].each do |cmd|
|
58
|
+
[:takeoff, :land, :streamon, :streamoff].each do |cmd|
|
40
59
|
define_method cmd do
|
41
60
|
Tello::Client.return_bool send("#{cmd.to_s}")
|
42
61
|
end
|
43
62
|
end
|
44
63
|
|
45
64
|
# Move in a given direction
|
46
|
-
[:up, :down, :left, :right, :forward, :
|
65
|
+
[:up, :down, :left, :right, :forward, :back].each do |cmd|
|
47
66
|
define_method cmd do |x|
|
48
67
|
if in_move_range? x
|
49
68
|
Tello::Client.return_bool send("#{cmd.to_s} #{x}")
|
@@ -52,6 +71,8 @@ module Tello
|
|
52
71
|
end
|
53
72
|
end
|
54
73
|
end
|
74
|
+
alias_method :front, :forward
|
75
|
+
alias_method :backward, :back
|
55
76
|
|
56
77
|
# Turn clockwise or counterclockwise
|
57
78
|
[:cw, :ccw].each do |cmd|
|
@@ -189,6 +210,23 @@ module Tello
|
|
189
210
|
send('temp?')
|
190
211
|
end
|
191
212
|
|
213
|
+
def sdk
|
214
|
+
send('sdk?')
|
215
|
+
end
|
216
|
+
|
217
|
+
def sn
|
218
|
+
send('sn?')
|
219
|
+
end
|
220
|
+
|
221
|
+
def bye!
|
222
|
+
## Tell the server to exit gracefully.
|
223
|
+
## Only applicable in test mode.
|
224
|
+
if Tello.testing
|
225
|
+
send('bye!')
|
226
|
+
exit(0) if connected?
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
192
230
|
# Get Wi-Fi signal-to-noise ratio (SNR); if parameters, set SSID and password
|
193
231
|
def wifi(ssid: nil, pass: nil)
|
194
232
|
if ssid && pass
|
@@ -198,8 +236,14 @@ module Tello
|
|
198
236
|
end
|
199
237
|
end
|
200
238
|
|
201
|
-
#
|
239
|
+
# stop: hovers in the air per Tello SDK 2.0 User Guide
|
202
240
|
def stop
|
241
|
+
Tello::Client.return send('stop')
|
242
|
+
end
|
243
|
+
alias_method :hover, :stop
|
244
|
+
|
245
|
+
# Halt all motors immediately
|
246
|
+
def halt
|
203
247
|
Tello::Client.return_bool send('emergency')
|
204
248
|
end
|
205
249
|
|
data/lib/tello/version.rb
CHANGED
metadata
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tello
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Black
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Fly the Tello drone with Ruby!
|
14
14
|
email: tom@blacktm.com
|
15
15
|
executables:
|
16
16
|
- tello
|
17
|
+
- telloedu
|
17
18
|
extensions: []
|
18
19
|
extra_rdoc_files: []
|
19
20
|
files:
|
20
21
|
- bin/tello
|
22
|
+
- bin/telloedu
|
21
23
|
- lib/tello.rb
|
22
24
|
- lib/tello/cli/console.rb
|
23
25
|
- lib/tello/cli/server.rb
|
@@ -32,7 +34,7 @@ homepage: https://github.com/blacktm/tello
|
|
32
34
|
licenses:
|
33
35
|
- MIT
|
34
36
|
metadata: {}
|
35
|
-
post_install_message:
|
37
|
+
post_install_message:
|
36
38
|
rdoc_options: []
|
37
39
|
require_paths:
|
38
40
|
- lib
|
@@ -47,9 +49,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
49
|
- !ruby/object:Gem::Version
|
48
50
|
version: '0'
|
49
51
|
requirements: []
|
50
|
-
|
51
|
-
|
52
|
-
signing_key:
|
52
|
+
rubygems_version: 3.2.32
|
53
|
+
signing_key:
|
53
54
|
specification_version: 4
|
54
55
|
summary: Tello
|
55
56
|
test_files: []
|