Tuesday, May 24, 2016

Motion Detection with Multiple RTSP Cameras

Well, here we go again.  One of our cameras went on the fritz, so I started looking.  There were two decent cameras that had the same resolution and the same outdoor ratings (e.g. windproof, water resistance, and dust resistance), so I picked them up.  Unfortunately, they do not expose an jpeg stream, so I had to use a different Linux motion tool, available from :

Now for the REAL down-side.  I compiled it, and loaded it up with two camera streams.  It worked great, for a day or two, and then the process would vaporize. I found an obscure message in the log file that consisted of :
    May  7 00:36:00 ch abrt[29014]: Saved core dump of pid 26188 (/usr/local/bin/motion) to /var/spool/abrt/ccpp-2016-05-07-00:35:55-26188 (548212736 bytes)
So, I loaded the application up, then attached to it via the debugger (gdb motion 123456) and got the following stack trace after a few days :
    [New Thread 0x7fffecdfa700 (LWP 23598)]
    [New Thread 0x7fffd3fff700 (LWP 23599)]
    [New Thread 0x7fffd21fc700 (LWP 23600)]
    Detaching after fork from child process 23603.
    Detaching after fork from child process 23604.
    
    Program received signal SIGABRT, Aborted.
    [Switching to Thread 0x7ffff72a8700 (LWP 23594)]
    0x00000030b5032625 in raise () from /lib64/libc.so.6
    (gdb) bt
    #0  0x00000030b5032625 in raise () from /lib64/libc.so.6
    #1  0x00000030b5033e05 in abort () from /lib64/libc.so.6
    #2  0x00000030b5070537 in __libc_message () from /lib64/libc.so.6
    #3  0x00000030b5075e66 in malloc_printerr () from /lib64/libc.so.6
    #4  0x00000030b50789b3 in _int_free () from /lib64/libc.so.6
    #5  0x0000000000416b20 in netcam_cleanup (netcam=0x7fffa0000030, 
        init_retry_flag=0) at netcam.c:2581
    #6  0x0000000000412d28 in vid_close (cnt=0x678a10) at video_common.c:555
    #7  0x0000000000406f19 in motion_cleanup (cnt=0x678a10) at motion.c:991
    #8  0x00000000004097b8 in motion_loop (arg=)
        at motion.c:2231
    #9  0x00000030b58079d1 in start_thread () from /lib64/libpthread.so.0
    #10 0x00000030b50e88fd in clone () from /lib64/libc.so.6
    (gdb)
So, I then checked in the log, found the above stack trace was not related, and that that run may have had other issues going on.  My real stack trace is :
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-redhat-linux-gnu".
    For bug reporting instructions, please see:
    ...
    Reading symbols from /usr/local/bin/motion...done.
    
    warning: core file may not match specified executable file.
    [New Thread 4667]
    Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
    Loaded symbols for /lib64/ld-linux-x86-64.so.2
    Core was generated by `/usr/bin/keyutil --command genreq --ascii --renew /etc/pki/tls/certs/cottonwood'.
    Program terminated with signal 11, Segmentation fault.
    #0  0x00000030b5047e2c in ?? ()
    Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.149.el6_6.5.x86_64
    (gdb) bt
    #0  0x00000030b5047e2c in ?? ()
    #1  0x0000000000000023 in ?? ()
    #2  0x00007fff1c7768c0 in ?? ()
    #3  0x0000000000000000 in ?? ()
    (gdb)
Bah!  Next, in the logs, I found :
    /var/log/messages:May 22 20:29:00 ch motion: [1] [ERR] [EVT] event_image_snapshot: Could not create symbolic link [01-20160522202900-snapshot.jpg]: No such file or directory
    /var/log/messages:May 22 20:29:30 ch motion: [1] [ERR] [ALL] create_path: Problem creating directory /home/media/security: Input/output error
    /var/log/messages:May 22 20:29:30 ch motion: [1] [ERR] [ALL] put_picture: Can't write picture to file /home/media/security/cameras/camera-backyard//01-20160522202930-snapshot.jpg: Input/output error
I completely missed the "Input/output error" and checked the filesystem location, only to find my entire disk had failed, so it could not write videos.  Sometimes, debugging can be such a pain!  Here comes a nice recovery fee and a nice fat check going out for a NAS with mirroring!

Tuesday, April 26, 2016

Who is Your Friend?

Often, I'm amazed at how many people know my wife.  Considering how amazing she is, it's not baffling, just awe-inspiring regarding how many lives she's effected.  She is an amazing wife and friend.

Anyway, going back through some paperwork, I ran across the following :



It made me laugh, that memory.  I'd better tell you the story.  We were visiting family in the area, and were out traveling one of the back roads.  As we're cruising along at 60 MPH (the speed limit was 55 MPH), she nonchalantly mutters something about her old "bucket of bolts" hitting 79-80 when she was growing up.

I kept it at 60 for that phase of the drive, but on the way back, I thought, "Why not?"

We hit some speeds that would have ended up with an immediate impound and a revoked license.  I slowed down to 60 MPH, but it suddenly felt relatively slow.  I found about 75 MPH was slow, but not unbearable.  My wife (still relaxed) said, "that's a cop up there - just pull over because it's too late".  (He was driving in the opposite direction, and a mile up the road, he pulled over and turned on his lights).

We passed him, and pulled to the side to wait for him to catch up.

Turns out my wife knew him.  He gave us a warning.  It still makes me laugh.  She knows EVERYBODY!

Thursday, April 21, 2016

More Math - a Lathe Countershaft

So, I already found math is very useful for calculating new change gears.  One question that has been bothering me is.... how fast does the treadmill motor turn?  It's from a NordicTrack C2000, and the motor is a Quadra M-204432.  It simply says "2.60 Peak Watts" and "1.5 Continuous Watts".  No specs on RPM.  I finally decided to determine how fast the little thing was turning, so I ran out and grabbed a few measurements.

The treadmill had a max peak of 10 Miles/Hour.  That equates to 10x5280 Feet/Hour, or 52800 Feet/Hour.  For RPM, we need a Per Minute, so we have to divide that by 60 (because everyone knows there are sixty minutes in an hour).  That gives us a distance traveled of 880 feet per minute at 10 miles per hour.  My units of measurement are in inches, so I have to multiply that by 12.  My final Max speed is 10,560 inches per minute.

I grabbed the diameter of the bar that the tread was turned by (a rod that sits on two bearings).  It came out to 6 1/8", or 6.125".  To get the maximum speed, the outside has to travel around 1724.081633 times per minute.  Incidentally, 1725 RPM is a standard motor speed.  But, we're not even to the motor yet - we're still on the treadmills rolling pin speed.  Now, the pulley ratios come in to play.

Calculating a pulley ratio is fairly simple.  Divide the diameter of the driving (or motor) pulley by the corresponding pulley on the other side.  In my case, the motor pulley is 1.125" across, and the rolling pin pulley is 3.5" across, or a ratio of 0.285714286.  Now, one is normally converting from motor speed to spindle speed for things like lathes (which is "multiply the motor speed by the ratio"), but we are going backwards.  We have to divide the speed above, so the final ratio comes out to....

... 6,037.5 RPM?  That doesn't make much sense.

But, it IS close to 6,000 RPM, and there are definitely treadmill motors out there that turn that fast.  However, I do not really want the lathe turning at 6,000 RPM, so I need to reduce the speed.  This countershaft will do two things for me - it will help me reduce the speed of the spindle (the torque will go up at the spindle), and it will let me convert from a serpentine belt to a v-belt, which is what I have on the lathe.

1725 is a good "don't kill yourself speed", but if using things like 3 jaw chucks, I'd probably say closer to 1200 RPM is a max.  I need a pulley ratio of 0.25 or lower to feel comfortable, but with the controller for speed, 0.25 is about right.  That would give me a maximum of 1500 RPM at the spindle - if I can hit the pulley ratio.  The right pulley size without a countershaft would be a 4.5" pulley.  My lathe spindle pulleys are 5" - so close enough, as it would slow me down a bit more - but I have to convert from serpentine to v-belt.

My problem is that I could only find a serpentine belt pulley that would match my motor pulley that was 2.2" across.  So, if I get a v-belt pulley that is close to the 2.2" across, that would eliminate the countershaft as the speed changer, and we'd only have to calculate motor-to-spindle - but they don't make them.  They do make 2.5" v-belt pulleys.  So, since I thought it would be close enough, I bought them, the 2.2" serpentine pulley, some CRS round bar and square tubing, a couple of pillow block bearings, and welded it onto a frame that can be put onto a hinge and bolted to the lathe table.  Before you look closely at the picture - remember, my welding was never professional - sometimes I just stink at it.




Because I have different diameters on the countershaft, we HAVE to calculate the speed of the countershaft, and then the speed of the spindle from the countershaft.  We do the work twice.

So, a 1.125" pulley to a 2.2" pulley is a ratio of 0.511363636 .  A 2.5" pulley to a 5" pulley is a ratio of exactly 0.5.  That means our final ratio on the countershaft is 0.255681818.  That ratio takes 6,000 RPM down to .... 1,534.09090909.

And a maximum of 1,534 RPM at the spindle is perfectly acceptable.  It's only spinning at 25 times per second.

Sunday, April 17, 2016

Book Scanner: Mechanically Complete

After agonizing about a broken fan on the 3D printer (yes, one successful print later, the 3D printer had a third part break), I started to wonder if I'd ever be able to print a camera mount for the book "scanner".

Yesterday, I had an idea (I would call it brilliant, but it was mine, and any ideas that come out of my head must be brilliant).  Instead of printing a plastic part... why not build it instead?  My brain went immediately to wood, as it would be the easiest to "mill" or to shape.  I was worried, though, about the wood splitting.  I needed some parts with a 60 degree surface to point the cameras at the glass platten. I kept thinking "sturdy", since the two parts had to hold a camera, and I did not want the cameras falling on the glass platten and breaking the glass and/or the cameras.  (Yes, wood was not my brilliant idea.)

Then something else hit my mind.  When I worked on the old Troybilt rototiller, I needed some steel for the recoil starter's dogs that engaged the pulley.  I had picked a piece of steel bar up, about 1/8" thick.  I thought about just welding three bars together and bolting it up to the aluminum extrusion meant to hold the mounts in place.

I grabbed the torch, and started heating the bar up.  Using a pair of ducks (commonly called "tongue and groove" pliers), I bent for the first angle.  The way it turned out was even better than I could comprehend.  I simply bent the first angle to 60 degrees, and cut off a length of it - I realized I didn't need the aluminum extrusion to support the cameras - the steel was sufficient.  I immediately built a matching one for the other camera, and drilled the holes.  One hole (the one on the 60 degree surface) needed to be tapped, so I grabbed my 1/4" taps and added some threads.  I put some threaded rod in place with a nut to lock it to the surface, and then the camera could just spin onto the mount.  Hooray!

Now to figure out the CHDK firmware hacks for the Canon cameras!


There are two glass plates, called "platten" (the German word for "plates" because scanners and copies have always called those parts "plattens") both set at 30 degrees from the main surface.  There are wooden supports underneath at the same angle for the plates to press against, so that when the plates are lowered against the supports, whatever is between them will be "flat".  The glass plates are mounted to two vertical drawer slides (you can see them in the above photo), with a cable (I used a vinyl-coated wire and pulleys) to lift both ends of the plates at the same time.  When the plates are down, you trigger a camera shot, then raise the plates, turn a page, and lower the plates.  Wash, rinse, and repeat.


The cameras are mounted onto 1/8" steel bar bent to 60 degrees.  This is because 60 degrees is perpendicular to 30 degrees (required for a straight-on shot of the page).  There are two cameras, one for each page.  Each camera will be loaded with CHDK (Canon Hacker Development Kit), a "firmware" designed to allow external control of the camera, or do things the native Canon firmware cannot do (e.g. saving the pictures as "RAW" images).  I simply need the CHDK firmware to allow me to remotely trigger a picture over a USB cable, and pull the picture down to the computer without filling up the camera card or with me trying to use the SD cards.  You CAN do this without the CHDK, but I'm just lazy.


The cable had to be attached to both drawer slides - I found that a single one had the thing going skewampus, and I didn't like that.  Getting the cables the same length was a little challenge, though nothing unsurmountable.

Here is what the view from the camera looks like (though, not the camera, just right next to the camera, since I am definitely too lazy to use a picture from the camera).


So, I just need to figure out the CHDK components (which I am definitely close to doing), and pick up a Raspberry Pi to act as the computer.  The Pi will be configured with a button so that all you have to do is raise the platten, turn a page, lower the platten, and press a button.  When done, the Pi should arrange all of the images and convert them into a PDF that can be loaded onto any tablet computer for your reading pleasure!

Friday, April 15, 2016

3D Printer Project - Complete.... Sort Of

So, this week, I finished up the 3D printer.  It's a FolgerTech Prusa i3 - not a bad little printer to put together.  There were a few issues along the way :

  1. The plastic parts broke when tightening - either it was weak, or I don't know my own strength
  2. One motor refused to run (the X axis), forcing me to procure a new one, which had to come from FolgerTech because I couldn't find one of the same dimensions anywhere else
  3. Bed leveling is nigh impossible, with the shorter springs and screws for attaching it to the acrylic frame

Aside from that, it went together fairly simply, and ran (at least once) :





I used the standard PLA test filament that came with the printer, and realized in the middle of the print that it was going to run out before it finished.  So, I grabbed the spool of ABS, and followed it through.  Not realizing I needed to increase the temperature, the joint between the two and also the ABS right after the PLA is weak, but that's my fault.  It still turned out :








So, I tried another print of the same part, using just the ABS.  I did not realize that Repetier-host (the software I am using on the Mac) will freeze hard if the screen saver kicks in.  It aborted in the middle, and the nozzle cooled while sitting right on the print, causing the plastic to curl around the nozzle and burn against it.

That part had progressed far enough along that it was still usable.  However, since that time, I failed for a day or two to get a good print.  After cleaning the nozzle again, I got one good print (a camera mount for the book scanner) :



Unfortunately, even with cleaning the nozzle, I have not been able to get a good print since then.  Very frustrating.  On top of that, one of the fan blades snapped, so the printer is now out of commission.  If I had done my math on that camera mount, it would have been great - but I needed it tilted at 60 degrees, not 30 degrees like I had printed.  Oh well!  You live and you learn!

Saturday, April 9, 2016

Another Project Bites the Dust

Well, now that you have that song stuck in your head, I got a few more projects completed.  I needed to get a fan installed (replace a light).  That was fairly easy :



The hardest part came because I misplaced the "instructions".  Really, I just needed to know how the braces bolted up to the ceiling to keep it stable.  Once those were in place, the rest was cakewalk - black wire to black, white to white, and green to the can (where it already was).

With that out of the way, I tried to focus on the 3D printer.   The parts had come in the mail, so I wanted to finish it.  However, one motor was malfunctioning.  It's my X axis, and couldn't move the printer head.  So frustrating that one was in bad shape straight out of the gate.  The rest is definitely complete, though.  I ordered a replacement, and (once it arrives) simply need to fire up the extruder and then I'm done.  (I also ordered a spool of filament while I was at it.)



With the "I can complete this" stuff out of the way, I decided to turn my attention to something that wasn't broken.  I wanted a new shaving razor.  I love the feel of the Mach3, but I have the "Fusion", and for Christmas, my sweetie pie bought me a razor kit from an online pen-turning company, woodcraft.  I wanted it done in Walnut (which I know I am allergic to, and, apparently, I am allergic to even walnut sawdust).  However, being a razor, I knew it would be in the elements (e.g. water), and water against woods is hard on them.  So, I turned it as I normally would, just a little smaller, and finished as I normally would without the polishing wax.  Once done, I took the turned project back into the house and coated it with clear, 5-minute epoxy :


Once the epoxy set, I took it back outside and re-turned it down to the real size that I wanted it, and went through the entire list of finishing steps again.  Looks great, and should last a long time!



Sunday, March 27, 2016

Spring Cleaning - Project Style

Well, one day a couple of weeks ago, I was told that I had too many projects going on at once.  Doing one thing for five minutes, then another for another five minutes - nothing was ultimately going to get done.  We had to itemize my projects :

  • Install ceiling fan in bedroom
  • Replace faucet in bathroom (finish had peeled off on the old one)
  • Finish South Bend Junior Lathe "milling" attachment, create a jackshaft so that I can use the old treadmill motor (different belts), and also figure out a controller for that motor
  • Hang quite a few photos to create our "travel wall"
  • Teach in Church
  • Corvette
  • Oil changes in the Truck
  • Run an Ethernet cable for a printer at the in-laws
  • Tiller
  • Lawn (rake so the grass can grow, get it fertilized, and kill some moles)
  • Get the 3D printer up and running
  • Finish the book scanner so a few books can be digitized (and get them digitized)

This is the list that I can think of right now.  I know there is much more that I am forgetting, but that will return to my head once we get some of the stuff checked off.  As it is spring, I knew I needed a little project "spring cleaning".

So, I set off to finish a few things.  No, the Corvette isn't one of them, though I wish it was.

I started out focusing on some of the easy stuff to get something crossed off the list.  First, I threw some pieces of the tiller back together - I am missing one piece that will prevent me from finishing that one (the recoil pulley).  The Kohler K161T engine is complete (the starter assembly is not).  The transmission rebuild is done (seals replaced, belts installed, reverse pulley replaced), and everything looks good.  I bought that pulley (it had a lot of dust on it as it sat in the companies parts bin for a few decades), installed it, and cranked the tiller up.  I had to tune the carb, but was then able to put it to work a little bit.  For an old machine, it runs pretty well, and boosted my confidence pertaining to things with engines (the Corvette has me a little nervous).





I next decided to work on the travel wall.  It doesn't look too bad, actually.  I was thinking with portrait and landscape photos, it would look terrible.



I also decided to throw together a jackshaft with the pulleys I needed to interface between the v-belts and the serpentine belt that I'd have on there.  I broke out the welder and some random stock I had laying around, and tacked it together :



Once that was completed, I realized I had quite a mess around the wood lathe - the tools were everywhere, and were moved every time I needed access to a tool.  When visiting the in-laws and running their cable for their printer, Mr. In-Law demonstrated a lathe tool rack (something I was thinking needed to be 3D printed, and was one of the reasons I procured the 3D printer).  It was simply a few boards with holes cut in them the size of the tools, with a third board beneath the bottom one to keep them from falling through.  I grabbed my hole saw and some scrap wood (gotta get rid of the scrap somehow, eh?) and built some quick shelves :


I grabbed a photo of the "shop", too.  It looks much better (other than the sawdust, and the holes from the lathe tool rack) than it did a month ago.



While out in the shop, I remembered the package I had laying around that included the "precision ground" 4" angle plate.  I had purchased it to put between the cross slide of the South Bend and the compound, moving the compound into purely the vertical axis I needed.  I can mill, except for three things right now - I still haven't gotten to the motor, I don't have the collets, and I need a vise I can attach to the compound t-slot.  Not sure they make something like that, but at this point, I doubt I'd have a hard time - if I had the stock for it.  The angle plate sure looks good in there, though :





Once that was done, I replaced the faucet.  Nice to have a finished bathroom again down there, and have it done right.  Also, I tossed in some refractory to the furnace to try and finish that.  Didn't turn out quite like I was hoping for (it is off-centered, and below the top lip).  I'll have to try again :



I feel like I had a very productive weekend.