Programming a Pi to Deter Cats: Part 8

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am droning on with my Raspberry Pi Cat Camera project.

Any sufficiently unguarded water cup is indistinguishable from a cat bowl. I had the unfortunate experience of going through that today. I gave it to the dogs. A completed sentry would not have helped in this case, but it serves as a little reminder. Of course, as soon as I get this thing working, I’d say its expected life expectancy is about a week or two. However long it takes before my cat stops the unwanted behavior.

I had a little bit of a tangent this week. It turns out it is very easy to get distracted when you have a special effects setup. The background I had last week, a constantly updating weighted average, was very entertaining in its own right. I could jump in front of the camera and fade in as if I were a ghost. I jump away, and my image fades out. If I held still, the picture would get sharper.

I ended up researching how to VNC into my Pi from my desktop so I don’t have to keep switching out the HDMI cord plugged into the back of my main monitor. It has actually been fairly uneventful so far. My password manager takes a while to register a new password, so I paused work on that angle of the project before I could set up a virtual desktop. The reason I want that is because the Pi checks if it is “headless” or without any video outputs when it boots. If there aren’t any, it goes into minimum resolution mode, presumably to conserve on CPU power. I have sense been careful to plug it in only after a monitor is connected.

I also went to the workshop again this week and promptly learned why I should always clean up after experiments; I had tried commenting out the line to convert to grayscale, and forgot to correct it. I also learned that the differing lighting conditions defeated the semi-fine tuned settings I had for my rudimentary motion spotter, and the ghost trails were back. We also did a big one on the old code while trying to simplify the code. One major change later, and I find things going half nuclear. I was given homework: Git Hub and code cleanup.

And by code cleanup, I mean extract the bits of code still in use after this great restructure and make it work again. I just need to be sure to chmod my new file. I’ll also be using native cv2 functions for finding the background and whatnot.

By next week, I hope to be able to remote into my Pi with full screen resolution, and get back to where I was but with native cv2 functions.

Final Question: How long will it take before the cat learns, and will I ever need to redeploy?

Programming a Pi to Deter Cats: Part 5

Good Morning from my Robotics Lab! This is Shadow_8472, and I feel good about my progress this week. Let’s get Started!

Last week, I had successfully confirmed OpenCV was installed on my Raspberry Pi. The first thing to do this week was to start coding just as soon as I figure out a way to save a program file within the virtual environment, right?

Not quite. I thought a virtual environment was kind of like a virtual machine, where it has a whole little computer running within your computer, only with a few less restrictions. I still think that, but it turns out it works just fine if I run a file within the virtual environment from the Desktop or anywhere else.

I also learned exactly what a bash script is. So, I had OpenCV working in a script, and I changed permissions so I could run a .py file from the command line, but when i went to run it, I got an error about import not being supported. It turns out I forgot to run the Python interpreter with my program as an argument. That detail got me into the workshop I sometimes mention.

I actually got my base coding test harness from the YouTube Channel CodingEntrepreneurs. (Link to their first OpenCV Python video) While I was at the workshop, I learned a bunch of tangential stuff like when to pack your Python power cord, I polished off my knowledge on how to make sure a substitute power supply is acceptable, and when it’s a good idea to go back to the tutorial instead of arbitrarily placing a missing closing parenthesis.

In the end, I feel like I had a very successful session, but since then I’ve been building a framework for my program as a whole. Hopefully, by next week, I will have a program that will look at a series of pictures, tell if the background in each of three zones (cupboard, counters, and cabinets) is occluded (blocked) by a moving object (a cat or human), and sound the alarm if it sees something in the counters’ zone. As a bonus, it can save a picture of the culprit for if/when I try my coding skills at training a neural net to tell if my cat is being naughty.

Final Question: When was the last time you caught yourself considering over complicating a plan?

Programming a Pi to Deter Cats: Part 4

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I have a small, but important step completed. Let’s get started!

The tutorial I’ve been following gave me a hiccup after compilation. I had a passing difficulty when the commands I was copying used A different version number for an ls command.

