Skip to content

Commit

Permalink
Merge branch 'line_commands_integrated' of github-research:mitmediala…
Browse files Browse the repository at this point in the history
…b/prg-raise-playground into line_commands_integrated
  • Loading branch information
Brandon Lei authored and Brandon Lei committed Nov 21, 2024
2 parents 5e58e4d + 0f606dd commit 7fec05d
Showing 1 changed file with 61 additions and 38 deletions.
99 changes: 61 additions & 38 deletions extensions/src/doodlebot/Doodlebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,52 +644,75 @@ export default class Doodlebot {
lineCounter = 0;
detector;
async followLine() {

let first = true;
const delay = 0.5;
const previousSpeed = 0.1;
const interval = 1000 / 2; // 1/15th of a second

while (true) {
try {
console.log("before 1");
let lineData = await this.detector.detectLine(this); // Await works here
console.log("after 1");

// Process line data
lineData = lineData.sort((a, b) => a[1] - b[1]);
console.log("LINE DATA", lineData);

if (first) {
({ motorCommands: this.motorCommands, bezierPoints: this.bezierPoints, line: this.line } = followLine(
lineData,
lineData,
null,
delay,
previousSpeed,
[],
[],
[],
false,
true
));
first = false;
} else {
({ motorCommands: this.motorCommands, bezierPoints: this.bezierPoints, line: this.line } = followLine(
this.line,
lineData,
null,
delay,
previousSpeed,
this.motorCommands,
[1.1 / 2],
[1],
false,
false
));
}

let lineString = "";
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
// for (let j = 0; j < 20; j++) {
// try {
// await sleep(1000);
console.log("before 1");
let lineData = await this.detector.detectLine(this);
console.log("after 1");
//lineData = lineData.map(pixel => [640 - pixel[0], 480 - pixel[1]])
lineData = lineData.sort((a, b) => a[1] - b[1]);
//const lineDataString = `export const line${lineCounter} = ${JSON.stringify(lineData)};\n`;
//lineString += lineDataString;
//console.log(lineString);
//lineCounter += 1;
console.log(this.connection.ip);
console.log("LINE DATA", lineData);
console.log("before");
if (first) {
({ motorCommands: this.motorCommands, bezierPoints: this.bezierPoints, line: this.line } = followLine(lineData, lineData, null, delay, previousSpeed, [], [], [], false, true));
first = false;
} else {
({ motorCommands: this.motorCommands, bezierPoints: this.bezierPoints, line: this.line } = followLine(this.line, lineData, null, delay, previousSpeed, this.motorCommands, [1], [1], false, false));
}
console.log("after");
for (const command of this.motorCommands) {
const { radius, angle } = command;
console.log(command);
console.log("after");
for (const command of this.motorCommands) {
const { radius, angle } = command;
console.log(command);
this.sendBLECommand("t", radius, angle);
}
console.log("after 2");

this.motorCommand("arc", radius, angle);
// Wait for the interval duration before the next iteration
await new Promise((resolve) => setTimeout(resolve, interval));
} catch (error) {
console.error("Error in followLine loop:", error);
break; // Optionally, break the loop on error
}
}
console.log("after 2");
//console.log(j);
// Process the line data here
}
//console.log(j);
// Process the line data here

// } catch (error) {
// console.error("Error detecting line:", error);
// // Optionally stop polling if there's a consistent error
// }
// }
// } catch (error) {
// console.error("Error detecting line:", error);
// // Optionally stop polling if there's a consistent error
// }
// }

}


private setupAudioStream() {
Expand Down

0 comments on commit 7fec05d

Please sign in to comment.