-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62ab8f9
commit 3628304
Showing
5 changed files
with
149 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Microsoft MakeCode extension for use with micro:bit CreateAI | ||
|
||
FR - This extension is leveraged by micro:bit CreateAI which creates suitable blocks based on the machine learning model you build in the app. It is not useful separate from micro:bit CreateAI. | ||
|
||
## Building locally | ||
|
||
Ensure you have the required toolchain to build for V1 and V2 | ||
(arm-none-eabi-gcc, python, yotta, cmake, ninja, srec_cat) or docker. | ||
|
||
```bash | ||
git clone https://github.com/microbit-foundation/pxt-microbit-ml | ||
cd pxt-microbit-ml | ||
npm install pxt --no-save | ||
npx pxt target microbit --no-save | ||
npx pxt install | ||
PXT_FORCE_LOCAL=1 PXT_NODOCKER=1 npx pxt | ||
``` | ||
|
||
For the V1 build Yotta can hit the GitHub rate limits quite easily if the | ||
project is built from a clean state more than once. | ||
A V2-only build can be performed with the `PXT_COMPILE_SWITCHES=csv---mbcodal` | ||
environmental variable. | ||
|
||
``` | ||
PXT_FORCE_LOCAL=1 PXT_NODOCKER=1 PXT_COMPILE_SWITCHES=csv---mbcodal npx pxt | ||
``` | ||
|
||
## Build flags | ||
|
||
### Model predictions per second | ||
|
||
By default the model will run every 250 ms, to change this value the | ||
`ML_INFERENCE_PERIOD_MS` config can be modified. | ||
|
||
```json | ||
{ | ||
"yotta": { | ||
"config": { | ||
"ML_INFERENCE_PERIOD_MS": 250 | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Model events | ||
|
||
By default this extension configures the Model prediction events to not be | ||
queued for the same event. | ||
So if an event raised when its handler is still running it will be dropped. | ||
|
||
```json | ||
{ | ||
"yotta": { | ||
"config": { | ||
"ML_EVENT_LISTENER_DEFAULT_FLAGS": 32 | ||
} | ||
} | ||
} | ||
``` | ||
|
||
The values are defined in the | ||
[codal-core/inc/core/CodalListener.h](https://github.com/lancaster-university/codal-core/blob/df05db9e15499bd8906618192a4d482e3836c62f/inc/core/CodalListener.h#L36-L40) | ||
file: | ||
|
||
```cpp | ||
#define MESSAGE_BUS_LISTENER_REENTRANT 0x0008 | ||
#define MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY 0x0010 | ||
#define MESSAGE_BUS_LISTENER_DROP_IF_BUSY 0x0020 | ||
#define MESSAGE_BUS_LISTENER_NONBLOCKING 0x0040 | ||
#define MESSAGE_BUS_LISTENER_URGENT 0x0080 | ||
``` | ||
|
||
### Debug messages | ||
|
||
To enable debug print from this extension, add the following into your | ||
pxt.json file: | ||
|
||
```json | ||
{ | ||
"yotta": { | ||
"config": { | ||
"ML_DEBUG_PRINT": 1 | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## License | ||
|
||
This software made available under the MIT open source license. | ||
|
||
[SPDX-License-Identifier: MIT](/LICENSE) | ||
|
||
## Code of Conduct | ||
|
||
Trust, partnership, simplicity and passion are our core values we live and breathe in our daily work life and within our projects. Our open-source projects are no exception. We have an active community which spans the globe and we welcome and encourage participation and contributions to our projects by everyone. We work to foster a positive, open, inclusive and supportive environment and trust that our community respects the micro:bit code of conduct. Please see our [code of conduct](https://www.microbit.org/safeguarding/) which outlines our expectations for all those that participate in our community and details on how to report any concerns and what would happen should breaches occur. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"mlrunner.customOnEvent": "FR - Register a TypeScript function to run when an event is raised.\n* This custom version of the MakeCode onEvent function is needed due to:\nhttps://github.com/microsoft/pxt-microbit/issues/5709\n*", | ||
"mlrunner.customOnEvent|param|flags": "FR - The specified event flags are ignored and configured via pxt.json.", | ||
"mlrunner.customOnEvent|param|handler": "FR - The function to call when the event is detected.", | ||
"mlrunner.customOnEvent|param|src": "FR - The ID of the component to listen to.", | ||
"mlrunner.customOnEvent|param|value": "FR - The event value to listen to from that component." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"ml.event.Unknown|block": "FR - unknown", | ||
"ml.getCertainty|block": "FR - certainty (\\%) ML $event", | ||
"ml.isDetected|block": "FR - is ML $event detected", | ||
"ml.onStart|block": "FR - on ML $event start", | ||
"ml.onStopDetailed|block": "FR - on ML $event stop $duration (ms)", | ||
"ml.onStop|block": "FR - on ML $event stop", | ||
"mlrunner|block": "FR - mlrunner", | ||
"{id:category}Ml": "FR - Ml", | ||
"{id:category}MlEvent": "FR - MlEvent", | ||
"{id:category}Mlrunner": "FR - Mlrunner", | ||
"{id:group}micro:bit (V2)": "FR - micro:bit (V2)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,36 @@ | ||
{ | ||
"name": "machine-learning", | ||
"version": "1.0.2", | ||
"description": "Machine learning extension to support micro:bit CreateAI", | ||
"dependencies": { | ||
"core": "*", | ||
"machine-learning-runner": "github:microbit-foundation/pxt-microbit-ml-runner#v0.4.8" | ||
}, | ||
"files": [ | ||
"README.md", | ||
"shims.d.ts", | ||
"enums.d.ts", | ||
"pxtextension.ts", | ||
"pxtextension.cpp" | ||
], | ||
"testFiles": [ | ||
"autogenerated.ts", | ||
"main.ts", | ||
"main.blocks" | ||
], | ||
"targetVersions": { | ||
"branch": "v6.0.26", | ||
"tag": "v6.0.26", | ||
"commits": "https://github.com/microsoft/pxt-microbit/commits/0ba979dd8a8f411c37c20b5fd4faba5b43ef51aa", | ||
"target": "6.0.26", | ||
"targetId": "microbit", | ||
"pxt": "9.0.17" | ||
}, | ||
"supportedTargets": [ | ||
"microbit" | ||
], | ||
"preferredEditor": "tsprj", | ||
"yotta": { | ||
"config": { | ||
"ML_INFERENCE_PERIOD_MS": 250, | ||
"ML_EVENT_LISTENER_DEFAULT_FLAGS": 32 | ||
} | ||
"name": "machine-learning", | ||
"version": "1.0.2", | ||
"description": "Machine learning extension to support micro:bit CreateAI", | ||
"dependencies": { | ||
"core": "*", | ||
"machine-learning-runner": "github:microbit-foundation/pxt-microbit-ml-runner#v0.4.8" | ||
}, | ||
"files": [ | ||
"README.md", | ||
"shims.d.ts", | ||
"enums.d.ts", | ||
"pxtextension.ts", | ||
"pxtextension.cpp", | ||
"_locales/fr/machine-learning-jsdoc-strings.json", | ||
"_locales/fr/machine-learning-strings.json", | ||
"_locales/fr/README.md" | ||
], | ||
"testFiles": ["autogenerated.ts", "main.ts", "main.blocks"], | ||
"targetVersions": { | ||
"branch": "v6.0.26", | ||
"tag": "v6.0.26", | ||
"commits": "https://github.com/microsoft/pxt-microbit/commits/0ba979dd8a8f411c37c20b5fd4faba5b43ef51aa", | ||
"target": "6.0.26", | ||
"targetId": "microbit", | ||
"pxt": "9.0.17" | ||
}, | ||
"supportedTargets": ["microbit"], | ||
"preferredEditor": "tsprj", | ||
"yotta": { | ||
"config": { | ||
"ML_INFERENCE_PERIOD_MS": 250, | ||
"ML_EVENT_LISTENER_DEFAULT_FLAGS": 32 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters