Skip to content

Commit

Permalink
restructure, add build.bat
Browse files Browse the repository at this point in the history
  • Loading branch information
alecGraves committed Mar 18, 2023
1 parent d1b60da commit 4369ec6
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.lib
*.pyd
*.exp
*.dll
*.exe
*.obj
*.o
*.so
__pycache*/
*.egg-*/
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
# telloc 📸🎮


# tellopy 📸🎮🐍

Minimal python3 library for reading images from and sending commands to a DJI tello drone.

To build on Windows, install ffmpeg wich chocolatey:

1. install chocolatey
2. open cmd or terminal as administrator
3. choco install

Then install visual studio and build

1. install visual studio
2. open a developer command prompt
3. edit build.bat for your version of python
4. run `build.bat` to compile the telloc python bindings (libtellopy)

Lastly, `pip install tellopy .` inside of this repo.



Tellopy is based on on telloc (see below:)

## telloc 📸🎮

Cross-platform C library for connecting to the DJI Tello with video support

This was created for the Roadrunner Dynamics Club.
Expand Down
35 changes: 35 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
rem This compiles telloc on windows.
rem run this script from the developer command prompt.
rem read the README.

rem :: set environment variables ::
set ffmpeg_include_dir="C:\Program Files\FFmpeg\include"
set ffmpeg_lib_dir="C:\Program Files\FFmpeg\lib"
set ffmpeg_dll_dir="C:\Program Files\FFmpeg\bin"
set build_python="true"
set python_dir="%userprofile%\AppData\Local\Programs\Python\Python311"

rem :: compile telloc ::
set SOURCES=telloc\video.c telloc\telloc_windows.c
set avcodec=%ffmpeg_lib_dir%\avcodec.lib
set avformat=%ffmpeg_lib_dir%\avformat.lib
set avutil=%ffmpeg_lib_dir%\avutil.lib
set swscale=%ffmpeg_lib_dir%\swscale.lib
cl /c /MT /Itelloc\ /I%ffmpeg_include_dir% %SOURCES%
lib /OUT:telloc.lib /MACHINE:X64 video.obj telloc_windows.obj %avcodec% %avformat% %avutil% %swscale% ws2_32.lib

rem :: compile test program ::
cl /c telloc/main_windows.c /Itelloc /link /LIBPATH:%CD% telloc.lib /OUT:test.exe user32.lib gdi32.lib

IF NOT %build_python% == "false" (
rem build the python library
cl /c /MT /Itelloc /I%python_dir%\include tellopy.c
link /dll /MACHINE:X64 /OUT:tellopy\libtellopy.pyd /LIBPATH:%python_dir%\libs tellopy.obj telloc.lib python3.lib
copy %ffmpeg_dll_dir%\avcodec*.dll tellopy
copy %ffmpeg_dll_dir%\avformat*.dll tellopy
copy %ffmpeg_dll_dir%\avutil*.dll tellopy
copy %ffmpeg_dll_dir%\swscale*.dll tellopy
copy %ffmpeg_dll_dir%\swresample*.dll tellopy
)

rem del *.obj
50 changes: 50 additions & 0 deletions build/lib/tellopy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from . import libtellopy
# import os
# import ctypes

# path = os.path.dirname(os.path.abspath(__file__))
# os.add_dll_directory(path)
# libtellopy = ctypes.windll.LoadLibrary(os.path.abspath(os.path.join(path, 'libtellopy.pyd')))


def connect():
"""
Connect to Tello drone, returning True if successful and False otherwise.
:return: success
"""
return libtellopy.connect()


def send_command(command):
"""
Send a command to the Tello drone, returning the response.
:param command: string command from Tello SDK api commands (e.g. 'battery?', 'takeoff', 'land', 'streamon', 'streamoff')
:return: string response
"""
return libtellopy.send_command(command)


def read_image():
"""
Read a frame from the video stream, returning a tuple of (height, width, flat) where flat is a list of RGB values.
:return: height, width, rgblist
"""
return libtellopy.read_image()


def read_state():
"""
Read the state of the drone, returning a dictionary of key-value pairs.
:return: string of comma-separated state information. Should be easy to turn into a dictionary.
"""
return libtellopy.read_state()


def disconnect():
"""
Disconnect from the Tello drone.
Throws and exception if there is a problme disconnecting. But honestly, you are likely to segfault in that case.
:return: True if disconnected or disconnection successful.
"""
return libtellopy.disconnect()

6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
author='Alec Graves',
author_email='[email protected]',
description='A simple package for controlling and viewing video from the DJI Tello',
long_description=open('README.md').read(),
long_description=open('README.md', encoding='utf8').read(),
long_description_content_type='text/markdown',
url='https://github.com/alecGraves/telloc',
url='https://github.com/alecGraves/tellopy',
packages=find_packages(),
package_data={'telloc': ['libtellopy.so', 'libtellopy.dll']},
package_data={'telloc': ['libtellopy.so', 'libtellopy.pyd', "*.dll"]},
include_package_data=True,
classifiers=[
'Development Status :: 3 - Alpha',
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt → telloc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(telloc C)
set(CMAKE_C_STANDARD 99)

# pedantic
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -Werror")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")

# check if we are on Windows (should work with MinGW and Visual Studio)
if (WIN32)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4369ec6

Please sign in to comment.