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 36ad146a39dd8ba1a155bc236ec85eff9b1f685f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Cuervo?= Date: Sat, 24 Jun 2023 23:47:45 -0400 Subject: Add filled polygons --- virtual-programs/shapes.folk | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/shapes.folk b/virtual-programs/shapes.folk index b693220e..25c615c5 100644 --- a/virtual-programs/shapes.folk +++ b/virtual-programs/shapes.folk @@ -3,18 +3,6 @@ set sizeDict [dict create small 1 medium 4 large 10] proc isSizeWord {word} { expr {[lsearch [list small medium large] $word] >= 0} } -proc polyline {points {strokeWeight 5} {color white} args} { - set i 0 - set pointsLength [llength $points] - set PL_less_one [expr {$pointsLength - 1}] - while {$i < $pointsLength} { - if {$i eq $PL_less_one} { return } - set current [lindex $points $i] - incr i - set next [lindex $points $i] - Display::stroke [list $current $next] $strokeWeight $color - } -} proc rectangle {x y w h {strokeWeight 5} {color "white"}} { set start [list $x $y] @@ -26,7 +14,7 @@ proc rectangle {x y w h {strokeWeight 5} {color "white"}} { lappend points [list [expr {$x + $w}] [expr {$y + $h}]] lappend points [list $x [expr {$y + $h}]] lappend points $start - polyline $points $strokeWeight $color + Display::stroke $points $strokeWeight $color } proc square {x y w {strokeWeight 5} {color "white"} args} { @@ -51,7 +39,7 @@ proc regionToInnerRect {region} { # numPoints 2 => line # numPoints 3 => triangle # numPoints 4 => square -proc shape {numPoints x y r {color white} args} { +proc shape {numPoints x y r {color white} {filled false} args} { set start [list $x $y] set points [list $start] set i 0 @@ -62,7 +50,11 @@ proc shape {numPoints x y r {color white} args} { set y [expr {$y + $r * sin($angle)}] lappend points [list $x $y] } - polyline $points 5 $color + if {$filled} { + Display::fillPolygon $points $color + } else { + Display::stroke $points 5 $color + } } When /someone/ wishes /p/ draws a /color/ /shape/ offset /offsetVector/ & /p/ has region /r/ { @@ -76,8 +68,6 @@ When /someone/ wishes /p/ draws a /color/ /shape/ offset /offsetVector/ & /p/ ha set y [expr {$y + $offsetY}] } - puts "drawing $shape at $x $y" - set adjustedWidth [expr {$width * 0.25}] set x [expr { $x * 1.3}] set y [expr { $y * 1.25}] -- cgit v1.2.3 From f8dc749467b5e00df5905fdce742e747f7ea9c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Cuervo?= Date: Mon, 26 Jun 2023 16:00:28 -0400 Subject: Left-align labels, watch for .folk.temp files --- virtual-programs/label.folk | 7 +++++++ virtual-programs/tags-and-calibration.folk | 12 +++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/label.folk b/virtual-programs/label.folk index 30787555..d18bdd02 100644 --- a/virtual-programs/label.folk +++ b/virtual-programs/label.folk @@ -4,10 +4,17 @@ When /thing/ has region /region/ { set width [boxWidth $bbox] set height [boxHeight $bbox] + set radians [lindex $region 2] if {$radians eq ""} {set radians 0} set upsidedown [expr {abs($radians) < 1.57}] + if ($upsidedown) { + set x [expr {$x + $width * 0.4}] + set y [expr {$y - $height * 0.2}] + } else { + set x [expr {$x - $width * 0.4}] + } if {$::isLaptop} {set upsidedown false} When the collected matches for [list /someone/ wishes $thing is labelled /text/] are /matches/ { diff --git a/virtual-programs/tags-and-calibration.folk b/virtual-programs/tags-and-calibration.folk index c624614a..f3155612 100644 --- a/virtual-programs/tags-and-calibration.folk +++ b/virtual-programs/tags-and-calibration.folk @@ -79,9 +79,15 @@ When (non-capturing) tag /tag/ has center /c/ size /size/ { When (non-capturing) tag /tag/ is a tag { puts "Added tag $tag" - set fp [open "$::env(HOME)/folk-printed-programs/$tag.folk" r] - set code [read $fp] - close $fp + set tempPath "$::env(HOME)/folk-printed-programs/$tag.folk.temp" + + if {[file exists $tempPath]} { + set path [open "$::env(HOME)/folk-printed-programs/$tag.folk.temp" r] + } else { + set path [open "$::env(HOME)/folk-printed-programs/$tag.folk" r] + } + set code [read $path] + close $path # Wish $tag is outlined green Claim $tag has program code $code -- 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


From 65672ef475755cb89d25a46ecee26d25c30d1be1 Mon Sep 17 00:00:00 2001
From: Omar Rizwan 
Date: Fri, 30 Jun 2023 22:39:49 -0400
Subject: New metrics

---
 virtual-programs/archive/metrics.folk | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

(limited to 'virtual-programs')

diff --git a/virtual-programs/archive/metrics.folk b/virtual-programs/archive/metrics.folk
index b4f76fa0..fe6baebd 100644
--- a/virtual-programs/archive/metrics.folk
+++ b/virtual-programs/archive/metrics.folk
@@ -1,11 +1,14 @@
-When $::nodename has step count /c/ {
-	Wish $this is labelled [string trim "
+When $::thisNode has step count /c/ & the camera time is /cameraTime/ & the AprilTag time is /aprilTime/ {
+  Wish $this is labelled [string trim "
+
+Metrics
+----
 step count: $c
 step time: $::stepTime
-camera time: [expr {[namespace exists ::Camera] ? [lindex $::Camera::statements 0 end] : {none}}]
+camera time: $cameraTime
+AprilTag time: $aprilTime
 display time: $::Display::displayTime
-statement count: [Statements::size]
-logsize: $::logsize
-	"]
+
+"]
 }
-Wish $this is outlined green
\ No newline at end of file
+Wish $this is outlined skyblue
-- 
cgit v1.2.3


From 4376459667603c77e55116e857c0f0b1a248a04e Mon Sep 17 00:00:00 2001
From: Omar Rizwan 
Date: Wed, 5 Jul 2023 15:01:25 -0400
Subject: Try to fix music stuff

---
 virtual-programs/music.folk | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

(limited to 'virtual-programs')

diff --git a/virtual-programs/music.folk b/virtual-programs/music.folk
index d2c979b6..0c208b29 100644
--- a/virtual-programs/music.folk
+++ b/virtual-programs/music.folk
@@ -114,15 +114,18 @@ proc ::Music::finishSetup {} {
   exec jack_control dps nperiods 2
   exec jack_control dps period 64
 
+  catch {exec pkill ghci}
   catch {exec pkill sclang}
-  exec -ignorestderr xvfb-run --auto-servernum sclang $musicDir/startup.sc &
+  after 500 {
+    exec -ignorestderr xvfb-run --auto-servernum sclang $musicDir/startup.sc &
 
-  set fifo $musicDir/tidal-input
-  exec rm -f $fifo
-  exec mkfifo $fifo
-  exec -ignorestderr sh -c "ghci < $fifo" &
-  set fifoId [open $fifo w]
-  ::exec cat $musicDir/BootTidal.hs > $fifo
+    set fifo $musicDir/tidal-input
+    exec rm -f $fifo
+    exec mkfifo $fifo
+    exec -ignorestderr sh -c "ghci < $fifo" &
+    set fifoId [open $fifo w]
+    ::exec cat $musicDir/BootTidal.hs > $fifo
+  }
 }
 
 proc ::Music::waitForDbus {} {
-- 
cgit v1.2.3


From c51a929be17ea8cf2b22949e773e80e7d26bcf87 Mon Sep 17 00:00:00 2001
From: Omar Rizwan 
Date: Thu, 6 Jul 2023 10:45:38 -0400
Subject: Fix fix Music?

---
 virtual-programs/music.folk | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

(limited to 'virtual-programs')

diff --git a/virtual-programs/music.folk b/virtual-programs/music.folk
index 0c208b29..1f48c9a8 100644
--- a/virtual-programs/music.folk
+++ b/virtual-programs/music.folk
@@ -117,14 +117,14 @@ proc ::Music::finishSetup {} {
   catch {exec pkill ghci}
   catch {exec pkill sclang}
   after 500 {
-    exec -ignorestderr xvfb-run --auto-servernum sclang $musicDir/startup.sc &
+    exec -ignorestderr xvfb-run --auto-servernum sclang $::Music::musicDir/startup.sc &
 
-    set fifo $musicDir/tidal-input
+    set fifo $::Music::musicDir/tidal-input
     exec rm -f $fifo
     exec mkfifo $fifo
     exec -ignorestderr sh -c "ghci < $fifo" &
     set fifoId [open $fifo w]
-    ::exec cat $musicDir/BootTidal.hs > $fifo
+    ::exec cat $::Music::musicDir/BootTidal.hs > $fifo
   }
 }
 
-- 
cgit v1.2.3