Other than that, I had a little drama copying some expected output as a command, and when I did get the correct version number and file name in the command, there were a mismatch witha number or two. I figured it was just because of the version.

In the end, the tutorial had me test everything by running Python in the virtual environment, import OpenCV, and have it report its version. I was so relieved when it gave something back that didn’t resemble an error.

Going forward, I think the next, big milestone needs to be turning on an external light when it sees my cat in the frame. Setting this goal opens up a slew of smaller goals: connecting an LED to the external pins; learning and implementing basic elements in the OpenCV API; setting up such a program to run from either a single command, an icon, or bootup.

After that, it I should probably set it up as a VNC server and place it in its rightful position where it can start learning the difference between naughty cat on the counter and hungry human in the kitchen.

This project feels like it’s gone on ar least ten times longer than I expected. It’s good to have a small victory for once.

Final question: How do you keep track of progress in long projects?

Programming a Pi to Deter Cats: Part 3

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am finally installing OpenCV on my Raspberry Pi. And if I have a little more time, I may even try getting a Hello World type program running with it; it’s unlikely though. Let’s Get Started!

Last time I actually made any progress, I finished with making a virtual environment, meaning anything that happens in the sandbox stays in the sandbox, and I won’t have to rebuild the whole computer if things go nuclear. I think. The tutorial LINK wasn’t very informative, but it was fairly instant while making it clear it was technically an optional step.

The next couple steps are fuzzy in my memory. I don’t remember everything in chronological order. I kept running into errors, but I was gently pushed in the direction of trying to learn about them when I was in the local workshop (I was sure to bring a keyboard and mouse that weren’t at odds with my Pi).

My first major roadblock was when I was setting up to compile. I was sent off to research ‘cmake,’ a command line program being used in that stem. I ended up on a page with a lot of text, and I’m an audio learner. I don’t remember much of what was going on, but I recognized enough to say I was only about 95% lost as to what was going on when it came down to fine details, like the options being used for each argument in the command.

For some reason, it didn’t work, and I left stressed over it. If there’s one thing that is just an infinitesimal less frustrating than something not working when everything you know says it should work, it’s something working when everything you know says it shouldn’t work, and you’re trying to reproduce the problem so you can fix it. That happened to me. I set up for compilation, and I ran it. Ten minutes into the expected hour-plus operation at home, it crashed. There was some library it couldn’t find based on the pregenerated header, but I only figured that out when I went back into the workshop for a second time.

Round two this week was more of the same, possibly leading to events jumping sessions in my mind, but the second one was felt a lot more productive. I found the cause of the source of the problem, and I also worked on another, unrelated topic I want to save for another time.

Bonus Topic: I’ve complained a few times about how Windows sometimes is like, “By the way, we are updating your computer in 10 minutes, is that okay?” I find that highly frustrating. It popped up two or three Friday nights ago (after Sabbath started, so I didn’t want to do a whole topic about it). My father and I finally found the settings to supposedly require human input to permit an update.

Final Question: How much do you usually know about the commands you use?

Programming a Pi to Deter Cats: Part 2

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am moving along towards a feline safety program for my Raspberry Pi. Let’s get started!

For starters, I was even having doubts if my Pi was even powerful enough for computer vision applications. A quick search gives plenty of harry tutorials on how to install it. I’m following one here: LINK. I’m on the Raspberry Pi 3B+, and word has it the Pi 2 was pioneering the field for its kin.

I also watched some tutorials to get an idea of how OpenCV works, and I think it should track the cabinets and counter. If it tracks something moving on the counter and there is no occlusion (nothing is blocking) of the cabinets, register a hit. On a hit, save a picture for future evaluation, and sound the alarm to get the cat off the counter if it’s a strong enough hit.

I started installing OpenCV, but I ran into some issues. First of all, I am very glad I went it to that workshop I’ve mentioned before, because the tutorial just gives me wall of text. It helps to have someone knowledgeable to take a look at things when they stop working. It also would have helped if I had seen the troubleshooting section before I went and searched for one particular error I came across and ended up on another tutorial for the same thing.

