K210-Call custom py library

Call custom py library

Friends who have used Python should know that Python supports calling custom py libraries (or third-party py libraries) in the same directory, and MicroPython also supports calling custom py libraries. Before calling the custom py library, the py library file needs to be imported into K210 in advance.

Import py library file

Here we take importing simplePID.py as an example.

There are two ways to import a custom py library. The first is to directly copy the custom py library file to the root directory of the memory card, and then insert the memory card to call it.

image-20230227152400203

The second is to import through CanMV IDE, please refer to the following content for specific operations.

Open Tools->Save file to CanMV Cam.

image-20230227142607010

Click Open, then select the py library file to be passed in, change the file name to simplePID.py, then click OK to start writing the file, and wait for the file writing to complete.

Note: The files written here are written to the memory card first.

image-20230227142752374image-20230227143304756image-20230227143344431

Call py library

from simplePID import PID
print("import simplePID OK")
PID_controller = PID(0, 10, 0, 1)
print("PID test OK")

Run the above code, if it is normal, the test OK prompt message will be printed on the serial terminal at the bottom of the IDE.

image-20230227150153123

If the simplePID.py file is not imported in advance, or the imported name does not correspond, an error will be prompted.

おすすめ

転載: blog.csdn.net/ai_moe/article/details/132672555