Skip to content

Commit

Permalink
smoother turns
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Sep 28, 2023
1 parent d8acc0d commit b72c1d8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
7 changes: 4 additions & 3 deletions robot/cutebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions robot/pxt.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "microcode-robot",
"version": "2.4.41",
"dependencies": {
"core": "*",
"radio": "*"
Expand All @@ -25,6 +26,5 @@
"supportedTargets": [
"microbit"
],
"preferredEditor": "tsprj",
"version": "2.4.41"
"preferredEditor": "tsprj"
}
10 changes: 10 additions & 0 deletions robot/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -16,3 +25,4 @@ basic.forever(() => {
microcode.robotDriver.motorStop()
}
})
*/

0 comments on commit b72c1d8

Please sign in to comment.