Conditions were challenging. the mouse was crazy sensitive, and if I didn’t select and copy with the mouse, I ran the risk of typos in the keyboard. In the end, I believe I got a virtual box for Python 3 to run computer vision, but I ran out of time there.

At the beginning of my post, I mentioned feline safety. It turns out, my father spotted him walking on the stove top, and I really don’t want him getting burned, let alone the health risk.

Final Question: Have you ever used automated deterrents on animals?

Programming a Pi to Deter Cats: Part 1

Good Morning from my Robotics Lab! This is Shadow_8472, and today, and likely for the next couple weeks, I am studying up on how computer vision software works so I can get started on the software to convey a message to my feline friend about venturing in places he isn’t welcome. Let’s get Started!

I decided a long time ago that I wanted to explore the free and open source option OpenCV for this project. From what I can tell, I will need to play around with OpenCV on my desktop first to get a feel of how to use it.

As of the time of writing, I believe my workflow will start with getting OpenCV onto a Linux desktop. After I’m comfortable with how it works, I can try running it on the Pi. Depending on how well the Pi takes it, I will develop the actual program on either my PacMan Ghost case, Blinkie Pie, or my Ubuntu server tower, Derpy Chips. A period of testing will involve Blinkie watching the forbidden area and logging suspicious activity: basically anything that moves, and narrow that down to naughty cat behavior. While that’s happening, I need to develop an audio turret.

My mother actually found a dog training device that emits high frequencies, and the cats aren’t too fond of it either. I’ve already tried taking it apart, and it’s so cheap, getting into the case for tinkering will mean a new case. My goal for this phase is to get the Blinkie to turn the nasty sounds on from a remote desktop.

Once I have my cat identification program working reliably, I can connect it to the frequency generator and set it loose. For the first few days and weeks, I’ll want to monitor it and evaluate its results by looking at pictures from suspect incidents. I’m looking forward to obedient cats.

Final Question: Have you worked with Neural Nets on Computer Vision problems before?

Ice Boat Challenge Port Revamp Part 2

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am covering the finer details of my port of one of my favorite minigames in Minecraft. Let’s get started.

Many times over this project, I’ve tun into bugs. There is no way I’d remember them all, but I did pick up a few tips along the way, mostly from Grifter. If things are going wrong with relative coordinates, try aligning yourself with the source block and teleporting to the relative coordinates. Another approach is to set a particle in a repeat command block or a chain command block downstream of one. More often than not, one of these will literally get you where you want to go. I recommend the barrier particle for its lack of movement and occupation of a full block space.

Another bug I had to deal with a lot early on was invalid functions. If you try loading a datapack with an invalid function, Minecraft just throws a compilation-time-like error in the console then ignores it. Fortunately, the error report, once I read it under Grifter’s instruction, told me where the function, line, and column of each error was. It also didn’t help that Minecraft functions can’t have a comment start part way through a line.

The most recent bug I had to deal with was one that royally goofed it during some stress testing my parents, Annie_8472 and Leo_8472, kindly provided. Sometimes, a level wouldn’t load if you didn’t make it onto the pressure plates far enough. I tried fixing that by using align xyz command segments, but I only made it worse. I never did figure it out because I reverted the change and extended the search range to include a bit more of the alcove. For those keeping score, the bug was with the IBC game and not the MGC core.

At present, the project is almost done; I don’t think I’ll have enough for a whole new post next week, but I still need to debug the Lost & Found. Jamcdonald, the one who showed me the super hoppers last time, did a quick test for me and made note of the bug. He also pointed me in the direction of a place to get signs to do some fancy stuff the original credits signs do.

Final Question: I’m open to further development after things launch. What kind of levels do you want to see in this datapack?

Ice Boat Challenge Port Re-revamp

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am going over the “boat race” I ported to Minecraft 1.13 vanilla. Let’s get started.

