Tello drone programming (part2)
Hi, Nice to see you again, if you didn't read the previous tutorial, you are not going to miss any essential points. I just explained some fundamentals.
let's install DjiTelloPy :
pip3 install djitellopy
Then we can use DjiTelloPy
write your code like this:
- In the first line of your code, you need to import the library.
from djitellopy import Tello
- Then define a Drone object using :
tello = Tello()
- use the connect method to initiate Tello’s SDK mode and use the “takeoff” method for safe takeoff
it's all done! now Drone is ready to receive your commands.tello.connect() tello.takeoff()
Tello commands list :
control commands(returns ok or error) :
drone.takeoff()#Tello auto take-off
drone.land()#Tello auto land
drone.streamon()#Set video stream on
drone.streamoff()#Set video stream off
drone.emergency()#Stop all motors immediately
drone.move_up()#fly up with distance x cm (20<x<500)
drone.move_down()#fly down with distance x cm (20<x<500)
drone.move_left()#fly left with distance x cm (20<x<500)
drone.move_right()#fly right with distance x cm (20<x<500)
drone.move_forward()#fly forward with distance x cm (20<x<500)
drone.move_back()#fly back with distance x cm (20<x<500)
drone.rotate_clockwise()#rotate x degree clockwise (1<x<3600)
drone.rotate_counter_clockwise()#rotate x degree counterclockwise ( 1<x<3600)
drone.flip(x)#fly flip x (l=left)(r=right)(f=forward)(b=back)
drone.go_xyz_speed(x: int, y: int, z: int, speed: int)#fly to (x y z) in speed (cm/s) x: 20–500 y: 20–500 z: 20–500 speed: 10–100
drone.curve_xyz_speed() →
#Arguments:
#x1: -500–500
#x2: -500–500
#y1: -500–500
#y2: -500–500
#z1: -500–500
#z2: -500–500
#speed: 10–60
set commands(returns ok or error) :
drone.set_speed()#set speed to x cm/s.(10<x<100)
drone.send_rc_control( left_right_velocity, forward_backward_velocity,up_down_velocity,
yaw_velocity) #(-100<velocity<100)
drone.set_wifi_credentials(SSID,password)#Set the Wi-Fi SSID and password. The Tello will reboot afterward
read commands :
drone.get_speed_x()#Returns X axis speed in integer
drone.get_speed_y()#Returns Y axis speed in integer
drone.get_speed_z()#Returns Z axis speed in integer
drone.get_battery()#Returns current battery percentage
drone.get_flight_time()#Returns flight time in s
drone.get_height()#Returns current height in cm
drone.get_temperature()#Returns average temperature in Celsius
drone.query_attitude()#Returns Query IMU attitude data in {pitch, roll,yaw} format
drone.query_barometer()#Returns barometer value in cm (0–100)
drone.get_acceleration_x()#Returns X Axis Acceleration in float
drone.get_acceleration_y()#Returns Y Axis Acceleration in float
drone.get_acceleration_z()#Returns Z Axis Acceleration in float
drone.get_distance_tof()#Returns current distance value from TOF in cm
drone.query_wifi_signal_noise_ratio()#Returns Wi-Fi SNR
Tello state:
if you read the previous tutorial, I told you about an optional part, creating a UDP server on your system and listening to the message from IP 0.0.0.0 via UDP PORT 8890.
if you have done this, you will receive messages in string format like :
“pitch:%d;roll:%d;yaw:%d;vgx:%d;vgy%d;vgz:%d;templ:%d;temph:%d;tof:%d;h:%d;bat:%d;baro: %.2f; time:%d;agx:%.2f;agy:%.2f;agz:%.2f;\r\n”
pitch → Attitude pitch in degree
roll → Attitude roll in degree
yaw → Attitude yaw in degree
vgx → Speed x in cm/s
vgy → Speed y in cm
vgz → Speed z
templ →Lowest temperature in celsius
temph → Highest temperature in celsius
tof → TOF distance in cm
h → Height in cm
bat → Current battery percentage(0<x<100)
baro → Barometer measurement in cm
time → Motors on time in sec
agx → Acceleration in the X-axis
agy → Acceleration in the Y-axis
agz → Acceleration in the Z-axis
SAFETY FEATURE :
be aware: If Tello does not receive any command input for 15 seconds, it will land automatically, you can use drone.send_keepalive()
to prevent the drone from landing after 15s
How to reset tello wifi:
- Turn on Tello
- The indicator light should flash yellow
- Long press power key for 5 seconds
- the indicator light will turn off and then flash yellow
- Wi-Fi SSID and password will be reset to the factory settings
- there is no password by default
end:
thanks for your time, I appreciate it, if you have any questions, fill free to ask me, I'm here for you, you can send me an email or find my socials on my Github profile, goodbye, peace ❤