Camera SoftwareScreenshotA little bit of stuff is working now, but as you can see from the latest screenshot I'm not actually taking pictures of books yet :-). However, I have added navigation buttons so you can page through the image directories to review things. It also no longer asserts when you start it without a UK1104 plugged in. The latest update has improved error recovery and the reliability of sending commands to the UK1104. |
I've also got a config dialog hooked up now:
Bits and PiecesI'm using a UK1104 usb relay and digital I/O controller made by Cana Kit to control the camera and lights from my computer (relay to toggle the USB power on and off, relay to turn the lights on and off, digital input to click the button to take the pictures). I'm using the QextSerialPort 3rd party Qt class to talk to the UK1104 (which looks like a serial device). I'm also grabbing code from an IMAP polling program I'm working on to run the simple comunications protocol with the UK1104. I'm using libudev to notice the camera plug events and trigger gphoto2 (apparently HAL is obsolete and libudev is the new "in" thing employed by all the Linux Cognoscenti, so I switched away from HAL). I'm running gphoto2 to download the latest images and delete them from the SD card when the camera enters USB mode. (I tried to understand libgphoto2 but decided it would take too long to decrypt.) I've tested most of this, but now I want to put it all together in one package. Naturally I'll need to actually finish my scanner and get the cameras attached as well. PrototypeI've made progress on the software. I can run the relays on the UK1104 when I press the click button, and I can download the images when the cameras show up in udev. I also update the image labels with the most recent left and right images after I download some new pictures. Yet to do is better error recovery (I pretty much just assert for everything at the moment), polling the UK1104 digital input for a button press (so I can use a button on the scanner instead of having to click the mouse on the computer) and real configuration save and restore (I just have a dummy config class with my default values all hard coded). The latest snapshot of the code in progress can be found here. I continue to fiddle with the code. Having used the libudev interface to find the cameras, I now also use it to find the UK1104 so it discovers it when you plug it in (or if it was already plugged in). It also notices if you unplug it and no longer starts reading EOF over and over. Cable SurgeryHey! Things are coming together. I surgically modified one of my USB extender cables, extracting the red +5V line and adding some short extensions so I could run it through a relay on the UK1104 board: After playing with the SDM script some, I finally got a version that works exactly as I want. I trigger the photograph with a short click of the relay, then trigger USB downloading with a longer click to provide power while I'm downloading the images. Here's the SDM script that interacts with my program: @title Shoot Books :loop sync_off press "shoot_half" wait_click 1 is_key k "remote" if k<>1 then goto "loop" click "shoot_full" release "shoot_half" sleep 300 :pool sync_off wait_click 1 is_key k "remote" if k<>1 then goto "pool" upload_images_for 6 goto "loop" end Just need to do some timing to make the computer and the camera agree on how long to wait at different points. I also may decide to batch up the downloads and not download each image as it is taken. There doesn't appear to be any way to prevent the lens from retracting during the USB connection, and I don't want to wear out the gears by constantly running it in and out. (So even though I can get this to work, Eye-Fi might be worth investigating as a a way to get the images without wearing out the gears.) More CablesI've now wired up and tested the original mouse I hacked, but now hooked to the digital input on the UK1104. I found an old ribbion cable with connector spacing that matched the digital I/O pins on the UK1104 and ran it out to a 12 conductor terminal strip I got at Radio Shack (4 conductors of which I cut off for use elsewhere). I've got a 10K pull-up resistor wired from the 5V line to the CH1 digital input and the mouse button wired from CH1 to ground. The CH1 input is normally 1 and when I click the button it goes to 0. I haven't fully integrated it with the software yet, but I have added enough code to test that I can poll the input and observe the button click fast enough that I don't need to worry about holding the button down. Here's what this nonsense looks like: I've also started work on getting the lights controlled by a relay on the UK1104. I've hacked one end off an old power cable, and extracted the white neutral line from the cable near the plug where I used the two ends of the 4 leftover terminal strip connectors to tie into the short stubs of the neutral power line I was able to extract and splice in a longer bit of power cable to hook to the relay: Now I just need to figure out how to get all these new bits plus the modified USB cables I made previously mounted securely (and safely) in an electrical box and attached to the scanner. TweakingI've got the hardware all finished, and I've tried it with this software, and while triggering the cameras and lights work, I clearly need to tweak the SDM script and wot-not. For example, here is what the pictures SDM took look like in the preview window: |
On the other hand, here is what the camera does when manually operated with normal firmware running and the same lights and pages being photographed: |
So work on the scripts is clearly needed :-). I've now started investigating the things I'd like to do to the SDM script if I can prove they are possible. The first thing I want to check is if I can monitor the USB power and see if it is still on (so I can keep the usb connection active till gphoto2 has finished downloading a batch of images). This script seems to be what I need (despite the name "get_usb_power" is not what I need :-): @title USB remote test :loop sleep 1000 sync_off wait_click 1 is_key k "remote" print "remote key", k goto "loop" end That prints a 1 on the screen as long as I have a USB cable plugged in and prints a 0 when I remove the cable, so I can ask the question "Is the USB power on?" Now I need to ask a more complicated question: Can I use the make_usb_connection and break_usb_connection functions to keep the usb connection active while still periodically monitoring the USB power state? (The problem might be the script running interacting badly with the USB downloads). That quest leads to this script: @title SuperScript rem wait for the usb power to come on and take a picture :laba sync_off wait_click 1 is_key k "remote" if k<>1 then goto "laba" press "shoot_half" sleep 500 click "shoot_full" release "shoot_half" sleep 500 rem check and see if power is still on sync_off wait_click 1 is_key k "remote" if k<>1 then goto "laba" rem power is still on, so make USB connection for downloading make_usb_connection :labb sleep 2000 sync_off wait_click 1 is_key k "remote" if k<>0 then goto "labb" rem power is now off, break USB connection and start at top break_usb_connection goto "laba" end Unfortunately, that script works right up to the point where I unplug the USB power after the download, at which point the camera powers down instead of going back to shooting mode. I may have to resort to timing and "upload_images_for" instead of trying to monitor the power. I supposed if both the camera and the computer agreed on an amount of time to add for each image, I could have the computer keep the USB power on a little bit longer than the camera needs it on, and everything might work. I've made some progress after being diverted for a while by things like getting my taxes done. I now have extensive configuration dialogs and I've gotten rid of the hard coded default config. I've also managed to squeeze enough information out of the libgphoto2 examples and utilities to incorporate native libgphoto2 code into the program for downloading and deleting the images from the cameras. I think I finally know what I need to get the SDM scripts to do. The book-scanner program now has a checkbox that says download images after taking next photos. What this will do is leave the USB power connected rather than merely generating a short pulse. I now need the SDM scripts to guess (based on the number of photos taken) how long to run the upload_images_for command. My program can then proceed to download then delete each image one at a time. If the camera happens to disconnect early, I'll get an error and stop downloading, but I will have gotten a batch of images before that. The camera script can then discover there are images left and give more time per image on the next batch (I just have to get that script written). |