From 59b0a49139241e2963b91b15a46cdb5fd56e4ba0 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Thu, 25 May 2023 12:19:34 -0400 Subject: Start moving camera to virtual program --- virtual-programs/camera.folk | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 virtual-programs/camera.folk (limited to 'virtual-programs') diff --git a/virtual-programs/camera.folk b/virtual-programs/camera.folk new file mode 100644 index 00000000..40950eb9 --- /dev/null +++ b/virtual-programs/camera.folk @@ -0,0 +1,33 @@ +if {$::isLaptop} return + +On process { + source pi/Camera.tcl + # FIXME: do these in outer scope + Camera::init 1280 720 + puts "Camera tid: [getTid]" + + set grayFrames [list] + while true { + # Hack: we free old images. Really this should be done on + # the main thread when it's actually done with them. + if {[llength $grayFrames] > 10} { + Camera::freeImage [lindex $grayFrames 0] + set grayFrames [lreplace $grayFrames 0 0] + } + set cameraTime [time { set grayFrame [Camera::grayFrame] }] + lappend grayFrames $grayFrame + + Commit camera { + Claim the camera time is $cameraTime + Claim the camera frame is $grayFrame + } + Step + } +} + +# AprilTags::init + # foreach tag $tags { + # Claim tag [dict get $tag id] has center [dict get $tag center] size [dict get $tag size] + # Claim tag [dict get $tag id] has corners [dict get $tag corners] + # } + -- cgit v1.2.3 From f472f8a7a57caef18b282f14bfb08f810ac78775 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Thu, 25 May 2023 23:49:26 -0400 Subject: WIP: Start implementing AprilTag detector. defineFolkImages shm --- virtual-programs/camera.folk | 41 +++++++++++++++--------------- virtual-programs/tags-and-calibration.folk | 5 ++++ 2 files changed, 25 insertions(+), 21 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/camera.folk b/virtual-programs/camera.folk index 40950eb9..4075162c 100644 --- a/virtual-programs/camera.folk +++ b/virtual-programs/camera.folk @@ -1,33 +1,32 @@ if {$::isLaptop} return +namespace eval ::Camera { + variable WIDTH 1280 + variable HEIGHT 720 +} + On process { source pi/Camera.tcl # FIXME: do these in outer scope Camera::init 1280 720 puts "Camera tid: [getTid]" - set grayFrames [list] - while true { - # Hack: we free old images. Really this should be done on - # the main thread when it's actually done with them. - if {[llength $grayFrames] > 10} { - Camera::freeImage [lindex $grayFrames 0] - set grayFrames [lreplace $grayFrames 0 0] - } - set cameraTime [time { set grayFrame [Camera::grayFrame] }] - lappend grayFrames $grayFrame +} - Commit camera { - Claim the camera time is $cameraTime - Claim the camera frame is $grayFrame +On process { + Wish $::nodename receives statements like [list /someone/ claims the camera frame is /frame/] + + source pi/AprilTags.tcl + AprilTags::init + + When the camera frame is /frame/ { + set aprilTime [time { set tags [AprilTags::detect $frame] }] + Commit { + Claim the AprilTag time is $aprilTime + foreach tag $tags { + Claim tag [dict get $tag id] has center [dict get $tag center] size [dict get $tag size] + Claim tag [dict get $tag id] has corners [dict get $tag corners] + } } - Step } } - -# AprilTags::init - # foreach tag $tags { - # Claim tag [dict get $tag id] has center [dict get $tag center] size [dict get $tag size] - # Claim tag [dict get $tag id] has corners [dict get $tag corners] - # } - diff --git a/virtual-programs/tags-and-calibration.folk b/virtual-programs/tags-and-calibration.folk index d6c4fad7..36086099 100644 --- a/virtual-programs/tags-and-calibration.folk +++ b/virtual-programs/tags-and-calibration.folk @@ -2,6 +2,11 @@ Wish $this has filename "tags-and-calibration.folk" if {$::isLaptop} { return } +namespace eval ::Camera { + variable WIDTH 1280 + variable HEIGHT 720 +} + package require math::linearalgebra namespace import ::math::linearalgebra::add \ ::math::linearalgebra::sub \ -- cgit v1.2.3 From 87eff0f909898e4a6180bcca82be3a92869bad1d Mon Sep 17 00:00:00 2001 From: Charles Chamberlain Date: Thu, 1 Jun 2023 15:21:42 -0400 Subject: Fix bug in process naming: choose unique names in same file --- virtual-programs/camera.folk | 1 - 1 file changed, 1 deletion(-) (limited to 'virtual-programs') diff --git a/virtual-programs/camera.folk b/virtual-programs/camera.folk index 4075162c..f161ce11 100644 --- a/virtual-programs/camera.folk +++ b/virtual-programs/camera.folk @@ -10,7 +10,6 @@ On process { # FIXME: do these in outer scope Camera::init 1280 720 puts "Camera tid: [getTid]" - } On process { -- cgit v1.2.3 From ebfbdd3f392e3d327692a159d89b00f96db93106 Mon Sep 17 00:00:00 2001 From: Charles Chamberlain Date: Thu, 1 Jun 2023 16:41:46 -0400 Subject: Getting one camera frame from a thread --- virtual-programs/camera.folk | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'virtual-programs') diff --git a/virtual-programs/camera.folk b/virtual-programs/camera.folk index f161ce11..b82c306d 100644 --- a/virtual-programs/camera.folk +++ b/virtual-programs/camera.folk @@ -10,6 +10,14 @@ On process { # FIXME: do these in outer scope Camera::init 1280 720 puts "Camera tid: [getTid]" + + while true { + set grayFrame [Camera::grayFrame] + Commit { + Claim the camera frame is $grayFrame; + } + Step + } } On process { -- cgit v1.2.3 From f62f3e2d9d06add473fa9b82e8e2697c7904c998 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Mon, 19 Jun 2023 12:39:42 -0400 Subject: WIP: Tag detect on same thread as camera for now. --- virtual-programs/camera.folk | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/camera.folk b/virtual-programs/camera.folk index b82c306d..b865392e 100644 --- a/virtual-programs/camera.folk +++ b/virtual-programs/camera.folk @@ -7,33 +7,31 @@ namespace eval ::Camera { On process { source pi/Camera.tcl - # FIXME: do these in outer scope + source pi/AprilTags.tcl Camera::init 1280 720 + AprilTags::init + puts "Camera tid: [getTid]" while true { - set grayFrame [Camera::grayFrame] - Commit { - Claim the camera frame is $grayFrame; - } - Step - } -} - -On process { - Wish $::nodename receives statements like [list /someone/ claims the camera frame is /frame/] - - source pi/AprilTags.tcl - AprilTags::init - - When the camera frame is /frame/ { - set aprilTime [time { set tags [AprilTags::detect $frame] }] + set cameraTime [time { + set grayFrame [Camera::grayFrame] + }] + set aprilTime [time { + set tags [AprilTags::detect $grayFrame] + }] + Commit { + Claim the camera frame is $grayFrame + + Claim the camera time is $cameraTime Claim the AprilTag time is $aprilTime + foreach tag $tags { Claim tag [dict get $tag id] has center [dict get $tag center] size [dict get $tag size] Claim tag [dict get $tag id] has corners [dict get $tag corners] } } + Step } } -- cgit v1.2.3 From 8ad09e5f697d7fdc739ba16a5c329ac69312e6e4 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Mon, 19 Jun 2023 13:40:19 -0400 Subject: Disable shapes log --- virtual-programs/shapes.folk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'virtual-programs') diff --git a/virtual-programs/shapes.folk b/virtual-programs/shapes.folk index b693220e..455125b9 100644 --- a/virtual-programs/shapes.folk +++ b/virtual-programs/shapes.folk @@ -76,7 +76,7 @@ When /someone/ wishes /p/ draws a /color/ /shape/ offset /offsetVector/ & /p/ ha set y [expr {$y + $offsetY}] } - puts "drawing $shape at $x $y" + # puts "drawing $shape at $x $y" set adjustedWidth [expr {$width * 0.25}] set x [expr { $x * 1.3}] -- cgit v1.2.3 From 4b2679ca8a61ce2edf9b74876df97aa923657872 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 27 Jun 2023 15:39:47 -0400 Subject: Add prefix math ops to language --- virtual-programs/regions.folk | 3 --- 1 file changed, 3 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/regions.folk b/virtual-programs/regions.folk index 1702bbfa..8f320b42 100644 --- a/virtual-programs/regions.folk +++ b/virtual-programs/regions.folk @@ -1,5 +1,4 @@ namespace eval ::vec2 { - namespace import ::tcl::mathop::+ ::tcl::mathop::- ::tcl::mathop::* proc add {a b} { list [+ [lindex $a 0] [lindex $b 0]] [+ [lindex $a 1] [lindex $b 1]] } @@ -21,8 +20,6 @@ namespace eval ::vec2 { proc dot {a b} { expr {[lindex $a 0]*[lindex $b 0] + [lindex $a 1]*[lindex $b 1]} } - namespace import ::tcl::mathfunc::max ::tcl::mathfunc::min - namespace import ::tcl::mathop::/ proc distanceToLineSegment {a v w} { set l2 [vec2 distance $v $w] if {$l2 == 0.0} { -- cgit v1.2.3 From 82d01c81089de61083b0bb52c5525384a38dc964 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 27 Jun 2023 15:40:13 -0400 Subject: Fix error rendering in web editor --- virtual-programs/new-program-web-editor.folk | 9 +- virtual-programs/web-editor.folk | 188 ++++++++++++++------------- 2 files changed, 102 insertions(+), 95 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/new-program-web-editor.folk b/virtual-programs/new-program-web-editor.folk index 692b00e0..5797365b 100644 --- a/virtual-programs/new-program-web-editor.folk +++ b/virtual-programs/new-program-web-editor.folk @@ -113,9 +113,9 @@ Wish the web server handles route "/new" with handler { ws.close(); } ws.onmessage = (msg) => { - if (msg.data.startsWith("ERROR:")) { + if (msg.data.startsWith("Error:")) { const errorEl = document.getElementById("error"); - if (msg.data == "ERROR: {}") { + if (msg.data === "Error:") { errorEl.style.backgroundColor = ""; errorEl.innerText = ""; } else { @@ -153,7 +153,10 @@ Wish the web server handles route "/new" with handler { if {$::isLaptop} { Step } `); setTimeout(() => { - send(`list ERROR: [Statements::findMatches [list {${program}} has error /err/ with info /errorInfo/]]`); + send(` +set errors [Statements::findMatches [list {${program}} has error /err/ with info /errorInfo/]] +join [list "Error:" {*}[lmap e $errors {dict get $e errorInfo}]] "\n" +`); }, 500); } let jobid; diff --git a/virtual-programs/web-editor.folk b/virtual-programs/web-editor.folk index 6669d9fa..ae14f9b4 100644 --- a/virtual-programs/web-editor.folk +++ b/virtual-programs/web-editor.folk @@ -1,117 +1,121 @@ Wish the web server handles route {/page/(.*)$} with handler { if {[regexp -all {/page/(\d*)$} $path whole_match program_id]} { - set filename "../folk-printed-programs/$program_id.folk" + set filename "../folk-printed-programs/$program_id.folk" set fp [open $filename r] set file_data [read $fp] close $fp } elseif {[regexp -all {/page/(.*)$} $path whole_match program_id]} { - set filename "virtual-programs/$program_id.folk" + set filename "virtual-programs/$program_id.folk" set fp [open $filename r] set file_data [read $fp] close $fp } html [string map [list file_data [htmlEscape $file_data] program_id $program_id file_name $filename] { - - -
- Status - - -
- -

-	
-	
-	
+            setTimeout(() => {
+              send(`
+set errors [Statements::findMatches [list program_id has error /err/ with info /errorInfo/]]
+join [list "Error:" {*}[lmap e $errors {dict get $e errorInfo}]] "\n"
+`);
+            }, 500);
+          }
+
+          let jobid;
+          function handlePrint() {
+            const code = document.getElementById("code").value;
+            jobid = String(Math.random());
+            send(`Assert web wishes to print program program_id with code {${code}} with job id {${jobid}}`);
+            setTimeout(500, () => {
+              send(`Retract web wishes to print program program_id with code {${code}} with job id {${jobid}}`);
+            });
+          }
+        
+        
+        
     }]
 }
-- 
cgit v1.2.3