At the beginning of the week, GrifterMage, an admin on the Minecraft server I play on, showed interest in getting the boat race up and running again sometime soon. I had already changed its host server over to a “Paper” server, like the server the project is being built for. Everything worked for a little while, but one day, the datapacks I tried sending weren’t working. I restarted my server, and my “original” copy was broken.

I decided to rebuild the backbone of the project from the ground up. While Grifter recommended I reuse as much as possible, I knew there was a certain amount of spaghetti logic at the end. I figured it would take less time to take the lessons I learned last time and make a version 2.1.

Grifter said he was okay with work-in-progress “untested” datapacks, so I made provisions as I set up my workspace. With Derpy set up as a VNC machine, I experimented with different arrangements of windows on both Derpy and my home Windows machine until I ended up with something that works.

My creative server with the secret boat race development laboratory in an Ice Spikes biome served to manufacture the structure files. From there, I would switch over to Derpy, where I would copy them into the “original” datapack along with the “originals” of the functions to run the whole setup. The datapack was stored in a special file on the desktop beside another file called Nightly Backups. This file did not live up to its name. I saved between two to four zip files per day there; whenever I felt I needed to make a progress report to Grifter I would open a terminal and run a command to zip the datapack for both storage and transmission.

The greatest flaw I perceived in my design last time was my inability to be sure someone else could set the game up on another server, so I created a “Clean Paper Server” to test my datapacks myself where I wouldn’t need to worry about anything accidentally relying on some scoreboard objective I forgot to make sure was created. Once I was done, all I had to do was delete the old server, copy the Clean Paper Server beside itself on Derpy’s desktop, copy the datapack into Clean Paper Server (copy 1), launch the server, hop in with my client on Windows, load both halves of the arena, and install the Ice Boat Challenge game. If this were something I was planning on needing to do over the course of a month or more, I would have looked into writing a script to automate what I could on Derpy.

The design objectives of this version remain almost the same as my first attempt at porting the boat race. I want to minimize the load on the server, while making it as easy as possible to develop other games for the system. I ended up coming up with a number of standards, like a “home” block for most command blocks in the Level Slots (floors a level can be loaded into) to run their commands from, forming a sort of two-way vector between the homes of each Alcove and Level Slot.

One improvement I noted in my notes for future development was to set up something similar for navigating the alcove. When Grifter introduced the /data merge command to me so I could use the same structure block for basically anything I wanted, he hinted that Minecraft 1.14 might actually let commands pipe information stored in such structures as input to other commands. I made sure to note that in many places within the comments of my functions. /data merge also opens up the possibility of multiplayer games that hijack functionality from the alcoves, so I made provisions for that functionality in the future.

This time around, the game starts when a player steps in an alcove. The Game Center operating system checks the player’s score for what game they want to play, and loads that game’s loader into the Level Slot for that alcove using a structure block in the home coordinates. The loader checks what slot it’s in, then checks what level to load for the player in the Level Slot’s alcove. It tries to load in the first half of the level, but if it fails for any reason, it has a carefully staged self-destruct to reset the Level Slot while making sure the redstone bits don’t accidentally pop off while multiple blocks are being changed (I’m pretty sure Minecraft likes to work from low y values on up based on an experiment I did with End Gateways, and my observations here back up this hypothesis).

After the loader, a series of command blocks embedded into each level takes over. These blocks handle spawning in the boat, teleporting the player, animating the boat so it does its cool spin, and checking for if the player has won or left their boat. It is here that I fixed a bug where the last version would smash players’ faces every once in a while. I used some redstone to space out commands. One of the last major bugs I faced before I got the main show working was dealing with how I hooked up the win detector. I had two blocks on repeat calling the same function and feeding into the same conditional chain command block. I ended up moving the win condition and giving it its own, dedicated command block.

A very big thanks to Grifter for all the help he’s given me this week. He got me started and helped me build inertia until I understood things well enough to continue mostly on my own. He also provided a friendly Discord avatar for me to explain the problem to in the hopes he would have time to help fix my current bug, only for me to keep working on it and often find it on my own.

