Module: Tello::DSL
- Defined in:
- lib/tello/dsl.rb
Constant Summary collapse
- TIMEOUT_SEC =
Needs to be tweaked after more testing
6
Instance Method Summary collapse
-
#acceleration ⇒ Object
Get IMU angular acceleration data.
- #ap_mode(ssid, passwd) ⇒ Object
-
#attitude ⇒ Object
Get IMU attitude data.
-
#baro ⇒ Object
Get barometer value.
-
#battery ⇒ Object
Get the battery level.
- #bye! ⇒ Object
-
#connect(ssid = nil, ip = nil, bind_port = nil) ⇒ Object
Connect to the drone.
-
#connected? ⇒ Boolean
Is the drone connected?.
-
#curve(x1, y1, z1, x2, y2, z2, speed = 10) ⇒ Object
Fly in a curve; If arc radius is not within 0.5..10 m, command responds false.
-
#disconnect ⇒ Object
Disconnect the drone.
-
#flip(f) ⇒ Object
Flip in a given direction.
-
#go(x, y, z, speed = 10) ⇒ Object
Fly to a location in x/y/z coordinates and provided speed.
-
#halt ⇒ Object
Halt all motors immediately.
-
#height ⇒ Object
Get the height of the drone.
-
#in_move_range?(v) ⇒ Boolean
Check if value is within the common movement range.
-
#rc(a, b, c, d) ⇒ Object
Send RC control via four channels: a: left/right, b: forward/backward, c: up/down, d: yaw.
- #sdk ⇒ Object
-
#send(s) ⇒ Object
Send a native Tello command to the drone.
- #sn ⇒ Object
-
#speed(s = nil) ⇒ Object
Get or set the flight speed.
-
#stop ⇒ Object
(also: #hover)
stop: hovers in the air per Tello SDK 2.0 User Guide.
-
#temp ⇒ Object
Get the temperature of the drone.
-
#time ⇒ Object
Get the flight time.
-
#tof ⇒ Object
Get distance value from TOF.
-
#wifi(ssid: nil, pass: nil) ⇒ Object
Get Wi-Fi signal-to-noise ratio (SNR); if parameters, set SSID and password.
Instance Method Details
#acceleration ⇒ Object
Get IMU angular acceleration data
183 184 185 |
# File 'lib/tello/dsl.rb', line 183 def acceleration send('acceleration?') end |
#ap_mode(ssid, passwd) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/tello/dsl.rb', line 43 def ap_mode(ssid, passwd) if ssid.to_s.strip.size == 0 puts 'Cannot set AP mode when SSID is empty' return false end cmd = "ap #{ssid.to_s} #{passwd.to_s}" send(cmd) end |
#attitude ⇒ Object
Get IMU attitude data
178 179 180 |
# File 'lib/tello/dsl.rb', line 178 def attitude send('attitude?') end |
#baro ⇒ Object
Get barometer value
188 189 190 |
# File 'lib/tello/dsl.rb', line 188 def Tello::Client.return_num send('baro?') end |
#battery ⇒ Object
Get the battery level
203 204 205 206 |
# File 'lib/tello/dsl.rb', line 203 def battery b = send('battery?') b == false ? false : Tello::Client.return_num(b) end |
#bye! ⇒ Object
221 222 223 224 225 226 227 228 |
# File 'lib/tello/dsl.rb', line 221 def bye! ## Tell the server to exit gracefully. ## Only applicable in test mode. if Tello.testing send('bye!') exit(0) if connected? end end |
#connect(ssid = nil, ip = nil, bind_port = nil) ⇒ Object
Connect to the drone
16 17 18 |
# File 'lib/tello/dsl.rb', line 16 def connect(ssid=nil, ip=nil, bind_port=nil) Tello::Client.connect(ssid, ip, bind_port) end |
#connected? ⇒ Boolean
Is the drone connected?
21 22 23 |
# File 'lib/tello/dsl.rb', line 21 def connected? Tello::Client.connected? end |
#curve(x1, y1, z1, x2, y2, z2, speed = 10) ⇒ Object
Fly in a curve; If arc radius is not within 0.5..10 m, command responds false
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/tello/dsl.rb', line 138 def curve(x1, y1, z1, x2, y2, z2, speed = 10) # Check if coordinates are in range # TODO: x/y/z can't be between -20..20 at the same time unless in_move_range?(x1) && in_move_range?(y1) && in_move_range?(z1) && in_move_range?(x2) && in_move_range?(y2) && in_move_range?(z2) puts "x/y/z coordinates must be between 20..500 cm" return false end # Check if speed is in range unless (10..60).include? speed puts "Speed must be between 10..60 cm/s" return false end Tello::Client.return_bool send("curve #{x1} #{y1} #{z1} #{x2} #{y2} #{z2} #{speed}") end |
#disconnect ⇒ Object
Disconnect the drone
26 27 28 |
# File 'lib/tello/dsl.rb', line 26 def disconnect Tello::Client.disconnect end |
#flip(f) ⇒ Object
Flip in a given direction
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/tello/dsl.rb', line 89 def flip(f) case f when :left, :l Tello::Client.return_bool send('flip l') when :right, :r Tello::Client.return_bool send('flip r') when :forward, :f Tello::Client.return_bool send('flip f') when :backward, :b Tello::Client.return_bool send('flip b') else puts "Not a valid direction to flip" false end end |
#go(x, y, z, speed = 10) ⇒ Object
Fly to a location in x/y/z coordinates and provided speed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/tello/dsl.rb', line 120 def go(x, y, z, speed = 10) # Check if coordinates are in range unless in_move_range?(x) && in_move_range?(y) && in_move_range?(z) puts "x/y/z coordinates must be between 20..500 cm" return false end # Check if speed is in range unless (10..100).include? speed puts "Speed must be between 10..100 cm/s" return false end Tello::Client.return_bool send("go #{x} #{y} #{z} #{speed}") end |
#halt ⇒ Object
Halt all motors immediately
246 247 248 |
# File 'lib/tello/dsl.rb', line 246 def halt Tello::Client.return_bool send('emergency') end |
#height ⇒ Object
Get the height of the drone
173 174 175 |
# File 'lib/tello/dsl.rb', line 173 def height Tello::Client.return_num send('height?') end |
#in_move_range?(v) ⇒ Boolean
Check if value is within the common movement range
53 54 55 |
# File 'lib/tello/dsl.rb', line 53 def in_move_range?(v) (20..500).include? v end |
#rc(a, b, c, d) ⇒ Object
Send RC control via four channels:
a: left/right, b: forward/backward, c: up/down, d: yaw
159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/tello/dsl.rb', line 159 def rc(a, b, c, d) # Check if channel values are in range [a, b, c, d].each do |v| unless (-100..100).include? v puts "RC channel values must be between -100..100" return false end end Tello::Client.return_bool send("rc #{a} #{b} #{c} #{d}") end |
#sdk ⇒ Object
213 214 215 |
# File 'lib/tello/dsl.rb', line 213 def sdk send('sdk?') end |
#send(s) ⇒ Object
Send a native Tello command to the drone
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tello/dsl.rb', line 31 def send(s) puts s begin ### WARNING: Ruby Timeout considered harmful (according to Dr. Google) Timeout::timeout(TIMEOUT_SEC) { Tello::Client.send(s) } rescue err = $!.to_s puts err unless err == 'execution expired' puts "timeout after #{TIMEOUT_SEC} seconds" end end |
#sn ⇒ Object
217 218 219 |
# File 'lib/tello/dsl.rb', line 217 def sn send('sn?') end |
#speed(s = nil) ⇒ Object
Get or set the flight speed
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/tello/dsl.rb', line 106 def speed(s = nil) if s if (10..100).include? s Tello::Client.return_bool send("speed #{s}") else puts "Speed must be between 10..100 cm/s" end else s = send('speed?') s == false ? false : s.to_f end end |
#stop ⇒ Object Also known as: hover
stop: hovers in the air per Tello SDK 2.0 User Guide
240 241 242 |
# File 'lib/tello/dsl.rb', line 240 def stop Tello::Client.return send('stop') end |
#temp ⇒ Object
Get the temperature of the drone
209 210 211 |
# File 'lib/tello/dsl.rb', line 209 def temp send('temp?') end |
#time ⇒ Object
Get the flight time
198 199 200 |
# File 'lib/tello/dsl.rb', line 198 def time Tello::Client.return_num send('time?') end |
#tof ⇒ Object
Get distance value from TOF
193 194 195 |
# File 'lib/tello/dsl.rb', line 193 def tof Tello::Client.return_num send('tof?') end |
#wifi(ssid: nil, pass: nil) ⇒ Object
Get Wi-Fi signal-to-noise ratio (SNR); if parameters, set SSID and password
231 232 233 234 235 236 237 |
# File 'lib/tello/dsl.rb', line 231 def wifi(ssid: nil, pass: nil) if ssid && pass Tello::Client.return_bool send("wifi #{ssid} #{pass}") else Tello::Client.return_num send('wifi?') end end |