Please select Into the mobile phone version | Continue to access the computer ver.
How the DJI Python interpreter works
1563 29 2019-11-11
Uploading and Loding Picture ...(0/1)
o(^-^)o
sevreNniarB
lvl.4
Germany
Offline

Some of you have asked how the DJI Python interpreter works and/or how the S1 internal functions are implemented. Attached you'll find some Python sources which hopefully will answer most of your questions. This is for the advanced Python users out there.

Robomaster S1.zip (74.39 KB, Down times: 65)
2019-11-11
Use props
DJI Stephen
Super Moderator

Offline

Hello and good day sevreNniarB. Thank you for sharing this informative information to us and thank you for your valued support.
2019-11-11
Use props
rhoude57 - YUL
Second Officer
Canada
Offline

Were those extracted from the RoboMaster app/program Unity Project?
2019-11-11
Use props
sevreNniarB
lvl.4
Germany
Offline

rhoude57 - YUL Posted at 11-11 10:50
Were those extracted from the RoboMaster app/program Unity Project?

No, it's genuine S1 Code.
2019-11-11
Use props
BGA
First Officer
United States
Offline

FWIIW, I can vouch that this is the real deal.
2019-11-11
Use props
rhoude57 - YUL
Second Officer
Canada
Offline

sevreNniarB Posted at 11-11 11:03
No, it's genuine S1 Code.

The RoboMaster app and PC program Unity project is as genuine as the code can get.

Everyone of those Python functions would likely be stored in the Unity Project as Scripts.
2019-11-11
Use props
sevreNniarB
lvl.4
Germany
Offline

rhoude57 - YUL Posted at 11-11 16:37
The RoboMaster app and PC program Unity project is as genuine as the code can get.

Everyone of those Python functions would likely be stored in the Unity Project as Scripts.

The Python scripts are stored locally on the  S1. If you run a program in Lab it gets send to the S1, is interpreted there and also executed. The compiler messages you see in Lab come from the S1 and not the Unity software. What you see in Lab is more or less working like a terminal session.

Take a look at safe_func_names in the script_manage.py, there is no Unity equivalent for this. The interpreter on the S1 filters unsafe functions & modules. That's why users (even with a debugger) can't change the scope of the whitelisted funtions or modules.

Cheers

2019-11-11
Use props
rhoude57 - YUL
Second Officer
Canada
Offline

sevreNniarB Posted at 11-11 17:06
The Python scripts are stored locally on the  S1. If you run a programm in Lab it gets send to the S1, is interpreted there and also executed. The compiler messages you see in Lab come from the S1 and not the Unity software. What you see in Lab is more or less working like a terminal session.

Take a look at safe_func_names in the script_manage.py, there is no Unity equivalent for this. The interpreter on the S1 filters unsafe functions & modules. That's why users (even with a debugger) can't change the scope of the whitelisted funtions or modules.

Cool! I get it now...

Thanks for the explanations.
2019-11-11
Use props
BGA
First Officer
United States
Offline

sevreNniarB Posted at 11-11 17:06
The Python scripts are stored locally on the  S1. If you run a program in Lab it gets send to the S1, is interpreted there and also executed. The compiler messages you see in Lab come from the S1 and not the Unity software. What you see in Lab is more or less working like a terminal session.

Take a look at safe_func_names in the script_manage.py, there is no Unity equivalent for this. The interpreter on the S1 filters unsafe functions & modules. That's why users (even with a debugger) can't change the scope of the whitelisted funtions or modules.

Just to be more precise, the code you create in the lab is actually inserted in the middle of a template code that connects with the actual S1 features (that is why you do not need to import anything, for example). Funny thing, the way to code is inlined makes the start() function be completely unnecessary (anythng that you type outside any function will be executed) and it is most likely there just to make Scratch code easier to reason about.
2019-11-12
Use props
justinzak
lvl.2

New Zealand
Offline

So this python code is the python interpreter/compiler for applications written and sent in the robomaster app? (our project code inserted within template?)
Is this the full code on the robomaster that the standard python compiler uses?
and if we have terminal access; can we not compile this on the device, or our own version of it, with libraries and functions to externalize the data streams?

