PHOTOGRAMMETRY

“Photogrammetry is the science of making measurements from photographs. It infers the geometry of a scene from a set of unordered photographies or videos. Photography is the projection of a 3D scene onto a 2D plane, losing depth information. The goal of photogrammetry is to reverse this process.”

I got interested in this process when I read an article from the website Instructables. It was about using a bunch of Raspberry Pi’s with cameras attached to take pictures of a subject from all angles and creating a 3D model from the pictures. This was written a number of years ago. The RPIs were all linked together so they took the pictures within milliseconds of each other so in essence capturing the subject in an instance of time. A person can’t sit still for very long to get pictures from all angles so a guy came up this that project. He used the Autodesk software program 123D Catch. It is not available any more.

I searched for quite some time before I found a viable alternative that wouldn’t break the bank. The software I found is called Meshroom developed by AliceVision which is an opensource program which means FREE. It is mind boggling to me that a group of programmers could develop such software.

“The AliceVision project is supported by the ALICEVISION association, a non-profit organization whose ambition is to democratize 3D digitization technologies from photographs. The association has been created in July 2020 by 14 founding members from the European academic and industry sector, who have been collaborating in the field of 3D computer vision for cultural and creative industries since 2010.”

It essentially converts 2D pictures into a 3D model. Granted you need to take a lot of pictures of the object from as many angles as possible to get a good model. But even so, I can’t imagine the complexity of the program to accomplish this task.

I downloaded the program and decided to give it a try. I watched the videos on how it works. I pulled out on of my european moose mounts and set it on a stool so I could get pictures from all angles. I proceeded to take about 50 pictures and loaded them into the software. I started the program. It errored out about halfway thru its cycle. Looking in the logs, the error was: Error: This program needs a CUDA Enabled GPU. I checked my graphics card driver and it had the CUDA enabled. I then searched their help file and they recommended that you load the lasted driver for your graphics card.

That sent me down the rabbit hole. Three or four hours later I had the latest driver installed and working so I tried running the program again. After two and half hours it finally completed. Took a bit of messing around to figure out how to see the results and find the model file. The finally product can be found by right clicking on the last box in the pipeline called “Texturing” and select “Open folder”. You will then find an object file (*.obj) called “texturedMesh.obj” in this folder.

I then opened this file in a program called Meshmixer. I took the pictures in a small room so this file contained lots of clutter from all the walls and stuff in the room. The moose skull was a very small object down in the middle of this mess. An hour later after deleting out everything other than the skull, I found the skull to be vary lacking in detail. On the video it said you could just take more pictures and add them in. So I took another 40 pictures and tried it again. The results were better but still disappointing.

I decided to take the skull outside and take the pictures so I wouldn’t have all the close wall clutter. I also found a couple settings in the documentation that clicking on the second pipeline box “FeatureExtraction” you can set the attribute “Describer Preset” to ” High” and clicking on the “Meshing” box and setting the attribute “Min Observations angle” to “30”. I then ran the software again and got much better results. I was able to clean the model up in Meshmixer and save it off as an STL file that my slicer program can use create the gcode for my 3D printer. I printed it and was quite happy with the results.

It is still amazing to me that you can convert 2D pictures into a 3D model.

Design Progression of the Mouse Trap

We have a cabin that sits empty a portion of the year. We have arrived to find everything covered in mouse turds and urine. Then spend the first day cleaning everything. We have even found afterbirth on the sheets of a bed once, quite disgusting. My wonderful wife now puts everything in plastic totes when we leave to keep the mice out.

Regular mouse traps work great. Problem is when you set 15 traps and catch 15 mice but there are 25 in the cabin, you still end up with mouse crap everywhere. Poison also works well but them sometimes they crawl under the stove or somewhere inaccessible and die. Then you have to deal with the stink of dead mice. Sometimes they even become immune to the poison and you get little green mouse poison turds all over.

I tried the beer can smeared with peanut butter on a dowel over a 5 gallon bucket. That worked pretty well but some of the mice just wouldn’t venture onto the can so we still have some of the mouse mess. I found a design on the web that had an enclosure over the bucket with a trap door that was triggered by a motion sensor to trigger a motor to pull open the trap door. I thought I’d try and build one of those.

I spent a few hours on Fusion 360 modeling program and designed the enclosure and trap door to print on my 3D printer. Decided to use an Arduino controller and one of my spare servos to pull open the trap door. Bought a small inexpensive motion sensor to detect the mouse. Used a rare earth magnet to hold the trap door closed. Added a long pull arm to the servo and a string attached to the trap door to pull it open then push it back up to magnet. It took a lot of adjustment to get the magnet to hold the trap door closed but weak enough to allow the little servo to pull it open. It worked ok until the temperature dropped, then the motion sensor kept false triggering which seemed to scare the mouse away from the trap. I replaced the motion sensor with a thru beam photo eye detector. This worked better except the photo eye drew too much current and drained the batteries too quickly. Below is the trap.

While scouring the internet for a better sensor, I found the walk-the-plank mouse traps. Great concept but a lot of reviews that it was hard to get the magnets adjusted just right. Seems they wok well but occasionally get stuck then the mice would eat all the bait. I thought I’d take that concept and marry it with my original one. So after a few more hours on the design software I came up with a walk the plank style but using a servo to drop the plank. I still needed a better sensor. Looked at proximity switches but they are quite expensive and heavy for the end of the trap. Finally came across the TTP223 touch key switch module. It was designed to work with Arduinos as a touchless button. They sense any dense object that come in close contact to the sensing area. I bought a few and tried them out. Seems to be the perfect solution to my problem.

After many 3D prints and many redesigns to get the sensor in the correct spot, servo mount correct, cam working properly, I had a decent working prototype. I put it in the cabin and caught 2 mice the first night. Was glad to see that a mouse would trip the sensor. Still had a battery problem. Did some intense testing and found the servo was draining the battery even though it was not enabled. Added some circuitry to cut the power to the servo until the sensor was tripped. This seemed to do the trick. The whole setup was only drawing 180 micro amperes at rest which means 4 AA batteries should last many months depending on how many times it is triggered.

As Ralph Waldo Emerson once wrote “If You Build A Better Mousetrap The World Will Beat A Path To Your Door”, I thought why not try and sell my design. It was hard to come up with a price. It took about 6 hours to print the trap and had about $22 in parts. Took quite a bit of soldering to get it all put together. I built a few and put them on Ebay. After a couple weeks I sold two. The same guy bought both, Shawn Woods. He contacted me later and said he was going to make a video of it and put it on youtube on his MouseTrap Monday. I had seen some of his videos and thought that would be the best free advertising I could hope for. He said to be ready for a ton of orders. He wasn’t wrong. Had about 50 people wanting to buy it. I scrambled to get parts and build the traps. I decided to build my own printed circuit board (pcb), that would cut the soldering time considerably.

That was another learning experience. I used the Autodesk Eagle software to design the board. Luckily it worked out on the first try. It is more expensive to build my own pcbs than using the inexpensive Chinese arduino pro mini boards but saves valuable build time. Plus I’ve ran into problems with some of the inexpensive pro mini controllers. Making my own, I can assure the quality.

Have been making small improvements from customer feedback and feel we have a good quality product now. Had a few requests for a larger trap that would work for rats. We have developed one but have no rats around here in Wasilla to test it on. Hoping to get Shawn to test it in his surprisingly rodent filled barn.

The Rat trap is now live. It is a longer more beefed up version of the mouse trap. The batteries don’t last as long in it as the mouse trap since the flap is twice the weight, it takes more power to lift it. The mouse trap seems to still work with the battery voltages as low as 4.4 volts but the rat trap needs at least 4.8 volts.

We are working on a new version of the mouse trap. Had a suggestion from a viewer which lead to this new design. Basically the flap is raised up above the main body and extended over the body so the whole plank will tip giving less opportunity for the rodent to hold on. Still in the prototype stage but it is looking promising.

SIDE NOTE: We have been testing the battery life in a couple mouse traps starting 11-23-20. Triggered it every day for the first month now just triggering every couple days or once a week. The battery is still at 5.37 volts as of 5-27-21. The servo will continue to operate down to 4.6 volts. The 4 Duracell alkaline batteries voltage started at 6.42 volts. The traps have been indoors. Battery life will degrade much faster in colder temps. 6 months and still going strong.

Chicken Coop Automation

I started out with a linear actuator to open/close the coop door. It is wired to a couple relays that are controlled by an Arduino microcontroller with a toggle switch to send it the signal to open or close the door. After getting that to work, I added a couple temperature sensors to measure the temperature inside and outside the coop. I then added a 2 line by 16 character liquid crystal display to display the temperatures. I then added another relay wired to an outlet which I have a heating lamp plugged in to. I programmed the Arduino to turn on the power to the outlet when the outside temperature gets below 25 degrees F to turn on the heat lamp and keep the chickens warm.

Side Note: (Arduino’s are amazing little devices. They give the common nerd an easy introduction to programming and designing with microcontrollers. They have built a great platform around it and there are thousands of libraries you can install with preprogramming to make it extremely easy to add devices to it. Like the temperature sensors and the display, add the libraries, wire them up and with a few lines of C+ programming code you are off to the races. Where as microcontrollers like the popular Microchip PIC series are feature rich but can be quite intimidating to get working. Each feature has control registers that you have to setup plus a bunch of configuration bits that you have to set. I spent many an hour trying to just get an output to toggle an LED. To Microchips credit though, they have updated their software (MPLAB X-IDE) and have a built in Code Configurator that lets you select features and it configures the bits for you. The Arduino IDE does all this in the background and you never have any exposure to the actual internal workings of the controllers.)

After I got all that working, I did a lot of research on the web on home automation with Arduinos and decided to add a Raspberry PI (RPI) single board computer to the mix. The RPI has an ethernet connection, blue tooth and multiple USB ports. It has a built in web server as well. I thought I’d build a webpage on it so I could open and close the chicken coop from that instead of going out to the coop to do it.

Venturing into the RPI world, I had to learn a new operating system (Linux). There is tons on info on the web. I ran into lots of problems along the way, but any problem I had someone else also had it and posted the problem where someone else was kind enough to help out. Bottom line is with a well worded search you can find an answer on the web to just about any problem you run into. I also had to learn a bit about HTML to make a webpage and the language Python which works well on the RPI. Also had to load the Apache web server software on the RPI and setup. Again, how to do all this can be found on many different places on the world wide web. I connected the RPI to my router through its wifi connection. Went into the router setup and reserved that IP address for the RPI so that the address will always be the same. After a power outage or router reset, the router assigns addresses to each device as they try to connect to it so they can be different each time.

I added a 915 mhz transmitter to the chicken coop Arduino and bought a Moteino (from LowPowerLabs) which has a built in 915 mhz transmitter. I bought a FTDI adapter (serial to USB) which is plugged into the Moteino. I have a USB cable connected to the FTDI board and into the RPI. I wish I had found the Moteinos to start out with because it was rather difficult to solder and wire up the little transmitter to the Arduino. LowPowerLab.com has a ton of great info on working with the transmitters. They have built an easy to use library with lots of example code to get you started. The owner Felix will even reply to emails on his products.

Once I got the two controllers talking and passing info, I had to figure out how to get that into the webpage. There are lots of gateway software packages you can buy, but I wanted to figure it out on my own and keep it as simple as I could. I experimented with writing some code in C+ but had problems with it connecting to the USB port consistently. Ended up with some Python code running in the background on the RPI that opens the USB port and continually monitors data coming in. Once that was working I had to figure out how to store the data that was received by the coop controller.

Next step was loading a database system on the RPI. I went with MariaDB which is a free version of MySQL. This resulted in having to learn SQL programming. Luckily I had some experience with SQL in a previous job so it wasn’t to hard get it working. I built a couple tables in the database to store the data received. I then had to setup a connection to the database in the Python program so it could push the received data into the database.

Now to get the data from the database to the webpage. This led to learning another language PHP. PHP is an open source powerful server-side scripting language which is used for creating dynamic webpages. Adding some PHP scripting to my HTML webpage lets you setup a connection to the database and query out the data you want then display it on the webpage.

With that all done, I could open the webpage from my computer by just opening a new tab in my browser and typing in the ip address assigned to the RPI (198.162.44.88). I could now see the info I programmed into the the webpage sent over from the coop Arduino. Now I wanted to be able to see it from any where I could access the internet. So I got bought a domain name from NameCheap.com. Costs about $4 a year to have your own domain name. Once you have that all setup, you have to tell them where your web server is located which is finding the IP address assigned to your router from your ISP (internet service provider). With that all complete, I could now see my webpage from anywhere with internet access.

The next problem that arose was when the router reset after a power outage, the IP address would change. You can purchase a set IP from you ISP but it was way to unreasonable for me. After searching the web once again, I found a script you can run on the RPI to retrieve your routers IP address (wget -q -O – checkip.dyndns.org|sed -e ‘s/.Current IP Address: //’ -e ‘s/<.$//’). And another script that would push that address to your Domain name server. I put this code into another Python program running in the background and have it executing every hour. Probably easier and better ways to do this but being a novice at all this, this is what works for me.

Being your typical lazy American, the next idea I had was to add more code so that I could open and close the chicken coop door from my webpage (www.beservices.us). That required another table added to the database to hold any requests from the webpage. Added more PHP scripting to have buttons on my webpage to open/close the coop door. If one of the buttons is clicked, it then writes data to the “Request” table in the database. (I actually added another webpage that is password protected so random people are messing with the chickens). Code was added to the Python script monitoring the USB port to also monitor that table. If a request is seen in the table, it sends that data out the serial port to the Moteino. Added code to the Moteino to send any data it receives on the serial port to the coop Arduino. Added code to the coop Arduino to open or close the door depending on the data received from the Moteino.

With that all working, I thought why not just have the RPI send a door open signal each morning and a close door signal each evening since the RPI keeps the actual time and date updated from the web. I added a couple data entry boxes on the coop webpage to enter in the time in the morning and evening to open and close the door which is also stored to the database. Updated the Python code to check the time and if it was equal to the open or close time, then send the signal to the coop controller to getter done. I also added an Enable/Disable button so if we don’t want it to automatically send the signals we could disable it from the webpage.

I learned a lot doing this project and it has been running flawlessly for more than 2 years. Only glitch I’ve had was a brief brownout that locked up the RPI. I have a small battery backup UPS (sold by LowpowerLab.com) but it didn’t catch that quick brownout. Works great on actual power outages though.

If anyone wants more info on our Chicken Coop Automation project, drop us an email and we’ll post some schematics and code snippets.