A final word: documentation. Documentation is the link between you programming now and whoever is working on your project in the future. I have a whole folder in the root directory of the datapack with what the logic behind the Game Center and the Boat Challenge game is supposed to be. It also has a list of known bugs, a list of naming conventions I found helpful, credits, and even some general notes for what to do for if someone ever rewrites the project again

Final Question: Have you ever gone back to redo a project, only to find you’ve sped up by a fairly large margin


MineCraft Boat Race Port Part 7

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am presenting my work to update the Boat Race from Titaincraft Season one’s custom dimension, The Above. Let’s get Started.

If you are here from the server and spot the “Part 7” in the title, don’t worry. I’m writing this post as a fresh introduction to the project. If you’re interested in the development of the project, feel free to go back and have a read, and if I post about further development, Part 9 and above will also be available.

The Above’s boat race was originally built by Duke and  2Cubed with testing by dminer78. In the original game, players would wander into an ice cave and get teleported to the lobby where they could pick an arena to play their personal next level in. Each of the five levels has a different maze to navigate, ending with a row of gold blocks serving as the finish line. After completing the last course, the game would award the player with a Tango head, the special currency of The Above’s prize system.

The new edition used Duke’s levels but has many technological improvements over 2Cubed’s programming. The 1.13 execute command’s overhaul means that whole blocks of commands that were running all the time are replaced with one or two commands with a smaller footprint on the server’s CPU, and they only run as often as needed. A planned time trial mode would increase the replay value (besides the Tango heads). As part of this planned feature, there would also be a way to choose what level pack you want, and whether or not to shuffle the levels among other, new level tracks. And thanks to MineCraft’s introduction of functions, I decided to rebuild the game so it could be easily expandable; not only should it be fairly easy to add even more new levels but also new games as well as time goes on. For now, I’m calling it the Modular Game Center.

Working on this project, I learned a lot and overcame many challenges, many with the help of Jamcdonald120 and a few others. If you want to learn about a few of them, go back and read parts 1-6. As of this writing, the Modular Game Center still needs a little work once 1.13 gets a stable release and Spigot gets its update in turn.

Final Question: What game would you like to see added to the Modular Game Center?

MineCraft Boat Race Port Part 5

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am excited to announce the near completion of my project. Let’s get started.

Who would have known, not more than 24 hours after writing my last post, 12 after it went live, I would finally have the last major chunk of code working for my demo? I even made my goal of finishing before MineCraft 1.13 launched!

This week was kind to me even after my breakthrough, as I not only finished that up, but I got the other two alcove/arena combos working. Jam was helpful with getting the /tellraw commands working when he told me to just change out the old selecters.

I also worked over the end of level win condition, patching a bug where you could import a boat and cheat your way to the end. It turns out the boat would sometimes get stuck on elevators and break apart, forcing the player out of the level and resetting their progress. I made the level require the use of the original boat by setting (and checking for) an invulnerable flag on the boat. Unfortunately, I have no way of testing the invulnerable flag on glitching boats.

As it is now, I think the experience is at about 99.9% of the original. The original boats spun in air as they were summoned, and I still need to nail the /teleport commands.

I showed my work off to a few people this week. Duke, the guy who built the levels and my first guest after the workable demo, came by and helped me with a potentially embarrassing bug for when Tango (the owner of the Patreon server I play on) eventually does a blind reaction. New players need a valid score before they can enter the level for the first time. I fixed that for him and when DropDaBass, the server’s head moderator, came by.

There are still a few minor bugs. Sometimes timings don’t work out the best and you take a little damage on the way to the arena. Once in a large while, the level unloads around you without returning you to the lobby. There’s trouble with FPS (Frames Per Second) when connected over the Internet and a level unloads. There will always be something to polish.

One of my major goals for this build is the flexibility to add more games. I brought another patron over called Pendl3, who is looking to help me with my random throw away idea of a golf course. Getting the code ready for running dual games will be interesting, but I will complete the challenge.

Final Question: Simple, what games should I add? I think it would be good for me to add a few a year and they can either players or moderators swap them out with a control panel.