Cameras for looking at yourself, Shared process memory, Screwdriver bit holders: ttftw 2023w14
By Robert Russell
- 6 minutes read - 1158 wordsThree things from this week.
This week I thought it’d be nice to talk about a simple camera hack to solve a niche problem, a Linux API to solve different niche problems, and a couple 3d printed parts that solve an entirely different niche problem.
Seeing the back of your own head
I have a personal mission of making it easy to see things that might otherwise be impossible or unpleasantly difficult to see. The back of your own head is one of those things. It turns out it might be easy to look at the back of your own head if you have the right equipment.
Mirrors are one way to see the back of your head. A couple of mirrors and good light might be enough to guide you to braid your own hair. If you want to see real detail though then it’s tricky to set up the right combination of lighting and magnification with mirrors. Switching to a digital mirror replacement is getting simple though. Without getting into details, I had a spot on the back of my head that needed some drops. It really bugged me that I couldn’t see the spot with my own eyes.
The mind produces an image of the body that doesn’t match what we see in the world. We build the map in our mind using factors like the relative importance, the density of nerves, or the priority of sensations from that part of the body. Sometimes we transfer pain from a spot that can’t feel to one that can. The map of the body produced by the mind is amazing, complex, and nuanced but it is a distortion of the physical map. When we can provide more input from an external view we can update and build on that map and combine different perspectives for a more useful perspective on the body.
Since I have random camera and computer hardware around I used a little clamp to secure a stand to my desk. Atop the stand I attached a webcam inside a ring light. The webcam plugged into my laptop and I ran OBS to watch the live feed. OBS is a fantastic piece of free, open source software which is popular for streaming and recording for YouTube and Twitch. I could have just as well used VLC or even ffmpeg. It’s fantastic to have so many FOSS options. One other key factor is that my laptop has a feature that I’ve long considered a gimmick which turned out to be really useful here, the screen can lie flat on the desk. It actually folds over into a tablet form factor. So that means I can run regular Windows or Linux software, plug in common peripherals like the webcam, keyboard, and mouse and I can also have a form factor that’s laying flat on the desk.
As I think about it there are other options that would work fine for this too, like streaming from a phone with a selfie stick. One important feature that worked well here which can be difficult - it’s important to have low latency. When your camera moves or your body moves the image has to feel like it’s changing right away. A laggy image adds too much complexity to interpreting the differing orientation and position. So odd wireless connections, super low-end computers, or super high-resolution cameras take away from this kind of experience.
It was really nice to have a simple way to connect a few things and see a new perspective. I’d put this in the same general category as reaching under your car or your couch with the cell phone camera on. When you have a camera in your hand and you can stick it in remote places you can see new things. When you can easily separate the screen and the camera that just opens up a few new options.
Shared memory
Not an epigenitic theory outgrowth, just /dev/shm
. Linux (really POSIX but w/e) has a set of APIs for sharing memory between processes. Like other Unix-y things the APIs favour a file-centric view of the shared memory. Using it can be as easy as using other files, depending on how you usually use files.
Here’s an example of a program that writes to a shared memory block. It becomes available at /dev/shm/mystuff
. This simple example may would work with regular files too but suppose sometimes there are good reasons to use a shared memory block rather than more general files.
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
int main(int argc, char **argv) {
int fd;
char *p;
char message[] = "Howdy\n";
int size = strlen(message);
fd = shm_open("howdy", O_CREAT | O_RDWR, 0666);
if (fd == -1) {
perror("Failed to open.");
exit(-1);
}
if (ftruncate(fd, size) == -1) {
perror("Failed to resize.");
exit(-2);
}
p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (p == MAP_FAILED) {
perror("Failed to map.");
exit(-3);
}
close(fd);
memcpy(p, message, size);
return 0;
}
It’s simple enough you can compile and run it with
cc -Wall saver.c -o saver && ./saver
and see the output
$ cat /dev/shm/howdy
Howdy
The result looks like a file and acts like a file and some might just say it is a file. Since it’s backed by RAM the contents of /dev/shm
will be gone after a reboot though, which isn’t generally what you expect from a file. There are similar examples in the man pages for shm_open()
and mmap()
.
There’s a relevant Python library called multiprocessing.shared_memory included since version 3.6. It offers a couple features to help interact with this kind of shared memory file. It acted a little quirky when I tried to just read the file I created in the C program above. It seems like maybe it’s more geared toward managing this resource completely within Python but figuring that out doesn’t seem to fit in a trivial example.
Torx screws
I’m pretty sure nobody has ever liked torx screws. Something came loose on the fence. One Phillips screw fell out and I had a Torx screw to patch things up.
Here’s a nice little holder I use to organize my screwdriver bits.
Maybe organize is too strong a word here. It keeps the bits close to each other. On the back of my drill I’ve attached this nice little clip that can hold some long bits. It’s a nice way to keep a variety of bits right on hand even if one has to be Torx it still has room for a few useful bits too. It does only work on specific models of drill since it clips on to some feature on the back of it. I like these quick PLA prints that provide a tiny little benefit for years.
Until next time
That’s all I’ve got for now. Not highlights, not the lowlights, just a sample. Hope you found one insteresting, one useful and one maybe a bit odd.