diff --git a/robot/cutebot.ts b/robot/cutebot.ts index 25a23c68..ddbb65e8 100644 --- a/robot/cutebot.ts +++ b/robot/cutebot.ts @@ -3,7 +3,7 @@ namespace microcode { //https://github.com/elecfreaks/pxt-cutebot/blob/master/cutebot.ts function motors(lspeed: number, rspeed: number): void { - let buf = pins.createBuffer(4) + const buf = pins.createBuffer(4) /* if (lspeed > 100) { lspeed = 100; @@ -87,8 +87,9 @@ namespace microcode { } motorTurn(speed: number) { - if (speed > 0) motors(speed, 0) - else motors(0, -speed) + const op = Math.abs(speed) >> 1 + if (speed > 0) motors(speed, Math.constrain(this.maxTurnSpeed - speed, 0, op)) + else motors(Math.constrain(this.maxTurnSpeed + speed, 0, op), -speed) } headlightsSetColor(red: number, green: number, blue: number) { diff --git a/robot/pxt.json b/robot/pxt.json index 6d17d2c2..2a2d86b2 100644 --- a/robot/pxt.json +++ b/robot/pxt.json @@ -1,5 +1,6 @@ { "name": "microcode-robot", + "version": "2.4.41", "dependencies": { "core": "*", "radio": "*" @@ -25,6 +26,5 @@ "supportedTargets": [ "microbit" ], - "preferredEditor": "tsprj", - "version": "2.4.41" + "preferredEditor": "tsprj" } diff --git a/robot/test.ts b/robot/test.ts index 61b06910..389c617d 100644 --- a/robot/test.ts +++ b/robot/test.ts @@ -3,6 +3,15 @@ microcode.elecfreaksCuteBot.start() //microcode.keyStudioMiniSmartRobot.start() microcode.setMotorDrift(6) +let speed = 0 +basic.forever(() => { +microcode.robotDriver.motorTurn(speed) + pause(500) + microcode.robotDriver.motorTurn(-speed) + pause(500) + speed = (speed + 1) % microcode.robotDriver.robot.maxTurnSpeed +}) +/* basic.forever(() => { const dist = microcode.robotDriver.ultrasonicDistance() if (dist > 10) microcode.robotDriver.motorRun(100) @@ -16,3 +25,4 @@ basic.forever(() => { microcode.robotDriver.motorStop() } }) +*/ \ No newline at end of file