Thank you for your efforts so far!
2019-11-12
Use props
sevreNniarB
lvl.4
Germany
Offline

BGA Posted at 11-12 09:03
Just to be more precise, the code you create in the lab is actually inserted in the middle of a template code that connects with the actual S1 features (that is why you do not need to import anything, for example). Funny thing, the way to code is inlined makes the start() function be completely unnecessary (anythng that you type outside any function will be executed) and it is most likely there just to make Scratch code easier to reason about.

Yes, it is really a mess... I've whitelisted the Python functions & module import and some stuff is still not working because of the way they have implemented it (sandwich style)... ever tried to write a class? GL with it Well, you are able to code everything outside of Lab and execute it directly, but that's a whole other story.

BTW: A lot of the system is heavily secured (SELinux, Checksums, FS checks, you name it). When you mess with the wrong files the S1 will reboot and reinitialize with its factory image... the whole system screams: “stay out!” and I really hope the efuses will not blow up my board one day



I'm sorry, but the S1 is not designed for real robotics development/coding or the cool stuff you see on the YouTube Robomaster shows...

Cheers
2019-11-12
Use props
justinzak
lvl.2

New Zealand
Offline

Oh man what a buzz kill! I hope something changes
2019-11-12
Use props
sevreNniarB
lvl.4
Germany
Offline

justinzak Posted at 11-12 13:06
So this python code is the python interpreter/compiler for applications written and sent in the robomaster app? (our project code inserted within template?)
Is this the full code on the robomaster that the standard python compiler uses?
and if we have terminal access; can we not compile this on the device, or our own version of it, with libraries and functions to externalize the data streams?

Thank you

