From 1552eb05b47af3b67cadb3203223eaf6b80d575f Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 8 Jan 2018 14:43:15 -0800 Subject: [PATCH 1/2] matter most info --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e3bb7798..fa3251c5 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ This repo contains the editor target hosted at https://d541eec2-1e96-4b7b-a223-da9d01d0337a.pxt.io/ -Issue tracker: https://src.education.lego.com/groups/ev3-makecode +LEGO Auth: https://src.education.lego.com/groups/ev3-makecode (use Google Authenticator) +LEGO Chat: https://chat.internal.education.lego.com/make-code/channels/town-square ## Local Dev setup From b5ad898c9ec815fd8c3a60107593156bc55243ad Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 8 Jan 2018 15:00:00 -0800 Subject: [PATCH 2/2] Screentweak (#214) * adding pid * hiding functions * precision of value --- docs/examples/line-follower-pid.md | 36 +++++++++++++++++++++++++++++- libs/core/screen.ts | 10 ++++----- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/docs/examples/line-follower-pid.md b/docs/examples/line-follower-pid.md index fb8c5ca1..f2efb567 100644 --- a/docs/examples/line-follower-pid.md +++ b/docs/examples/line-follower-pid.md @@ -1,3 +1,4 @@ +# Gradien follower PID + calibration ```blocks let lasterror = 0 @@ -5,12 +6,45 @@ let D = 0 let I = 0 let P = 0 let error = 0 +let setpoint = 0 +let max = 0 +let min = 0 +let v = 0 +v = sensors.color3.light(LightIntensityMode.Reflected) +min = v +max = v +setpoint = v +while (!(brick.buttonEnter.wasPressed())) { + brick.clearScreen() + brick.showString("Move robot on terrain", 1) + brick.showString("Press ENTER when done", 2) + v = sensors.color3.light(LightIntensityMode.Reflected) + min = Math.min(min, v) + max = Math.max(max, v) + setpoint = (max + min) / 2 + brick.showValue("v", v, 3) + brick.showValue("min", min, 4) + brick.showValue("max", v, 5) + brick.showValue("setpoint", setpoint, 6) + loops.pause(100) +} loops.forever(function () { - error = sensors.color3.light(LightIntensityMode.Reflected) - 35 + brick.clearScreen() + v = sensors.color3.light(LightIntensityMode.Reflected) + brick.showValue("light", v, 1) + error = v - setpoint + brick.showValue("error", error, 2) P = error * 5 + brick.showValue("P", P, 3) I = I + error * 0.01 + brick.showValue("I", I, 4) D = (error - lasterror) * 0.2 + brick.showValue("D", D, 5) motors.largeBC.steer(P + (I + D), 100) lasterror = error + if (brick.buttonEnter.wasPressed()) { + motors.largeBC.setSpeed(0) + brick.buttonDown.pauseUntil(ButtonEvent.Click) + } }) ``` \ No newline at end of file diff --git a/libs/core/screen.ts b/libs/core/screen.ts index 61f6690e..b87d3156 100644 --- a/libs/core/screen.ts +++ b/libs/core/screen.ts @@ -58,7 +58,7 @@ namespace brick { } } - export function setPixel(on: boolean, x: number, y: number) { + function setPixel(on: boolean, x: number, y: number) { x |= 0 y |= 0 if (0 <= x && x < DAL.LCD_WIDTH && 0 <= y && y < DAL.LCD_HEIGHT) @@ -101,6 +101,7 @@ namespace brick { //% weight=96 group="Screen" inlineInputMode="inline" blockGap=8 //% line.min=1 line.max=10 export function showValue(name: string, value: number, line: number) { + value = Math.round(value * 1000) / 1000; showString((name ? name + ": " : "") + value, line); } @@ -140,12 +141,9 @@ namespace brick { */ //% blockId=screen_show_image block="show image %image=screen_image_picker" //% weight=100 group="Screen" blockGap=8 - export function showImage(image: Image, delay: number = 400) { + export function showImage(image: Image) { if (!image) return; image.draw(0, 0, Draw.Normal); - delay = Math.max(0, delay); - if (delay > 0) - loops.pause(delay); } /** @@ -170,7 +168,7 @@ namespace brick { screen.clear(); } - export function drawRect(x: number, y: number, w: number, h: number, mode = Draw.Normal) { + function drawRect(x: number, y: number, w: number, h: number, mode = Draw.Normal) { x |= 0; y |= 0; w |= 0;