diff options
| author | Andrés Cuervo <andrescuervor@gmail.com> | 2023-09-18 21:22:02 +0000 |
|---|---|---|
| committer | Andrés Cuervo <andrescuervor@gmail.com> | 2023-09-18 21:22:02 +0000 |
| commit | bd15f3e4f71b3aca0b536bf41f7521ee709ea6f1 (patch) | |
| tree | 9e34e46eb25d33978b0559cfbc48dc573005713b | |
| parent | Correctly angle editor text (diff) | |
| parent | Run camera at 60fps if possible (diff) | |
| download | folk-bd15f3e4f71b3aca0b536bf41f7521ee709ea6f1.tar.gz folk-bd15f3e4f71b3aca0b536bf41f7521ee709ea6f1.zip | |
Merge branch 'main' into ac/editor
| -rw-r--r-- | pi/Camera.tcl | 27 | ||||
| -rw-r--r-- | virtual-programs/apriltags.folk | 4 | ||||
| -rw-r--r-- | virtual-programs/archive/metrics.folk | 8 | ||||
| -rw-r--r-- | virtual-programs/camera.folk | 4 | ||||
| -rw-r--r-- | virtual-programs/display.folk | 7 |
5 files changed, 38 insertions, 12 deletions
diff --git a/pi/Camera.tcl b/pi/Camera.tcl index 76f007dc..7a6359d6 100644 --- a/pi/Camera.tcl +++ b/pi/Camera.tcl @@ -72,8 +72,7 @@ namespace eval Camera { if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) quit("no capture"); if (!(cap.capabilities & V4L2_CAP_STREAMING)) quit("no streaming"); - struct v4l2_format format; - memset(&format, 0, sizeof format); + struct v4l2_format format = {0}; format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; format.fmt.pix.width = camera->width; format.fmt.pix.height = camera->height; @@ -85,8 +84,7 @@ namespace eval Camera { } while (ret == EBUSY); if (ret == -1) quit("VIDIOC_S_FMT"); - struct v4l2_requestbuffers req; - memset(&req, 0, sizeof req); + struct v4l2_requestbuffers req = {0}; req.count = 4; req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; req.memory = V4L2_MEMORY_MMAP; @@ -94,6 +92,27 @@ namespace eval Camera { camera->buffer_count = req.count; camera->buffers = calloc(req.count, sizeof (buffer_t)); + struct v4l2_streamparm streamparm = {0}; + streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + if (xioctl(camera->fd, VIDIOC_G_PARM, &streamparm) == -1) quit("VIDIOC_G_PARM"); + if (streamparm.parm.capture.capability & V4L2_CAP_TIMEPERFRAME) { + int req_rate_numerator = 1; + int req_rate_denominator = 60; + streamparm.parm.capture.timeperframe.numerator = req_rate_numerator; + streamparm.parm.capture.timeperframe.denominator = req_rate_denominator; + if (xioctl(camera->fd, VIDIOC_S_PARM, &streamparm) == -1) { quit("VIDIOC_S_PARM"); } + + if (streamparm.parm.capture.timeperframe.numerator != req_rate_denominator || + streamparm.parm.capture.timeperframe.denominator != req_rate_numerator) { + fprintf(stderr, + "the driver changed the time per frame from " + "%d/%d to %d/%d\n", + req_rate_denominator, req_rate_numerator, + streamparm.parm.capture.timeperframe.numerator, + streamparm.parm.capture.timeperframe.denominator); + } + } + size_t buf_max = 0; for (size_t i = 0; i < camera->buffer_count; i++) { struct v4l2_buffer buf; diff --git a/virtual-programs/apriltags.folk b/virtual-programs/apriltags.folk index ac2c4f8b..8bdd415a 100644 --- a/virtual-programs/apriltags.folk +++ b/virtual-programs/apriltags.folk @@ -114,6 +114,7 @@ On process { set ::tagsCache [dict create] # TODO: Garbage-collect this cache. +set ::aprilTime none When the collected matches for [list /someone/ detects tags /tags/ at /timestamp/ in time /aprilTime/] are /matches/ { set tagsSeen [dict create] foreach match $matches { @@ -136,5 +137,6 @@ When the collected matches for [list /someone/ detects tags /tags/ at /timestamp Claim tag $id has center [dict get $tag center] size [dict get $tag size] Claim tag $id has corners [dict get $tag corners] } - Claim the AprilTag time is [lmap m $matches {dict get $m aprilTime}] + set ::aprilTime [lmap m $matches {dict get $m aprilTime}] + Claim the AprilTag time is $::aprilTime } diff --git a/virtual-programs/archive/metrics.folk b/virtual-programs/archive/metrics.folk index fe6baebd..e5389512 100644 --- a/virtual-programs/archive/metrics.folk +++ b/virtual-programs/archive/metrics.folk @@ -1,13 +1,13 @@ -When $::thisNode has step count /c/ & the camera time is /cameraTime/ & the AprilTag time is /aprilTime/ { +When $::thisNode has step count /c/ { Wish $this is labelled [string trim " Metrics ---- step count: $c step time: $::stepTime -camera time: $cameraTime -AprilTag time: $aprilTime -display time: $::Display::displayTime +camera time: $::cameraTime +AprilTag time: $::aprilTime +display time: $::displayTime "] } diff --git a/virtual-programs/camera.folk b/virtual-programs/camera.folk index 0a95c8f0..428c4195 100644 --- a/virtual-programs/camera.folk +++ b/virtual-programs/camera.folk @@ -29,6 +29,10 @@ On process { } } +set ::cameraTime none +When the camera time is /cameraTime/ { + set ::cameraTime $cameraTime +} # For backward compatibility. When the camera frame is /grayFrame/ at /timestamp/ { Claim the camera frame is $grayFrame diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk index d3f6b610..674cf1f7 100644 --- a/virtual-programs/display.folk +++ b/virtual-programs/display.folk @@ -35,8 +35,6 @@ namespace eval ::Display { proc fillPolygon args { uplevel [list Wish display runs [list Display::fillPolygon {*}$args] on layer $::Display::LAYER] } - - variable displayTime none } On process { @@ -87,7 +85,10 @@ On process { Step } } -# TODO: remove this compatibility hack + +set ::Display::displayTime none +set ::displayTime none When the display time is /displayTime/ { set ::Display::displayTime $displayTime + set ::displayTime $displayTime } |
