Programming a Pi to Deter Cats: Part 9.2

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I’m exploring SSH a little farther. Let’s get started!

Just as there’s more than one way to tie a knot, there’s more than one way to secure communications between two computers. Last week, I talked about how to use SSH to log in remotely. This week, I learned how to use a pair of cryptographic keys to log in without a pesky password preventing punctual passage.

I’d like to take a break here and just say that when you have multiple implementations for the same task, it can be difficult to choose which one to go with if there isn’t already some sort of standard in place. For example, if you are just starting to look at getting a new computer and you know precious little about them, it would probably not be a good idea to go with a completely unknown operating system like PurpleDragon (Fictional example). There isn’t likely much support for it, you likely won’t find much software for it outside what comes with it, and you just might have issues trying to connect with other computers if it isn’t programmed with standardized network protocols. This isn’t to say you will never want to run something like PurpleDragon, especially if you are in charge of a secret super genius’s lair and you need to prevent outside hackers and can afford a whole IT staff to maintain it.

Whatever the case, I’m now working with PuTTY, a fancier SSH client that’s supposed to work a little better than the Windows extension I’ve been working with. The cryptographic keys I mentioned earlier are generated in pairs. Oversimplified, both parties each have a public key and a private key, and each party’s public key can unlock the matching private key. The two parties swap public keys, and then the two can lock their chatter up in a way that it just looks like noise to anyone trying to listen in.

Final Question: It feels a little awkward learning about modern cryptography with Quantum computing coming any day now (relatively speaking). Once Quantum computers are easily accessible to the public, cryptography will be obsolete, but they will give us unbreakable quantum cryptography. How long do you think it will take to affect this change?

Programming a Pi to Deter Cats: Part 9.1

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am starting a small side adventure with my Pac-Man ghost inspired Raspberry Pi project. Let’s get started!

This week, I took a break from programming. For weeks now, I’ve had to share an HDMI monitor between my desktop and my Pi, which I’ve named Blinkie. In past weeks, I’ve setup a VNC server so I can remote in and take control of Blinkie from my desktop with a VNC client, but I have a few edges to smooth out.

Firstly, the system seems to get its resolution from an attached HDMI display. If I boot it up headless (no monitor attached) then Raspian will boot the GUI into a low-resolution mode, presumably to save on CPU time. If I later connect a monitor later, it doesn’t auto-adjust, and I end up rebooting. I’ve taken to going behind my monitor and switch the HDMI inputs, and they can be difficult to get on the first try.

Secondly, when I’m no longer working on Blinky, I will have two jobs for it. Guard the kitchen, and stream the Church service on Saturday morning. This will imply both headless and headed operation. I can easily optimize for one or the other, but getting it just right will be tricky.

The bulk of my work this week went into turning Blinky from a more tiny Desktop into more of an actual security camera arrangement. I taught myself about SSH, the most fundamental skill I’ll need for operating it at a distance. SSH feels similar to VNC, but only for the command line in that it has a server and a client. Since I’m starting with optimizing for the security camera configuration, I found a way to boot to CLI, the command line only, and a way to enable a virtual desktop in memory from that command line. I ran into a little surprise.

The first problem I found was a quick fix. Instead of the traditional pointer I’m used to, it favored a black X. LINK to the forum thread I used. Another issue was the unexpected evolution of the aspect ratio. I ended up just moving the whole VNC window over to my other monitor, since it about fit and I don’t particularly relish the black boarder around the desktop. I can rework my workflow on Blinkie to accommodate the narrower work area.

I still have some bits to figure out. The mouse buttons are still double swapping. If I’m going to be going between headless and desktop modes, I want to have a consistent, swapped button experience. The worst case scenario right now is where I run a bash or other kind of script and program it to change the setting based on if there’s a monitor connected on startup.

I also need to find an easier SSH client for Windows or else find a way to zoom in on the text. Also against the default Windows SSH client is the fact I cannot just paste a long, super secure password into Command Prompt for logging in. In addition, I may be interested in looking into an Android SSH client for both now and future projects.

I need to find an easier SSH client for Windows or else find a way to zoom in on the text. Also against the default Windows SSH client is the fact I cannot just paste a long, super secure password into Command Prompt for logging in. In addition, I may be interested in looking into an Android SSH client for both now and future projects.

Final Question: Have you ever used SSH on an Android device before? Do you recommend any in particular?

Programming a Pi to Deter Cats: Part 9

Good Morning from my Robotics Lab! This is Shadow 8472, and today, I feel like I’m progressing in a non-linear fashion. Let’s get started!

