Program a drone with the DroneBlocks Simulator and then deploy to Tello
Project description
DroneBlocksTelloSimulator
Welcome to the DroneBlocks Tello Simulator with Python. If you are looking for the JavaScript version you can check it out here.
The wonderful thing about this library is you can interact with a simulated Tello drone and take the same code and run it with a real Tello drone.
The first thing we recommend you do is set up a virtual environment for your project. This isn't a necessity but it helps keep your project clean.
python3 -m venv venv
or on some systems you may need to use the following:
python -m venv venv
Now that your virtual environment is up and running go ahead and activate it from the root of the project directory.
source venv/bin/activate
on Windows:
.\venv\Scripts\activate
Now install the DroneBlocksTelloSimulator Python package:
pip install DroneBlocksTelloSimulator
Installation is done! Now you need to create your first mission with the DroneBlocks Simulator. You can access the simulator at the link below:
You will need configure Chrome to "Allow Insecure Content" for the simulator. This is not a security risk and will only be done for this domain. This will allow the DroneBlocks simulator to receive commands from Python. Follow these steps:
- Click on the lock icon next to the web address
- Click on "Site settings"
- Scroll to the bottom and look for "Insecure content"
- Change "Block" to "Allow"
- Close the tab and refresh the simulator
You can now move onto programming your first simulated drone mission in Python! Click the button in the top left of the DroneBlocks simulator that says "Get Drone Simulator Key". Copy this unique key to your clipboard as it will be used in your mission code below.
Create a simulated mission using the following code:
from DroneBlocksTelloSimulator.DroneBlocksSimulatorContextManager import DroneBlocksSimulatorContextManager
if __name__ == '__main__':
sim_key = 'YOUR_SIM_KEY_GOES_HERE'
distance = 40
with DroneBlocksSimulatorContextManager(simulator_key=sim_key) as drone:
drone.takeoff()
drone.fly_forward(distance, 'in')
drone.fly_left(distance, 'in')
drone.fly_backward(distance, 'in')
drone.fly_right(distance, 'in')
drone.flip_backward()
drone.land()
Congrats on your first simulated mission! Now let's run the exact same code on a real Tello. We're assuming you know how to connect to Tello from your computer so go ahead and do that.
Once connected you'll run the exact same code above with one small difference. We've changed the sim_key to None and Python now knows to send the same commands to your real Tello, Tello EDU, or Tello Talent!
from DroneBlocksTelloSimulator.DroneBlocksSimulatorContextManager import DroneBlocksSimulatorContextManager
if __name__ == '__main__':
sim_key = None
distance = 40
with DroneBlocksSimulatorContextManager(simulator_key=sim_key) as drone:
drone.takeoff()
drone.fly_forward(distance, 'in')
drone.fly_left(distance, 'in')
drone.fly_backward(distance, 'in')
drone.fly_right(distance, 'in')
drone.flip_backward()
drone.land()
Ta-da! Now you've run the same code in both the DroneBlocks simulator and on Tello! Let's take a look at all the commands available to both the Simulator and Tello:
drone.takeoff()
drone.fly_forward(20, 'in')
drone.fly_backward(20, 'in')
drone.fly_left(20, 'in')
drone.fly_right(20, 'in')
drone.fly_up(20, 'in')
drone.fly_down(20, 'in')
drone.fly_to_xyz(10, 20, 30, 'in')
drone.fly_curve(25, 25, 0, 0, 50, 0, 'in')
drone.flip_forward()
drone.flip_backward()
drone.flip_left()
drone.flip_right()
drone.land()
Give it a try and let us know what you think! If you run into any issues please open a bug here.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for DroneBlocksTelloSimulator-0.0.8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3f6ac748a956af8c9222818ba0e0ea8b38145d72965ebbc0b2324d4b4c07719 |
|
MD5 | 2a63d27677ebaee22cf5a73b50278ef6 |
|
BLAKE2b-256 | e6d19bf51c8a9109c7f5cf59dcb67d8ac2e72cef9f025ff7ddc449af060d79ec |
Hashes for DroneBlocksTelloSimulator-0.0.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc460c3376c03b0cede06a3b5cce5cc88d29406487d4b7a328ce90526ee28f1e |
|
MD5 | 941699459ea6bbf01182b86517900516 |
|
BLAKE2b-256 | 27abd9268d79902acc362f2205e293e6107f8cd21c781e7c296069ecb2648e8c |