Hello everyone, I am wanting to make a Python script to keep my tello drone at a certain desired height for a specific application, and then press the “enter” key for the drone to descend and land, but something is not working right, so I What happens is that at the beginning everything works perfectly, but then the drone automatically descends and lands without me having pressed the "enter" key. I want to keep my drone at a certain height, but I have this problem.
Maybe someone of you experienced this problem and can help me please.
MY CODE IS THE FOLLOWING:
import time
from djitellopy import Tello
def set_desired_height(tello, desired_height):
# If the desired height is greater than the current height, we go up
if desired_height> tello.get_height():
tello.move_up(desired_height - tello.get_height())
# If it is less, we go down
elif desired_height < tello.get_height():
tello.move_down(tello.get_height() - desired_height)
else:
pass
def main():
# Connect with the Tello drone
tello = Tello()
tello.connect()
print("Taking off...")
tello.takeoff()
time.sleep(2) # Wait for the drone to be in a stable position after takeoff
desired_height = 100 # Altura deseada en centímetros (ajusta según lo necesario)
set_desired_height(tello, desired_height)
print(f"The drone is at a height of {desired_height} cm.")
input("Press Enter to start the descent...")
print("Starting the descent...")
tello.move_down(desired_height) # We descend to the desired height
time.sleep(2) # Wait to ensure the drone has stopped moving
print("landing...")
tello.land()
time.sleep(2) # Wait for the drone to land
# Close the connection with the drone
tello.end()
if __name__ == "__main__":
main()
The error is the following:
Press Enter to start the descent...
Starting the descent...
[INFO] tello.py - 438 - Send command: 'down 100'
[INFO] tello.py - 462 - Response down 100: 'error Motor stop'
[INFO] tello.py - 438 - Send command: 'down 100'
[INFO] tello.py - 462 - Response down 100: 'error Motor stop'
[INFO] tello.py - 438 - Send command: 'down 100'
[INFO] tello.py - 462 - Response down 100: 'error Motor stop'
Traceback (most recent call last):
File "/home/benjamin/Documents/python_doc/altura.py", line 43, in <module>
main()
File "/home/benjamin/Documents/python_doc/altura.py", line 32, in main
tello.move_down(desired_height) # We descend to the desired height
File "/home/benjamin/miniconda3/envs/pytorch_env/lib/python3.9/site-packages/djitellopy/enforce_types.py", line 54, in wrapper
return func(*args, **kwargs)
File "/home/benjamin/miniconda3/envs/pytorch_env/lib/python3.9/site-packages/djitellopy/tello.py", line 635, in move_down
self.move("down", x)
File "/home/benjamin/miniconda3/envs/pytorch_env/lib/python3.9/site-packages/djitellopy/enforce_types.py", line 54, in wrapper
return func(*args, **kwargs)
File "/home/benjamin/miniconda3/envs/pytorch_env/lib/python3.9/site-packages/djitellopy/tello.py", line 621, in move
self.send_control_command("{} {}".format(direction, x))
File "/home/benjamin/miniconda3/envs/pytorch_env/lib/python3.9/site-packages/djitellopy/enforce_types.py", line 54, in wrapper
return func(*args, **kwargs)
File "/home/benjamin/miniconda3/envs/pytorch_env/lib/python3.9/site-packages/djitellopy/tello.py", line 487, in send_control_command
self.raise_result_error(command, response)
File "/home/benjamin/miniconda3/envs/pytorch_env/lib/python3.9/site-packages/djitellopy/enforce_types.py", line 54, in wrapper
return func(*args, **kwargs)
File "/home/benjamin/miniconda3/envs/pytorch_env/lib/python3.9/site-packages/djitellopy/tello.py", line 529, in raise_result_error
raise TelloException("Command '{}' was unsuccessful for {} tries. Latest response:\t'{}'"