From 1dc26b07a43ec40a262743d654214eace44252d2 Mon Sep 17 00:00:00 2001 From: Maya Rajan Date: Sun, 9 Feb 2025 00:17:28 -0500 Subject: [PATCH] more clean up --- extensions/src/doodlebot/Doodlebot.ts | 8 +- extensions/src/doodlebot/index.ts | 159 +------------------------- 2 files changed, 4 insertions(+), 163 deletions(-) diff --git a/extensions/src/doodlebot/Doodlebot.ts b/extensions/src/doodlebot/Doodlebot.ts index f1de1cc54..8892c9a75 100644 --- a/extensions/src/doodlebot/Doodlebot.ts +++ b/extensions/src/doodlebot/Doodlebot.ts @@ -635,8 +635,6 @@ export default class Doodlebot { console.log(this.wholeString); } - - i = 0; wholeString = "export const allLines = ["; cumulativeLine = "export const cumulativeLines = ["; @@ -645,7 +643,7 @@ export default class Doodlebot { line; lineCounter = 0; detector; - j = 0; + iterationNumber = 0; deepEqual = (a, b) => { if (a === b) return true; @@ -736,7 +734,7 @@ export default class Doodlebot { } - if (this.j % iterations == 0) { + if (this.iterationNumber % iterations == 0) { newMotorCommands[0].angle = this.limitArcLength(newMotorCommands[0].angle, newMotorCommands[0].radius, 2); // newMotorCommands[0].angle = this.increaseArcLength(newMotorCommands[0].angle, newMotorCommands[0].radius, ); if (newMotorCommands[0].radius < 10) { @@ -788,7 +786,7 @@ export default class Doodlebot { console.error("Error in followLine loop:", error); break; // Optionally, break the loop on error } - this.j = this.j + 1; + this.iterationNumber = this.iterationNumber + 1; } } diff --git a/extensions/src/doodlebot/index.ts b/extensions/src/doodlebot/index.ts index 7aea5cd56..1cab90079 100644 --- a/extensions/src/doodlebot/index.ts +++ b/extensions/src/doodlebot/index.ts @@ -252,167 +252,10 @@ export default class DoodlebotBlocks extends extension(details, "ui", "indicator await this.doodlebot?.motorCommand("stop"); } - prependUntilTarget = (line) => { - const targetX = line[0][0]; - const targetY = line[0][1]; - const startX = line[0][0]; - const startY = 0; // Start slightly below targetY - - - const incrementX = 0.01; // Small step for x - let x = startX; - let y = startY; - - const newSegment = []; - while (y < targetY) { - newSegment.push([x, y]); - y += incrementX; // Increment y based on slope - } - - // Prepend the new segment to the beginning of line - line.unshift(...newSegment); - return line; - } - - async followLine() { - - const delay = 0.5; - const previousSpeed = 0.1; - - const lineData = [line0, line1, line2, line3, line4, line5, line6, line7, line8]; - - const beforeLine = this.prependUntilTarget(lineData[0]); - const allCommands = []; - - let prevRadius: number; - let prevAngle: number; - let prevTravel: number; - let { motorCommands, bezierPoints, line } = followLine(beforeLine, lineData[0], lineData[1], delay, previousSpeed, [], [], [], true, true); - console.log("here"); - for (const command of motorCommands) { - const { radius, angle } = command; - let { travelT, priorTravelSpeed, targetSpeed, acceleration, adjustedT, aT } = calculateArcTime(0, 0, radius, angle); - this.doodlebot.sendBLECommand("t", radius, angle); - //await this.doodlebot.motorCommand("arc", radius, angle); - prevTravel = travelT; - prevRadius = radius; - prevAngle = angle; - console.log("command"); - console.log(command); - allCommands.push(command); - } - - await new Promise((resolve) => setTimeout(resolve, (prevTravel / 2) * 1000)); - ({ motorCommands, bezierPoints, line } = followLine(line, lineData[1], lineData[2], delay, previousSpeed, motorCommands, [prevTravel / 2], [prevTravel], true)); - //({ motorCommands, bezierPoints, line } = followLine(line, lineData[1], lineData[2], delay, previousSpeed, motorCommands, [prevTravel], [prevTravel], true)); - //await new Promise((resolve) => setTimeout(resolve, (prevTravel + 2) * 1000)); - for (const command of motorCommands) { - const { radius, angle } = command; - let { travelT, priorTravelSpeed, targetSpeed, acceleration, adjustedT, aT } = calculateArcTime(prevRadius, prevAngle, radius, angle); - this.doodlebot.sendBLECommand("t", radius, angle); - //await this.doodlebot.motorCommand("arc", radius, angle); - prevTravel = travelT; - prevRadius = radius; - prevAngle = angle; - console.log("command"); - console.log(command); - allCommands.push(command); - } - - await new Promise((resolve) => setTimeout(resolve, (prevTravel / 2) * 1000)); - ({ motorCommands, bezierPoints, line } = followLine(line, lineData[2], lineData[3], delay, previousSpeed, motorCommands, [prevTravel / 2], [prevTravel], true)); - //({ motorCommands, bezierPoints, line } = followLine(line, lineData[2], lineData[3], delay, previousSpeed, motorCommands, [prevTravel], [prevTravel], true)); - //await new Promise((resolve) => setTimeout(resolve, (prevTravel + 2) * 1000)); - for (const command of motorCommands) { - const { radius, angle } = command; - let { travelT, priorTravelSpeed, targetSpeed, acceleration, adjustedT, aT } = calculateArcTime(prevRadius, prevAngle, radius, angle); - this.doodlebot.sendBLECommand("t", radius, angle); - //await this.doodlebot.motorCommand("arc", radius, angle); - prevTravel = travelT; - prevRadius = radius; - prevAngle = angle; - console.log("command"); - console.log(command); - allCommands.push(command); - } - - await new Promise((resolve) => setTimeout(resolve, (prevTravel / 2) * 1000)); - ({ motorCommands, bezierPoints, line } = followLine(line, lineData[3], lineData[4], delay, previousSpeed, motorCommands, [prevTravel / 2], [prevTravel], true)); - //({ motorCommands, bezierPoints, line } = followLine(line, lineData[3], lineData[4], delay, previousSpeed, motorCommands, [prevTravel], [prevTravel], true)); - //await new Promise((resolve) => setTimeout(resolve, (prevTravel + 2) * 1000)); - for (const command of motorCommands) { - const { radius, angle } = command; - let { travelT, priorTravelSpeed, targetSpeed, acceleration, adjustedT, aT } = calculateArcTime(prevRadius, prevAngle, radius, angle); - this.doodlebot.sendBLECommand("t", radius, angle); - //await this.doodlebot.motorCommand("arc", radius, angle); - prevTravel = travelT; - prevRadius = radius; - prevAngle = angle; - console.log("command"); - console.log(command); - allCommands.push(command); - } - - await new Promise((resolve) => setTimeout(resolve, (prevTravel / 2) * 1000)); - ({ motorCommands, bezierPoints, line } = followLine(line, lineData[4], lineData[5], delay, previousSpeed, motorCommands, [prevTravel / 2], [prevTravel], true)); - //({ motorCommands, bezierPoints, line } = followLine(line, lineData[4], lineData[5], delay, previousSpeed, motorCommands, [prevTravel], [prevTravel], true)); - //await new Promise((resolve) => setTimeout(resolve, (prevTravel + 2) * 1000)); - for (const command of motorCommands) { - const { radius, angle } = command; - let { travelT, priorTravelSpeed, targetSpeed, acceleration, adjustedT, aT } = calculateArcTime(prevRadius, prevAngle, radius, angle); - this.doodlebot.sendBLECommand("t", radius, angle); - //await this.doodlebot.motorCommand("arc", radius, angle); - prevTravel = travelT; - prevRadius = radius; - prevAngle = angle; - console.log("command"); - console.log(command); - allCommands.push(command); - } - - await new Promise((resolve) => setTimeout(resolve, (prevTravel / 2) * 1000)); - ({ motorCommands, bezierPoints, line } = followLine(line, lineData[5], lineData[6], delay, previousSpeed, motorCommands, [prevTravel / 2], [prevTravel], true)); - //({ motorCommands, bezierPoints, line } = followLine(line, lineData[5], lineData[6], delay, previousSpeed, motorCommands, [prevTravel], [prevTravel], true)); - //await new Promise((resolve) => setTimeout(resolve, (prevTravel + 2) * 1000)); - for (const command of motorCommands) { - const { radius, angle } = command; - let { travelT, priorTravelSpeed, targetSpeed, acceleration, adjustedT, aT } = calculateArcTime(prevRadius, prevAngle, radius, angle); - this.doodlebot.sendBLECommand("t", radius, angle); - //await this.doodlebot.motorCommand("arc", radius, angle); - prevTravel = travelT; - prevRadius = radius; - prevAngle = angle; - console.log("command"); - console.log(command); - allCommands.push(command); - } - - // for (let i = 0; i < allCommands.length - 1; i++) { - // let command1 = allCommands[i]; - // let { radius: radius1, angle: angle1 } = command1; - - // let command2 = allCommands[i + 1]; - // let { radius: radius2, angle: angle2 } = command2; - - // console.log(calculateArcTime(radius1, angle1, radius2, angle2)); - // let { travelT, priorTravelSpeed, targetSpeed, acceleration, adjustedT, aT } = calculateArcTime(radius1, angle1, radius2, angle2); - // console.log("Travel time is less than 0.01 seconds. Waiting..."); - // await new Promise((resolve) => setTimeout(resolve, (travelT/2) * 1000)); - // } - - } - - @block({ - type: "command", - text: "test line follow" - }) - async testLine() { - await this.followLine(); - } @block({ type: "command", - text: "test line follow 2" + text: "Test line follow" }) async testLine2() { await this.doodlebot.followLine();