Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
145 commits
Select commit Hold shift + click to select a range
e70e63d
Scaffolding project
pmalacho-mit Jan 4, 2024
23e8c57
setting up websocket side
pmalacho-mit Jan 5, 2024
48c9700
Added connection UI
pmalacho-mit Jan 10, 2024
58eeeeb
adding comment guards
pmalacho-mit Feb 4, 2024
5eefc27
Merge pull request #331 from mitmedialab/dev
pmalacho-mit Feb 4, 2024
f4e97ae
Merge branch 'main' into doodlebot_port
pmalacho-mit Feb 5, 2024
9de0ca3
fixing indicator error. Adding display blocks
pmalacho-mit Feb 5, 2024
e5cd97f
Adding some log statements on receive BLE
pmalacho-mit Feb 6, 2024
167084a
adding some more logging. changing default motor command
pmalacho-mit Feb 6, 2024
a5527d5
fixed command parser
pmalacho-mit Feb 6, 2024
12a10d4
fixing indicator
pmalacho-mit Feb 6, 2024
ba7011e
Adding storing passwords into local storage -- this a little question…
pmalacho-mit Feb 6, 2024
c8aa1df
setting steps per second to 2000
pmalacho-mit Feb 6, 2024
673b0f7
adding debug statements
pmalacho-mit Feb 6, 2024
be85fe9
Merge branch 'dev' into doodlebot_port
pmalacho-mit Apr 9, 2024
339eb61
trying to accomodate ip override
pmalacho-mit Apr 9, 2024
af7abd0
implemented most ble commands. working towards network commands
pmalacho-mit Apr 26, 2024
786d95d
Added bumper blocks and fixed arc block
pmalacho-mit Apr 26, 2024
db784a3
rethinking connection workflow
pmalacho-mit Apr 27, 2024
88139f7
allowing for ip based connection
pmalacho-mit Apr 27, 2024
4ce2d87
updating connection workflow
pmalacho-mit Apr 29, 2024
ea0b80d
audio recording works
pmalacho-mit Apr 29, 2024
3215ed7
added few missing commands, like play sound and display text
pmalacho-mit Apr 29, 2024
abd2069
Set up hand detection
pmalacho-mit Apr 29, 2024
4008e60
Adding performance logging
pmalacho-mit Apr 29, 2024
9ccf7d7
Adding in spin to object functionality
pmalacho-mit Apr 30, 2024
a39cb80
cleaning up
pmalacho-mit Apr 30, 2024
28da242
merging in scratch-refactor branch
pmalacho-mit Jul 24, 2024
a94455c
updating scratch package versions
pmalacho-mit Jul 24, 2024
d000b3f
Merge branch 'staging' into doodlebot_port-scratch-package-refactor
pmalacho-mit Jul 29, 2024
6cfd533
tracking lockfile
pmalacho-mit Jul 29, 2024
6f044d3
line following code
mayarajan3 Sep 16, 2024
61d6850
it follows ish
mayarajan3 Sep 18, 2024
caed802
correct changes
mayarajan3 Sep 19, 2024
81f4356
packages
mayarajan3 Sep 19, 2024
65ae2ff
new test segments
mayarajan3 Sep 19, 2024
4e56887
added displayLine command
Sep 30, 2024
3a72da5
line detection block
Sep 30, 2024
1eff7cb
updates
mayarajan3 Sep 30, 2024
fb1df19
added html page for testing
Oct 3, 2024
754c4c3
it works
Oct 4, 2024
29851ea
it works
Oct 4, 2024
5dd3257
Merge remote-tracking branch 'origin/line_detection_2' into line_comm…
mayarajan3 Oct 4, 2024
4ff3b6c
testing
mayarajan3 Oct 9, 2024
23fdd14
fix bug
mayarajan3 Oct 9, 2024
187a273
change
mayarajan3 Oct 17, 2024
e06d4fb
cleaning code
mayarajan3 Nov 1, 2024
469858c
more cleaning
mayarajan3 Nov 1, 2024
3d91321
commenting
mayarajan3 Nov 1, 2024
a8ac2d5
more comments
mayarajan3 Nov 1, 2024
08a2a47
naming
mayarajan3 Nov 1, 2024
cc8ca5c
minor fix
mayarajan3 Nov 1, 2024
1ec554b
testing on bot
mayarajan3 Nov 3, 2024
f2808a9
testing points
mayarajan3 Nov 3, 2024
50c7268
errors
mayarajan3 Nov 3, 2024
7d0d507
testing on bot
mayarajan3 Nov 5, 2024
3461646
curve matcher
mayarajan3 Nov 8, 2024
77ac62e
Merge branch 'line_commands_test' of github.com:mitmedialab/prg-raise…
mayarajan3 Nov 8, 2024
6a73e15
integrate cv
mayarajan3 Nov 8, 2024
8795144
commenting cv
mayarajan3 Nov 8, 2024
cb9562a
updated brandon code
mayarajan3 Nov 9, 2024
96b5671
integration updates
mayarajan3 Nov 10, 2024
a73a892
dealing with straight lines
mayarajan3 Nov 12, 2024
f67bd02
fixed integration
Nov 14, 2024
326243b
improved line detection
Nov 14, 2024
5552aef
updates
mayarajan3 Nov 14, 2024
c522ac9
arc
mayarajan3 Nov 14, 2024
38a61f5
correct algorithm
mayarajan3 Nov 14, 2024
96773d6
arc function
mayarajan3 Nov 17, 2024
4b8b16e
fixed line detection
Nov 18, 2024
d1ac252
sunday driving
mayarajan3 Nov 19, 2024
ce2cbc9
Merge branch 'line_commands_integrated' of github.com:mitmedialab/prg…
mayarajan3 Nov 19, 2024
1c62aa6
oooooh
mayarajan3 Nov 21, 2024
835a130
added debug
Nov 21, 2024
2212b4b
only one image
Nov 21, 2024
9588714
used get image stream
Nov 21, 2024
ba883cd
interval
mayarajan3 Nov 21, 2024
0f606dd
merge
mayarajan3 Nov 21, 2024
5e58e4d
image stream called only once
Nov 21, 2024
7fec05d
Merge branch 'line_commands_integrated' of github-research:mitmediala…
Nov 21, 2024
33a2946
ensuring extension and linedetector use the same stream
pmalacho-mit Nov 21, 2024
2301de1
interval
mayarajan3 Nov 21, 2024
47af9cf
good sorta
Nov 21, 2024
1d68981
stop
mayarajan3 Nov 21, 2024
9c8e848
merge
mayarajan3 Nov 21, 2024
0a79d25
nice
Nov 21, 2024
604964a
crisis averted
mayarajan3 Nov 23, 2024
5f44627
more
mayarajan3 Nov 23, 2024
04e380a
teachable machine - loading model works, image recognition could be b…
Dec 6, 2024
23f20e1
upgrading gui version
pmalacho-mit Dec 8, 2024
4ab248d
incrementing pnpm version in build step
pmalacho-mit Dec 8, 2024
c57ba37
adding in support for external BLE
pmalacho-mit Dec 9, 2024
3679c04
Got the 2-way communication working
pmalacho-mit Dec 10, 2024
7b6e5b5
ensuring only the ip is required
pmalacho-mit Dec 10, 2024
828bbaf
adding commands
mayarajan3 Dec 15, 2024
69a2bff
add image capture
Dec 16, 2024
7cb8371
added doodlebot image capture
Dec 16, 2024
548eb5d
testing chat api
mayarajan3 Jan 6, 2025
8eafdbe
additional test
mayarajan3 Jan 7, 2025
22d49ee
test endpoint
mayarajan3 Jan 13, 2025
2df3dc2
test health
mayarajan3 Jan 13, 2025
bad9754
chat test
mayarajan3 Jan 13, 2025
5275724
new testing with recording
mayarajan3 Jan 13, 2025
5e7fcd0
wss
mayarajan3 Jan 13, 2025
02994be
ws
mayarajan3 Jan 13, 2025
47cc372
fine tuning
mayarajan3 Jan 25, 2025
ff9b9c8
a good place
mayarajan3 Jan 26, 2025
28a62bd
progress
mayarajan3 Jan 27, 2025
2c30c90
working
mayarajan3 Jan 27, 2025
12f61ce
updates
mayarajan3 Jan 27, 2025
255de60
websocket
mayarajan3 Jan 27, 2025
fb4ad9e
progress
mayarajan3 Jan 29, 2025
6eaa970
update model loading
Jan 30, 2025
9bf01fc
Merge branch 'curriculum' of github-research:mitmedialab/prg-raise-pl…
Jan 30, 2025
37af236
today changes
mayarajan3 Jan 30, 2025
4692b5f
fix chat api post params
Jan 30, 2025
1fb06ed
new
mayarajan3 Jan 30, 2025
9382cfd
progress
mayarajan3 Feb 1, 2025
aa15d8e
it works
mayarajan3 Feb 2, 2025
56e8f4f
progress
mayarajan3 Feb 3, 2025
27bc66b
changes
mayarajan3 Feb 3, 2025
f6f6388
add confidence
Feb 3, 2025
7985c3d
demo work
mayarajan3 Feb 4, 2025
6f6da4d
Merge branch 'curriculum' into line_following_demo
mayarajan3 Feb 5, 2025
33a33f3
chan ges
mayarajan3 Feb 5, 2025
e85f2fc
Merge branch 'line_following_demo' of github.com:mitmedialab/prg-rais…
mayarajan3 Feb 5, 2025
a17ba15
chat feature
mayarajan3 Feb 5, 2025
aa28185
clean up
mayarajan3 Feb 9, 2025
1dc26b0
more clean up
mayarajan3 Feb 9, 2025
48527d2
added visual states and seconds parameter
Feb 11, 2025
b6f27c9
more fixes
mayarajan3 Feb 12, 2025
5792239
Merge pull request #390 from mitmedialab/line_following_cleanup
mayarajan3 Feb 12, 2025
b1302d4
test
mayarajan3 Feb 13, 2025
01c8dbc
Merge pull request #393 from mitmedialab/curriculum-facedisplay
mayarajan3 Feb 13, 2025
b476060
one more change
mayarajan3 Feb 13, 2025
80577fd
Merge pull request #394 from mitmedialab/curriculum-facedisplay
mayarajan3 Feb 13, 2025
a384808
invert frame
mayarajan3 Feb 26, 2025
fc1e196
remove faces
mayarajan3 Mar 13, 2025
84470ec
commented out un-needed blocks and took out expressions
Mar 22, 2025
ca35ee9
debug statements
mayarajan3 Mar 24, 2025
6dd40d8
added SOCIAL
Mar 25, 2025
f5b5438
more debug
mayarajan3 Mar 26, 2025
53750c5
day 1 lock
Mar 28, 2025
96e3456
day 2 lock
Mar 30, 2025
c20a354
added repeat after me block
Apr 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
node-version: ${{ matrix.node-version }}
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9.1.2
- name: install & build
run: pnpm build
env:
Expand Down
149 changes: 149 additions & 0 deletions LineDetection.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Line Detection</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; }
#outputImage { max-width: 100%; height: auto; border: 1px solid #ddd; }
#controls { margin: 20px 0; }
#ipInput { padding: 5px; width: 200px; }
button { padding: 5px 10px; cursor: pointer; }
</style>
<script>
const port = { camera: 8000 };
const endpoint = { video: 'video_feed' };