Last week, I cleaned up my code by moving the bits I still wanted over from one .py file to another. My goal for this week was to distinguish between objects moving in the foreground and a stationary, but adaptive background.

My progress this week doesn’t feel quite so linear. I got about half way to my stated goal on my own while working with a premade background subtraction function, and ended up getting stuck on trying to find a way to monitor my own progress. I’d like to first see my foreground, preferably in color, then I’d like to see my present background so I can hopefully understand the algorithm better.

I went into the workshop for a little help, and things really went in a lot of odd directions after that. We spent a while chasing oddball, but not quite false, leads a couple big bugs. We downloaded and installed an IDE called Spyder3.

As an aside, I would just like to say, that IDE’s are both a curse and a blessing. They are a pain to get working correctly, especially if you’re working with anything outside the core language. But they make development easier, and they are a lot easier to use than a command line for new programmers, once again provided someone who knows what they are doing is setting it up or the programmer has ample amounts of both luck and determination.

Spyder took a lot of hassle to generate a few nuggets of debug gold, and it still is misbehaving. I plan on just using it as a nicer environment for coding, but I intend to use the command line for testing unless I need a closer look at my program’s state when it fails.

One of my big breakthroughs this week was finally realizing a mismatch between a list of list of lists and a list of lists (a 3D array and a 2D array). It looks like one of those bugs I had was about an improper use of a blur function. My current understanding is that it outputs a “color” frame even if it gets a grayscale input.

I eventually arrived at a grayscale, background-subtracted image with poorly defined edges. It seems to have a hard time with my purple shirt against another background.

My goal for next week is to stabilize the background subtraction with a smooth edges algorithm, and hopefully be able to draw boxes around objects.

Final Question: did you or would you rather learn programming with an IDE or with a command line?

Programming a Pi to Deter Cats: Part 7

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am simplifying the path before me. Let’s get started!

I went to the workshop again this week, and I got some fairly simple advice. I have a fairly fancy background system, but do I really need it? For a first prototype, probably not.

The new way forward is going to be just keeping a running average of the background. After initialization, each frame will be fed into a function to average it with the existing background. I have my doubts, but adding some weights to the average to favor the existing background should achieve the same goal with less computing power spent and less code written.

I also talked about a few other things while I was there. I wanted to take advantage of multiple threads, where one core would manage the background while another handled the object detection. I forgot an important detail: Python itself doesn’t support multiple threads. Now, if I were to have it start another program… Possibly not, though.

I also brought up the unlikely possibility of changing program constants while the program is running. Turns out there are ways to do that. From my brief glance at the topic, it’s not quite the module to include I imagined, rather: it looks like it might be similar to a cheat engine I once saw being used for a game. I’ll be looking into it for next week.

Hopefully by next week, I will have something set up to change global variables on the fly. Another good boon would be to fully implement the whole deal of fading the whole background. I was exposed to the sound chip, but with my case geometry, I’ll need a GPIO port ribbon to accommodate my inverted board and an extra power cord. I’m still aiming for modifying a buzzer to accept a pulse from the Pi instead of a finger on a button.

Final Question: I think I’ve finally realized on the format I want to use from now on. Review progress, present progress, then plan ahead. I don’t always make as much progress in a given week, so I often pad it with descriptions of future plans. What do you think?

Programming a Pi to Deter Cats: Part 6

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I’m working on my Raspberry Pi again to make it chase cats off counters. Let’s get started.

A lot has happened this week, yet it feels like not enough. I had a Python script running OpenCV from the command line last week, and this week, I’ve started work on the dynamic background.

I’d have to say I’m not quite a third of the way to this smaller goal, but in terms of required research, I should be finished with it next week.

Right now, I have the pseudocode for this part of the project, as well as a demo highlighting the difference between the last two frames. To get to that point, I had to buffer frames to a two-frame queue, then compare them.

It is not fun when you have an error search engines don’t recognize. “Src1 is not a valid numerical tuple.” Long story short, it was the way Python arrays work. They need to be declared, then each element, or a placeholder element added. Somehow, after giving up for the night, I halfheartedly tinkered with swapping the order of comparison, and it followed the same element. I traced the bug back through my IO function, and got a buffered video feed.

The other exciting thing was finding the comparison function. The buffer has a pointer to say which is the more recent frame, and reading the most recent frame is fine, but the trick here is to highlight what’s new and changed this frame. It took a bit to find that function, and I played with a few bitwise operators I found next to it. One strangely affected the “raw footage,” and ended up strobing. I had to slow the framerate on that one to see it was inverting everything each frame.

