Skip to content

Commit

Permalink
more clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mayarajan3 committed Feb 9, 2025
1 parent aa28185 commit 1dc26b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 163 deletions.
8 changes: 3 additions & 5 deletions extensions/src/doodlebot/Doodlebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,6 @@ export default class Doodlebot {
console.log(this.wholeString);
}


i = 0;
wholeString = "export const allLines = [";
cumulativeLine = "export const cumulativeLines = [";

Expand All @@ -645,7 +643,7 @@ export default class Doodlebot {
line;
lineCounter = 0;
detector;
j = 0;
iterationNumber = 0;

deepEqual = (a, b) => {
if (a === b) return true;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}

Expand Down
159 changes: 1 addition & 158 deletions extensions/src/doodlebot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1dc26b0

Please sign in to comment.