Hmmm, I don't think it is all of it - just the more interesting and important stuff. There are tons of test programs in Python, shell scripts and other stuff to explore. I still don't understand the messaging system from the S1 to the client application (but with direct access you don't need it anyway)

Yes, this is the Python code (my .zip file) that is running on the S1.

Yes, we could compile our own versions on the S1. The problem is the internal security...

Cheers
2019-11-12
Use props
BGA
First Officer
United States
Offline

justinzak Posted at 11-12 13:06
So this python code is the python interpreter/compiler for applications written and sent in the robomaster app? (our project code inserted within template?)
Is this the full code on the robomaster that the standard python compiler uses?
and if we have terminal access; can we not compile this on the device, or our own version of it, with libraries and functions to externalize the data streams?

This is the python code that run son the S1. The code you write in the lab is inserted in the middle of it. It is not the entirety of the relevant S1-side code (for example, the AI stuff is not there most likely because it is implemented as C libraries.

There are several limitations about what you can do on the robot side because it checks checksums for several things and resets itself if it detects tampering. That being said, with the doors open as they are, it is not impossible a workaround might appear.
  
2019-11-12
Use props
justinzak
lvl.2

New Zealand
Offline

Ah. I'm guessing its unlikely that we gain insight as to where/how the security checks are implemented, so probably a lot of boundary testing until some holes are found?
2019-11-12
Use props
sevreNniarB
lvl.4
Germany
Offline

justinzak Posted at 11-12 14:24
Ah. I'm guessing its unlikely that we gain insight as to where/how the security checks are implemented, so probably a lot of boundary testing until some holes are found?

It's working like with all other devices (e.g. if you root your phone). The OS is Android, what we need is a tool to extract the Firmware, modify it and flash it back... simple as that

There is a really great DJI mod comminty out there, unfortunately the S1 has not caught their interest yet.

Cheers
2019-11-12
Use props
justinzak
lvl.2

New Zealand
Offline

Hope base firmware that can be extracted is correct and reliable method of  flashing is found, as the risk of bricking something like this is tenfold, no?
2019-11-12
Use props
sevreNniarB
lvl.4
Germany
Offline

justinzak Posted at 11-12 14:53
Hope base firmware that can be extracted is correct and reliable method of  flashing is found, as the risk of bricking something like this is tenfold, no?

Flashing will brick your device if it is not done correctly, yes. Poking around will do no harm at all... i don't think the S1 efuses are "real efuses" in the Motorola or MS way.

Motorola and Microsoft used real efuses on some of their boards. Everytime e.g. a new firmware was flashed, one of the fuses blew up to limit the amount attempts... for "security reasons", they said.

IBM originally invented the technology in the 2000's to alter the function and performance of a chip in real time. MS & Motorola just used it in a different way ^^
2019-11-13
Use props
justinzak
lvl.2

New Zealand
Offline

Would not be a concerned about that at all, Motorola and Microsoft are on a completely different plane to DJI. Just from a general perspective I meant, knowing the hardware is different and that firmware can be easily restored should it fail
2019-11-13
Use props
g1107
lvl.4
China
Offline

very nice!!!
2019-11-13
Use props
gpvillamil
Second Officer
Flight distance : 210226 ft
United States
Offline

So, you might have addressed this already, but how did you gain direct access?
2019-11-14
Use props
sevreNniarB
lvl.4
Germany
Offline

gpvillamil Posted at 11-14 11:18
So, you might have addressed this already, but how did you gain direct access?

Please take a look at my PM

Cheers
2019-11-15
Use props
fans09cc21f3
lvl.1

South Korea
Offline

I want to download this file, but I can't. Tell me how to download..
2019-12-9
Use props
dlnl
lvl.1

Netherlands
Offline

fans09cc21f3 Posted at 12-9 01:35
I want to download this file, but I can't. Tell me how to download..

me too. I get a message I'm not authorized to download? I just signed up a DJI account.
2019-12-9
Use props
sevreNniarB
lvl.4
Germany
Offline

New users can't download files, you need to be lvl. 1 - I'm sorry, this is how this forum works
2019-12-9
Use props
Michaelion
New
Puerto Rico
Offline

sevreNniarB Posted at 2019-12-9 02:37
New users can't download files, you need to be lvl. 1 - I'm sorry, this is how this forum works

I just created account last month and guess that makes me a new user.  Bought the robot with sole purpose of using/learning python code.  The Lab part of the AP doesn’t allow you to write python code but rather converts  the scratch blocks-am I missing something.  Came here looking for answers, tried to down load your zip file but said I don’t have permission (new user?) any help or guidance appreciated.
1-28 11:51
Use props
BGA
First Officer
United States
Offline

Michaelion Posted at 1-28 11:51
I just created account last month and guess that makes me a new user.  Bought the robot with sole purpose of using/learning python code.  The Lab part of the AP doesn’t allow you to write python code but rather converts  the scratch blocks-am I missing something.  Came here looking for answers, tried to down load your zip file but said I don’t have permission (new user?) any help or guidance appreciated.

You can write python code. If you look at the top of the work area in the lab, you will see a "Python(Beta)" tab. Click on it and start writing python code.

But 2 things about this:

1 - Using the S1 to learn Python does not sound like a very good idea. You can only use a limited subset of Python on it
2 - Downloading the files available in this thread will not help you with developing using Python on the S1. Specially if you still need to learn Python.
.
1-28 15:21
Use props
Michaelion
New
Puerto Rico
Offline

I figured it would be a fun way to continue to learn python and would help keeping the interest of kids.  My last endeavor was using the Spigot API with Minecraft and enjecting the python code into the Minecraft game.  Taught me some of python stuff and kids thought it was cool-win-win!  I went back to Python Beta like you said and figured it out-appreciate you pointing me in the right direction and confirming it could be done Once I got past that ID10T error.
1-29 09:21
Use props
BGA
First Officer
United States
Offline

Michaelion Posted at 1-29 09:21
I figured it would be a fun way to continue to learn python and would help keeping the interest of kids.  My last endeavor was using the Spigot API with Minecraft and enjecting the python code into the Minecraft game.  Taught me some of python stuff and kids thought it was cool-win-win!  I went back to Python Beta like you said and figured it out-appreciate you pointing me in the right direction and confirming it could be done Once I got past that ID10T error.

Glad I could help.
1-29 09:34
Use props
Bitmizu
lvl.1

Singapore
Offline

Wonder how to gain root access on my rm s1? Would it work on ep?
3-27 20:32
Use props
Advanced
You need to log in before you can reply Login | Register now

Credit Rules