The very next thing to do is to boost those frames to all white, but I haven’t found how to do that yet. After that, I need to figure out how to extract the resolution and get the demo working in low resolution mode by scaling the width and height down by an integer.

With a scaled down resolution, I should be able to build a heatmap as a countdown timer until areas fade into the background. Once I have all that working, I can start researching again for spawning a second thread and analysing the full resolution picture for naughty felines.

Final Question: How many more weekly parts should it take before I have my first working prototype?

Planning a Semi-Sealed Night Light Part 4

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am printing a thin box frame the maximum size of my 3d Printer. Let’s get started.

Workflow wise, things were fairly straight forward, though in reality, things were overlapping, as usual. The workflow started with planning. I want a physical model of how big I am able to print. I toyed along the production line between Blender, Cura (the slicer), and the printer before settling for a squished “cube” that will scale to have 5mm edges and corners. A power outage during the night caused me to lose my model, but I was able to load my hollowed out cube again from a .stl file. Interestingly, it was converted to have triangular faces, so I had to turn it all back into quads before I could continue.

Meanwhile, my early cube prototypes’ rafts wouldn’t start out correctly. The extruder tip would start moving without the plastic sticking until a few inches down the line. This problem looks like the exact same one as when I printed 36 coins at once for the meetup with Tango a year ago. That time, I could just discard the malformed tokens, but this time, it’s a whole print depending on this line.

I’ve investigated the matter by learning enough G code to read the instructions the printer was following, and I get the idea it’s following them correctly. Link to a Wiki. I learned a bunch, but I literally don’t have anything to show for it this week. No cube, not even one on the printer. I’ve tested a number of theories, including retracted filament to goopy nosel. I’m out of time, but the first thing for next week is checking out the print bed, a factor I dismissed earlier on because of its resemblance to the coin problem earlier. I will say though, that I do have the bed a little lower than I have had it before, so that may be the case.

Another unsolved problem: Whenever the printer boots and I try printing the hollow cube, I’m finding the printer ratcheting when it tries going beyond its print range. I’ve had this happen a couple times, but it stabilizes after a couple false starts without me seemingly doing anything.

Final Question: Two: What’s with my delayed extrusion start? What’s with the printer glitching and self-correcting?

Planning a Semi-Sealed Night Light Part 3

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am prototyping the shape for this large night light project. Let’s get Started!

I made a lot of progress this week. We ordered a roll of white PLA plastic for this project, and since it worked out well with a free shipping deal, we also got an ABS spool for when I print up another Pi case sometime in the future when I have a setup that can safely handle the toxic fumes.

While the spools were shipping, I got into Blender, and fiddled around with merging two half-cylinders on top of a box. The shape is supposed to look kind of like a house with four windows. Modeling that up took the majority of my time, but that was review. Good thing I remembered enough to recognize or look up the names and shortcuts for each tool I used.

I printed up my first prototype, and it turned out about exactly as I imagined it, only the color was solid white instead of clearish white like the demo filament that came with the printer in the first place. I modeled up an interior, and it turned out exactly how I imagined the first one. When I saw the printer wasn’t doing it correctly, I applied my mirror modifier and tried connecting the inside layer and outside layer, but the same problem must have happened again, because when I opened up the slicer with the allegedly third design, it was the second, sealed design. Good to note it doesn’t just draw the outer most layer.

While the third one was printing, I decided to slip in a few “spare parts” that were otherwise rattling around in my laptop before replacing the power port. I paused the print and noted how I would need access to the back of the printer when I install the electronics for the final light. Another minor mystery I’ve been dealing with was specks of other colors showing up in prints. While shopping for the filament, we actually spotted a spool for cleaning the printer. I don’t know how it works, but I could see the demand for such a product if someone wants to make sure if there isn’t contamination between colors or types of plastic.

I’ve used what I’ve learned to refine my understanding of this project:

Prototype shape
Hollow Prototype (present)
Model up relief pictures on “windows”
Deduce Final size
Electronics to fit final size
Refine model to hold electronics
Final product

In the interest of keeping specks of black or red out of my final print, I think I want to make a print to demonstrate the full print range of the printer. I’m thinking of doing a simple cube with just the edges. It will produce a lot of infill, but I think it will be neat to just have a cube around.

Final Question: What fun shapes would you like to see available for print for tiny computers?

A Series of Limitations

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am laying a project to rest. Let’s get started.

