From 369fd6765775f74757879c4ccde3fd2a7512385c Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 19 Sep 2023 14:16:13 -0700 Subject: [PATCH 1/3] Update robot/protocol.ts, robot/robot.ts, robot/micromaqueenrobot.ts, robot/radio.ts --- robot/micromaqueenrobot.ts | 3 --- robot/protocol.ts | 4 +--- robot/radio.ts | 11 +++-------- robot/robot.ts | 7 ++----- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/robot/micromaqueenrobot.ts b/robot/micromaqueenrobot.ts index 8d04683b..c871b735 100644 --- a/robot/micromaqueenrobot.ts +++ b/robot/micromaqueenrobot.ts @@ -19,9 +19,6 @@ namespace microcode { maqueen.motorRun(maqueen.Motors.All, right < 0 ? maqueen.Dir.CCW : maqueen.Dir.CW, right) } } - motorStop() { - maqueen.motorStop(maqueen.Motors.All) - } } robot = new MicroMaqqueenRobot() diff --git a/robot/protocol.ts b/robot/protocol.ts index d3a78b10..3944ab7e 100644 --- a/robot/protocol.ts +++ b/robot/protocol.ts @@ -2,9 +2,7 @@ namespace microcode { const MESSAGE_MAGIC = 0xf498 export enum RobotCommand { - SetRobotDriver = 0x0001, - MotorRun = 0x0002, - MotorStop = 0x0003, + MotorRun = 0x0001, } export enum RobotDrivers { MicroMaqqueen = 0x01 diff --git a/robot/radio.ts b/robot/radio.ts index 9a8729a3..fda68de5 100644 --- a/robot/radio.ts +++ b/robot/radio.ts @@ -13,7 +13,7 @@ namespace microcode { export function setGroup(newGroup: number) { if (newGroup < 0) - newGroup += MAX_GROUPS + newGroup += MAX_GROUPS group = newGroup % MAX_GROUPS radio.setGroup(group) showRadioStatus() @@ -40,17 +40,12 @@ namespace microcode { const payload = msg.payload switch (cmd) { case RobotCommand.MotorRun: { - const left = payload.getNumber(NumberFormat.Int8LE, 0) - const right = payload.getNumber(NumberFormat.Int8LE, 1) + const left = Math.clamp(-255, 255, payload.getNumber(NumberFormat.Int16LE, 0)) + const right = Math.clamp(-255, 255, payload.getNumber(NumberFormat.Int16LE, 2)) console.log(`motor run ${left} ${right}`) robot.motorRun(left, right) break } - case RobotCommand.MotorStop: { - console.log(`motor stop`) - robot.motorStop() - break - } } }) } \ No newline at end of file diff --git a/robot/robot.ts b/robot/robot.ts index 69faa957..084e9635 100644 --- a/robot/robot.ts +++ b/robot/robot.ts @@ -1,13 +1,10 @@ namespace microcode { export interface Robot { /* - Set the power on motors + Set the power on motors where `left` and `right` are in [-255,255] + Set left and right to 0 to stop. */ motorRun(left: number, right: number): void; - /** - * Stop and brake - */ - motorStop(): void; } export let robot: Robot From cc2f4c39be3331954ae5299556f5ebfb9733544a Mon Sep 17 00:00:00 2001 From: Tom Ball Date: Tue, 19 Sep 2023 15:00:31 -0700 Subject: [PATCH 2/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4a7c00b5..9de02704 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ ## Microsoft MicroCode [https://aka.ms/microcode](https://aka.ms/microcode) -Microsoft MicroCode is an icon-based programming language and editor for young learners to code with the [BBC micro:bit V2](https://microbit.org). MicroCode runs in the browser or directly on the micro:bit V2 with an [Arcade shield accessory](#arcade-shields-for-microbit-v2). +Microsoft MicroCode is an icon-based programming language and editor for young learners to code with the [BBC micro:bit V2](https://microbit.org). -## Happy/Sad program +MicroCode allows you to program the micro:bit V2 with only an [Arcade shield accessory](#arcade-shields-for-microbit-v2) - no other computer is required! If you prefer the web browser, there's also a MicroCode web app that connects to your micro:bit V2 over WebUSB. Here's the classic micro:bit *Happy-A-button/Sad-B-button* program in MicroCode: From 522e67357cf81adb15c4cf935ff2ab2103245b01 Mon Sep 17 00:00:00 2001 From: Tom Ball Date: Tue, 19 Sep 2023 15:01:35 -0700 Subject: [PATCH 3/3] Update README.md --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 9de02704..11ecfba4 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,6 @@ ## Microsoft MicroCode [https://aka.ms/microcode](https://aka.ms/microcode) -Microsoft MicroCode is an icon-based programming language and editor for young learners to code with the [BBC micro:bit V2](https://microbit.org). - -MicroCode allows you to program the micro:bit V2 with only an [Arcade shield accessory](#arcade-shields-for-microbit-v2) - no other computer is required! If you prefer the web browser, there's also a MicroCode web app that connects to your micro:bit V2 over WebUSB. - -Here's the classic micro:bit *Happy-A-button/Sad-B-button* program in MicroCode: +Microsoft MicroCode is an icon-based programming language and editor for young learners to code with the [BBC micro:bit V2](https://microbit.org). MicroCode allows you to program the micro:bit V2 with only an [Arcade shield accessory](#arcade-shields-for-microbit-v2) - *no other computer is required!* If you prefer the web browser, there's also a MicroCode web app that connects to your micro:bit V2 over WebUSB. Here's the classic micro:bit *Happy-A-button/Sad-B-button* program in MicroCode: ![MicroCode screenshot](./docs/images/generated/sample_smiley_buttons.png)