From d9a2553aa314e3f715cd3b59e432cc24dd907147 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Fri, 22 Nov 2024 11:54:54 +0000 Subject: [PATCH] More testing --- _locales/fr/README.md | 96 +++++++++++++++++++ .../fr/machine-learning-jsdoc-strings.json | 7 ++ _locales/fr/machine-learning-strings.json | 13 +++ docs/attach-to-sprite.md | 49 ---------- pxt.json | 71 +++++++------- pxtextension.ts | 5 +- 6 files changed, 152 insertions(+), 89 deletions(-) create mode 100644 _locales/fr/README.md create mode 100644 _locales/fr/machine-learning-jsdoc-strings.json create mode 100644 _locales/fr/machine-learning-strings.json delete mode 100644 docs/attach-to-sprite.md diff --git a/_locales/fr/README.md b/_locales/fr/README.md new file mode 100644 index 0000000..5d915e2 --- /dev/null +++ b/_locales/fr/README.md @@ -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. diff --git a/_locales/fr/machine-learning-jsdoc-strings.json b/_locales/fr/machine-learning-jsdoc-strings.json new file mode 100644 index 0000000..1a5079c --- /dev/null +++ b/_locales/fr/machine-learning-jsdoc-strings.json @@ -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." +} \ No newline at end of file diff --git a/_locales/fr/machine-learning-strings.json b/_locales/fr/machine-learning-strings.json new file mode 100644 index 0000000..33cdaf8 --- /dev/null +++ b/_locales/fr/machine-learning-strings.json @@ -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)" +} diff --git a/docs/attach-to-sprite.md b/docs/attach-to-sprite.md deleted file mode 100644 index 1931f73..0000000 --- a/docs/attach-to-sprite.md +++ /dev/null @@ -1,49 +0,0 @@ -# attach To Sprite - -Attach a status bar to a sprite. - -```sig -statusbars.create(0,0,StatusBarKind.Health).attachToSprite(null) -``` - -A status bar is attached to a sprite you specify. -The status bar will follow the sprite around the screen instead of being set in a fixed position. - -When a status bar is attached to a sprite, you can use the `status bar attached to mySprite` -and `sprite that statusbar is attached to` blocks to get the sprites / status bars that are attached to each other. - -## Parameters - -* **toFollow**: the sprite to attach to. -* **padding**: an optional [number](types/number) of pixels to pad around the status bar. -* **offset**: an optional [number](types/number) of pixels away from the sprite to place the status bar. - -## Example - -```blocks -let statusbar = statusbars.create(20, 4, StatusBarKind.Health) -let mySprite = sprites.create(img` - . . . . . . . . . . b 5 b . . . - . . . . . . . . . b 5 b . . . . - . . . . . . b b b b b b . . . . - . . . . . b b 5 5 5 5 5 b . . . - . . . . b b 5 d 1 f 5 d 4 c . . - . . . . b 5 5 1 f f d d 4 4 4 b - . . . . b 5 5 d f b 4 4 4 4 b . - . . . b d 5 5 5 5 4 4 4 4 b . . - . b b d d d 5 5 5 5 5 5 5 b . . - b d d d b b b 5 5 5 5 5 5 5 b . - c d d b 5 5 d c 5 5 5 5 5 5 b . - c b b d 5 d c d 5 5 5 5 5 5 b . - c b 5 5 b c d d 5 5 5 5 5 5 b . - b b c c c d d d 5 5 5 5 5 d b . - . . . . c c d d d 5 5 5 b b . . - . . . . . . c c c c c b b . . . - `, SpriteKind.Player) -controller.moveSprite(mySprite) -statusbar.attachToSprite(mySprite) -``` - -```package -pxt-status-bar=github:jwunderl/pxt-status-bar -``` \ No newline at end of file diff --git a/pxt.json b/pxt.json index e2831c1..f2306f9 100644 --- a/pxt.json +++ b/pxt.json @@ -1,40 +1,37 @@ { - "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", - "docs/on-start.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 - } + "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", + "docs/on-start.md", + "_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 } + } } diff --git a/pxtextension.ts b/pxtextension.ts index 99e6590..02e25b8 100644 --- a/pxtextension.ts +++ b/pxtextension.ts @@ -56,7 +56,7 @@ namespace ml { //% weight=50 //% parts="v2" //% group="micro:bit (V2)" - //% help=github:microbit-foundation/pxt-microbit-ml/docs/on-start + //% help=github:pxt-microbit-ml/docs/on-start export function onStart(event: MlEvent, body: () => void): void { event.onStartHandler = body; const wrappedBody = () => { @@ -80,7 +80,7 @@ namespace ml { //% weight=40 //% parts="v2" //% group="micro:bit (V2)" - //% help=github:microbit-foundation/pxt-microbit-ml/README + //% help=github:pxt-microbit-ml/README export function onStop(event: MlEvent, body: () => void): void { if (!isRunning()) { startRunning(); @@ -94,7 +94,6 @@ namespace ml { //% draggableParameters="reporter" //% parts="v2" //% group="micro:bit (V2)" - //% help=github:pxt-status-bar/docs/attach-to-sprite export function onStopDetailed( event: MlEvent, body: (duration: number) => void