The past couple weeks, I’ve been working to make a video call from my Raspberry Pi using the PiCamera taped into the case. Only this week did I learn it was too ambitious when I stopped by the workshop and actually started testing what worked. I managed to get a inbound stream, and presumably good audio (there weren’t any speakers connected at the time), but the video stream coming from the Discord webapp in Chromium came through way too slowly to be of any use but for a good laugh.

My time on this project was not wasted, though. I learned a lot about both how the PiCamera works and what it can do and what the Pi itself cannot do. It turns out the Raspberry Pi has all its graphics on the CPU, meaning no specialized circuitry for videos to begin with. That isn’t to say it cannot handle ANY streaming. It did manage to pull off viewing the live broadcast of my church’s services for the last couple Sabbaths with only a few problems. It’s likely something to do with the resolution and frame rate it’s trying to work through. That or trying to send non-existent audio while streaming video is a little much for the little computer.

This project was fun, but I simply don’t have the skills to pull it off at this time. If I ever do get it working, I expect it to be on a tiny, 64 bit OS for the Pi written just for video chat and nothing else.

On an unrelated note, I plan on separating the Pi itself from the cat deterrent(s). It will hopefully solve the power problems if I set up a little, offline network connected by radio or WiFi. Maybe I’ll take apart an old wireless mouse and see if I can use that.

Final Question: If you want to stretch your abilities, you should pick goals just outside of your abilities. What was the last project you tried, but found was just a little bit too far out of your reach?

A New Tool Part 12

Good morning from my Robotics Lab! This is Shadow_8472, and today, I am finally done with the paint job. Let’s get started!

I had to give in. Spray paints are just too broad of strokes for the delicate eyes. I ended up recruiting my sister to do them with acrylics. On the plus side, they are a slightly closer shade of blue to the original sprites, which I was going for, anyway. I booted up the Pi after the final bits of paint were dry, and confirmed a clear image from the camera. I snagged My father to clean the whole thing with rubbing alcohol and the two of us applied a clear coat.

As of this writing, I have spent an hour or two working at removing that Elmer’s glue mask. I waited too long, and the mask is too thin. If I ever need to mask off another waffle cone like that again, I’ll spend less time using masking tape beforehand than peeling the glue afterword. The Elmer’s glue trick is only for small details!

The paint job is not as perfect as I’d hoped. The white iris has a little bit of blue in it and there’s a little chip in the paint on the back. A bubble or three have grown in a few places about the surface, and the final irises have brush strokes. Even with all these small flaws, it still looks better finished than it did while stuck in development limbo. Overall, I’d say it’s almost what I wanted.

As it stands now, I have most of the glue off, but the rest is either splitting on me or stubbornly sticking to the printed plastic. Fortunately, the holes I taped off remained taped off through the whole ordeal so I didn’t have to go through and find a hook to get blobs of glue out of all the deep crevices.

Looking forward, I hope I don’t need to use an Internet connection to recognize a cat. I honestly don’t know how long it will take to finish with the software side of things, but I will need to first make a “Hello World” program to debug my coding setup. Come to think of it, I likely only have one more “A New Tool” post, as it’s just going to be attaching the board and any little details that pop up.

Final Question: have you ever had a long project finally approach its completion date after crawling along for way too long?

Minecraft Boat Race Port Part 3

Good Morning from my Robotics lab! This is Shadow_8472, and today, I am bringing you another short chapter in the history of my port project. Let’s get started.

Work is still slow. I have a fairly solid idea of what the structure of the final product is supposed to be, but it’s coming along. Jam and I weren’t exactly able to work on it constantly, but he did help me with a few ideas and get the teleport command for entering the level.

I really hope I can do a demo for next week encompassing the original experience for the boat race. In the meantime, I can finish fine tuning what I have and showing my progress off and comparing it to the last time I showed it off to someone. Early on, I showed it off to my self, playing the levels just for old memories’ sake. That was just the levels loaded into a field after aligning them correctly. Later, I had a friend over where I loaded each level half in manually. After that, I demonstrated how I only needed to load one half, and it would load the other automatically. Another step toward completion let me show someone else how I had the structure blocks correctly placed to load the five available levels. This week, I provided my mother with an experience one step closer to completion when I played interface between the pressure plate and loading the level; the level now teleports its players to its own starting point.

Right now, I can think of two remaining challenges: I need to do the interface between pressure plate and level loading, and I still need to do the level end functions. Other than that, I still haven’t even looked at the original celebration commands.

Final Question: The teleport command came to me after goofing off all day. Have you ever gotten a critical idea in a similar fashion?