Laser Purr-suit
Got crazy kitties driving you batty? Check out this Raspberry Pi-powered laser turret that leverages computer vision to entertain cats.
Adopting kittens is like embarking on a whirlwind adventure that you never knew you signed up for. It all starts innocently enough when you stroll into a little pet shop with its rows of adorable, sweet, and seemingly calm little kittens. Your heart melts as you gaze upon these furballs of cuteness, peacefully nestled in their cozy cubbies. “How hard could it be to raise a couple of these angelic creatures?” you think to yourself, blissfully unaware of the chaos that is about to ensue.
Fast forward to the day you bring your newfound furry companions home. Those sweet little faces that once radiated innocence now reveal themselves as the masterminds behind an epic campaign of feline mischief. As if on a secret mission, they transform into tiny whirlwinds of boundless energy. Countertops become launch pads for gravity-defying leaps, and the floor becomes a racetrack for their turbocharged zooming.
Their mischievous endeavors don't stop there. Shoelaces become their mortal enemies, curtains are playgrounds for daring acrobatics, and anything that remotely resembles a cardboard box becomes a battlefield for their imagination. You quickly realize that the serene pet shop scene was merely an illusion, and you've unwittingly become the co-star of a real-life feline circus.
Despite the madness, you quickly realize that you would not have it any other way. That is how Hoani Bryson felt after adopting a trio of kittens he found abandoned at a racetrack. But the limitless kitten energy was a bit out of control, and playing with them as a full-time job was not in the cards. So Bryson came up with a technological solution to keep the cats happy and out of trouble.
Anyone that has spent any amount of time with cats knows that they love laser pointers. They will stop at nothing to catch the red dot, even if it means executing death-defying leaps and gravity-defying twists. So Bryson built an automated laser turret to keep the kitties entertained while he goes about his normal business. But just randomly shining a laser around will get boring before long, so some intelligence had to be built into the system to stimulate the cats’ hunting instincts.
The result of his efforts is a ceiling-mounted device called LazerPaw that uses computer vision to track the locations of the cats, and move the laser away from them as they give chase. A low-power red laser was used for safety, and was attached to a servo pan-tilt module along with a camera. By moving the camera and laser together, Bryson did not have to worry about tracking its position ― the laser was always in the center of the image frame.
A Raspberry Pi Zero 2 W was leveraged to provide processing power, and was paired with a Raspberry Pi NoIR Camera Module to capture images. A ring of NeoPixels was added to display the status of the system, and some 3D printed parts were produced to mount LazerPaw to the ceiling.
To make the most of the Raspberry Pi Zero 2 W’s available resources, the cat detection problem was simplified a bit. A red-colored flooring was laid down below the camera, such that the cats would clearly stand out against the background. That allowed cat detection and localization to be handled relatively easily using a thresholding algorithm in OpenCV. Bryson developed an algorithm that will move the laser away from the cats — and the closer they get, the faster it moves away. There is also a safety feature that causes the laser to turn off if it is pointing directly at one of the kitties.
LazerPaw can be activated either by a pushbutton on the device itself, or via a web interface that also streams images so that Bryson can check in on his furry friends while he is away. He says that his cats love to chase the lasers around, so it sounds like LazerPaw is helping to restore peace in his home.
If you would like to build your own intelligent cat laser turret, the source code is available on GitHub. And if you just cannot get enough cats and AI, make sure you check out CatGPT — it is just purrfect!