Please select Into the mobile phone version | Continue to access the computer ver.
RoboMasterPy: a Python SDK and framework for RoboMaster EP
509 7 6-7 19:07
Uploading and Loding Picture ...(0/1)
o(^-^)o
nanmu42
lvl.1

Taiwan
Offline

I made a Python SDK and framework for Robomaster EP, hope you guys like it.



link: https://github.com/nanmu42/robomasterpy

Or you can install it directly using pip:

pip install robomasterpy

The SDK(client) is straightforward to use:

>>> import robomasterpy as rm  

# IP of RoboMaster is detected under router mode
>>> cmd = rm.Commander()  


# check RoboMaster's API version
>>> cmd.version()
'version 00.00.00.60'  


>>> cmd.get_robot_mode()
'chassis_lead'  


# ensure your Robomaster has enough room to move
>>> cmd.chassis_move(x=-1, z=30)
'ok'  


# activate video streaming,
# which can be handled by the framework.
>>> cmd.stream(rm.SWITCH_ON)
'ok'  


# activate gimbal attitude push at 5Hz,
# which can be handled by the framework.


>>> cmd.gimbal_push_on(attitude_freq=5)
'ok'  


# Watch out!
>>> cmd.blaster_fire()
'ok'


The framework deals with video streaming, push and event, provides a high-level interface for controlling and communication. You can build your controlling logic basing on it.



Fun Examples: https://github.com/nanmu42/robo-playground

  • Drive your robomaster using keyboard;
  • Make your robomaster a goalkeeper;
  • More examples







6-7 19:07
Use props
JohnnyRobotic
lvl.4
United States
Offline

Impressive! Thank you for sharing.
6-8 09:18
Use props
djiuser_pu8X2L7zHZMo
lvl.1

Hong Kong
Offline


pip install robomasterpy

Collecting robomasterpy
  Downloading robomasterpy-0.1.0-py2.py3-none-any.whl (15 kB)
Collecting opencv-contrib-python
  Downloading opencv_contrib_python-4.2.0.34-cp36-cp36m-win_amd64.whl (39.5 MB)
     |████████████████████████████████| 39.5 MB 6.4 MB/s
Collecting numpy>=1.11.3
  Downloading numpy-1.18.5-cp36-cp36m-win_amd64.whl (12.7 MB)
     |████████████████████████████████| 12.7 MB 6.8 MB/s
Installing collected packages: numpy, opencv-contrib-python, robomasterpy
  WARNING: The script f2py.exe is installed in 'c:\users\fms-lcf.fkssteacher\appdata\local\programs\python\python36\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed numpy-1.18.5 opencv-contrib-python-4.2.0.34 robomasterpy-0.1.0



I got the following errors how to solve that.

Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information.

>>> import robomasterpy as rm Traceback (most recent call last):   File "<pyshell#0>", line 1, in <module>     
import robomasterpy as rm   

File "C:\Users\fms-lcf.FKSSTEACHER\AppData\Local\Programs\Python\Python36\lib\site-packages\robomasterpy\__init__.py", line 20, in <module>     from . import framework   File "C:\Users\fms-lcf.FKSSTEACHER\AppData\Local\Programs\Python\Python36\lib\site-packages\robomasterpy\framework.py", line 21, in <module>     from .client import CTX, LOG_LEVEL, PUSH_PORT, GimbalAttitude, ChassisPosition, ChassisAttitude, ChassisStatus, DEFAULT_BUF_SIZE, EVENT_PORT, ARMOR_HIT, ArmorHitEvent, SOUND_APPLAUSE, SoundApplauseEvent, VIDEO_PORT, Commander   File "C:\Users\fms-lcf.FKSSTEACHER\AppData\Local\Programs\Python\Python36\lib\site-packages\robomasterpy\client.py", line 15, in <module>     from dataclasses import dataclass ModuleNotFoundError: No module named 'dataclasses'
6-14 16:39
Use props
djiuser_pu8X2L7zHZMo
lvl.1

Hong Kong
Offline

Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import robomasterpy as rm Traceback (most recent call last):   File "<pyshell#0>", line 1, in <module>     import robomasterpy as rm   File "C:\Users\fms-lcf.FKSSTEACHER\AppData\Local\Programs\Python\Python36\lib\site-packages\robomasterpy\__init__.py", line 20, in <module>     from . import framework   File "C:\Users\fms-lcf.FKSSTEACHER\AppData\Local\Programs\Python\Python36\lib\site-packages\robomasterpy\framework.py", line 21, in <module>     from .client import CTX, LOG_LEVEL, PUSH_PORT, GimbalAttitude, ChassisPosition, ChassisAttitude, ChassisStatus, DEFAULT_BUF_SIZE, EVENT_PORT, ARMOR_HIT, ArmorHitEvent, SOUND_APPLAUSE, SoundApplauseEvent, VIDEO_PORT, Commander   File "C:\Users\fms-lcf.FKSSTEACHER\AppData\Local\Programs\Python\Python36\lib\site-packages\robomasterpy\client.py", line 15, in <module>     from dataclasses import dataclass ModuleNotFoundError: No module named 'dataclasses'
6-14 16:40
Use props
nanmu42
lvl.1

Hong Kong
Offline

Reference from the doc:

If you are using Python 3.6.x, you need to install dataclasses:

pip install dataclasses
6-14 19:18
Use props
si3n4
lvl.2
Canada
Online

Thx! Is it possible to make it work for S1?
6-20 19:16
Use props
David Martin Graff
Captain
Flight distance : 34614662 ft
  • >>>
United States
Offline

Nicely done - thanks again for sharing!
6-20 21:18
Use props
BGA
First Officer
United States
Offline

si3n4 Posted at 6-20 19:16
Thx! Is it possible to make it work for S1?

This is EP only unless DJI decides toi release the SDK for the S1. Which it did not do so far.
6-22 05:19
Use props
Advanced
You need to log in before you can reply Login | Register now

Credit Rules