let collectLine = false;

class LineDetector {
constructor(raspberryPiIp, width = 640, height = 480) {
this.raspberryPiIp = raspberryPiIp;
this.width = width;
this.height = height;
this.canvas = document.createElement('canvas');
this.canvas.width = width;
this.canvas.height = height;
this.ctx = this.canvas.getContext('2d');
this.lastDetectedLine = [];
this.frameCount = 0;
this.allCoordinates = [];
}

async detectLine() {
try {
const image = await this.loadImage(`http://${this.raspberryPiIp}:${port.camera}/${endpoint.video}`);
this.ctx.drawImage(image, 0, 0, this.width, this.height);
const imageData = this.ctx.getImageData(0, 0, this.width, this.height);
const lineCoordinates = this.processImageData(imageData);
console.log("coordinates");
console.log(lineCoordinates);
if (lineCoordinates.length > 0) {
this.lastDetectedLine = lineCoordinates;
}

if (collectLine) {
this.allCoordinates.push(lineCoordinates);
this.frameCount++;
this.writeCoordinatesToFile(this.allCoordinates);
collectLine = false;
}

this.drawLine(this.lastDetectedLine);
return this.canvas.toDataURL();
} catch (error) {
console.error('Error detecting line:', error);
return null;
}
}

loadImage(src) {
return new Promise((resolve, reject) => {
const img = new Image();
img.crossOrigin = "Anonymous";
img.onload = () => resolve(img);
img.onerror = reject;
img.src = src;
});
}

processImageData(imageData) {
const lineCoordinates = [];
const threshold = 70;

for (let y = 0; y < this.height; y++) {
for (let x = 0; x < this.width; x++) {
const index = (y * this.width + x) * 4;
const [r, g, b] = imageData.data.slice(index, index + 3);

if (r < threshold && g < threshold && b < threshold && y < 400) {
lineCoordinates.push([x, y]);
}
}
}
return lineCoordinates.sort((a, b) => a[1] - b[1]);
}

drawLine(coordinates) {
this.ctx.beginPath();
this.ctx.strokeStyle = 'blue';
this.ctx.lineWidth = 2;
coordinates.forEach(([x, y], i) => {
this.ctx.arc(x, y, 5, 0, Math.PI*2);
});
this.ctx.stroke();
}

writeCoordinatesToFile(allCoordinates) {
const content = allCoordinates.map((frame, index) =>
`export const baseLine = [${frame.map(coord => ("[" + coord.join(',') + "]"))}]\n`
);
const blob = new Blob([content], { type: 'text/plain' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'iterations.txt';
a.click();
URL.revokeObjectURL(a.href);
}
}

let detector;
let updateInterval;

function initializeDetector() {
const raspberryPiIp = document.getElementById('ipInput').value;
if (!raspberryPiIp) {
alert('Please enter a valid IP address');
return;
}
detector = new LineDetector(raspberryPiIp);
clearInterval(updateInterval);
updateImage();
updateInterval = setInterval(updateImage, 500);
}

function collectLineFn() {
collectLine = true;
}

async function updateImage() {
if (detector) {
const imageDataUrl = await detector.detectLine();
if (imageDataUrl) {
document.getElementById('outputImage').src = imageDataUrl;
}
}
}
</script>
</head>
<body>
<h1>Line Detection</h1>
<div id="controls">
<input type="text" id="ipInput" placeholder="IP Address">
<button onclick="initializeDetector()">Start Detection</button>
<button onclick="collectLineFn()">Collect Points</button>
</div>
<img id="outputImage" alt="Processed Image">
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type Renderer = {
destroyDrawable(drawableID: Handle, group: string): void;
}

type Drawable = ImageBitmap | Parameters<Renderer["createBitmapSkin"]>[0];

/**
* Mixin the ability for extensions to draw images into the canvas
* @param Ctor
Expand All @@ -75,12 +77,13 @@ export default function <T extends MinimalExtensionConstructor>(Ctor: T) {
* @param {ImageData | ImageBitmap} image
* @returns
*/
protected createDrawable<T extends ImageData | ImageBitmap>(image: T) {
protected createDrawable<T extends ImageBitmap | Drawable>(image: T) {
this.renderer ??= this.runtime.renderer;
const { renderer } = this;

if (!renderer) return null;


const skin = renderer.createBitmapSkin(image as ImageData, 1);
const drawable = renderer.createDrawable(StageLayering.VideoLayer);

Expand All @@ -92,7 +95,7 @@ export default function <T extends MinimalExtensionConstructor>(Ctor: T) {
const setVisible = (visible: boolean = true) =>
renderer.updateDrawableVisible(drawable, visible);

const update = (image: ImageData | ImageBitmap) =>
const update = (image: Drawable) =>
renderer.updateBitmapSkin(skin, image as ImageData, 1);

const destroy = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { untilTimePassed } from "$common/utils";
import { MinimalExtensionConstructor } from "../../base";
import { isSvgGroup, isSvgText, openAlert } from "./svgAlert";

type IndicatorPayload = { position?: "category", msg: string, type?: "success" | "warning" | "error" };
export type IndicatorPayload = { position?: "category", msg: string, type?: "success" | "warning" | "error", retry?: boolean };

/**
* Mixin the ability for extensions to add an indicator message to the workspace.
Expand All @@ -22,13 +22,20 @@ export default function <T extends MinimalExtensionConstructor>(Ctor: T) {
* - `type`: The type of indicator to display. Currently "success", "warning" and "error", which effect the color of the indicator.
* @returns
*/
async indicate({ position = "category", msg, type = "success" }: IndicatorPayload) {

async indicate({ position = "category", msg, type = "success", retry = false }: IndicatorPayload): ReturnType<typeof openAlert> {
const elements = position === "category"
? getCategoryElements(this.name)
: { error: "Unsupported indicator position" };

if ("error" in elements) throw new Error(elements.error);
if ("error" in elements) {
if (retry) {
await untilTimePassed(100);
const retried = await this.indicate({ position, msg, type, retry: false });
return retried;
}
else throw new Error(elements.error);
}

const { container } = elements;
const alert = await openAlert(container, msg, type);
return alert;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { IndicatorPayload } from ".";
import { ExtensionInstanceWithFunctionality } from "../..";

export const isSvgGroup = (element: Element): element is SVGGElement => element.nodeName === "g";
export const isSvgText = (element: Element): element is SVGTextElement => element.nodeName === "text";

type AlertType = Parameters<ExtensionInstanceWithFunctionality<["indicators"]>["indicate"]>[0]["type"];
type AlertType = IndicatorPayload["type"];

const fills = {
success: "#5ACA75",
Expand Down
8 changes: 7 additions & 1 deletion extensions/src/common/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ export type ExpandRecursively<T> = T extends (...args: infer A) => infer R
? T extends infer O
? { [K in keyof O]: ExpandRecursively<O[K]> }
: never
: T;
: T;

export type ReverseMap<T extends Record<keyof T, keyof any>> = {
[P in T[keyof T]]: {
[K in keyof T]: T[K] extends P ? K : never
}[keyof T]
}
Loading
Loading