Since this might be new territory for the average camera owner, writing their own little programs to automate their cameras, it would be a good idea to discuss any concerns, hints, tips, and further information you might have on the subject.
Here are some concerns that come to mind:
I wasn't too sure about uBasic syntax and how variables are defined (integer, floating-point, etc.). I found a uBasic package online that included a lengthy doc file in it, but we are working with a very small subset of all available commands for uBasic. Which commands will work? Which will not?
There is also the discrepancy between camera makes and models that CHDK will work on. I have found that some menu items are not identical between the A-series and Sx SI series of cameras. Scripts will have to be modified at times when using special features of each camera. And some type of standard notation in shared-scripts to alert others to which camera(s) the script was written for.
It would be nice if there was an easy place for all of us to share our tweaked or brand-new scripts. I recently wrote one that allows for a greatly extended use of Focus-Bracketing for a Powershot S3 IS camera, but it requires special instructions for use that are too lengthy to include in the script itself. I am also unsure if this script would work on other makes and models of cameras. How would one go about sharing that script and required documentation?
We could include new scripts in this wiki as new pages. Perhaps we could make a link here like "more scripts" or "user scripts" or something like that. And on that new page, we could place our scripts as subpages.
Added in a "User Written Scripts" section. PLEASE advise if I'm doing this all wrong! Or if it should be done some other way. I'm new to this Wikia thingy.
Full Command Syntax Manual? Edit
When hunting online for more uBASIC info I ran across a file inside of a ubasic.zip archive. (Don't ask me where I found that now, it took about an hour's search before I found something more extensive than what was already posted here.)
The included Word DOC was titled "UBASIC86 Version 7.23 - for IBM-PC - User's Manual"
I saved it in a text file for further reference. This is a much more extensive list of commands than what is available in CHDK's uBASIC. Would it be a good idea to post that text file as a new sub-page for this scripting section, in the hopes that someone would go through and glean out the unimplemented commands? Just the info on how variables are defined alone was helpful. As well as now knowing that using goto and gosub are equally valid to call up a label routine.
It was recently reported, for example, that the "print" command in CHDK is limited to a line length of 24 characters. Little things like that would be important to know for the know-nothing script writer, like myself.
Post it, don't post it? What say you?
UBASIC has (almost) nothing to do with uBasic were are talking about, so no need to post it. (UBASIC is a math oriented basic with e.g. very high accuracy) Also the first link on the main uBasic page should be changed.
CHDK uBASIC DOS/Windows Emulator? Edit
Is there any way that a uBASIC emulator can be available for DOS or Windows where we could write our scripts on the computer, and test them BEFORE putting them on the SD card for the camera?
I found I was taking up more time copying the scripts to my SD card, rebooting the camera, going to the menu, testing it, noting the error, going back to the computer ... rinse & repeat infinauseum.
Surely there must be an easier way than this.
- I've compiled the console version of uBasic interpreter from CHDK. You can find it as usual: grandag.nm.ru/hdk/. Usage: ubasic_test.exe <script_file.bas> -- GrAnd 08:19, 19 May 2007 (UTC)
- Nice. Is it able to run on Win XP (home)? Right now, it says "UBASIC~1.EXE - The NTVDM-CPU has found an invalid command. CS:071b IP:00f9 OP:ff ff 00 00 00 Click 'close' to end this task". --Harvester 08:25, 19 May 2007 (UTC)
- The server doesn't seem to allow me to download an EXE file. (Or you're fixing it right now and it's not there or something.)
- It doesn't work if you left click on it, but right click>save as did work for me. --Harvester 08:44, 19 May 2007 (UTC)
- Yes. The server blocks EXE file downloading. I've packed the file... -- GrAnd 08:57, 19 May 2007 (UTC)
- Thanks! I thought it might be that. (On a similar note I have a server that won't allow MPG files for some reason.) The problem with the long-exposures seems to be fixed! I just did 15, 8-second exposures with no problem. But now I see a new one, in my Ultra Intervalometer script ... I never figured in long exposure times for the cycle length. I'll have to build a small table of values from that get_tv command and add in the seconds of exposure + black-frame time. I wonder if I can do all that in under 2k ... Or easier yet, not worry about it and let the user just figure out why it's taking so long. :-)
- p.s. ubasic_test worked just fine for me on XP, Command Prompt>ubasic_test scriptname.bas I renamed ubasic_test to just test.exe and put it on my HDD's scripts folder to test them. NICE!! Thanks!!!
- The new (packed) version now also works fine for me. Thx, very nice! --Harvester 09:22, 19 May 2007 (UTC)
Are there more script commands? Edit
GrAnde? I was peeking at some of the source-code for this, and noticed in the uBASIC files that there were quite a few more strings in the tokenizer sections that haven't been mentioned yet.
I don't understand how to even compile code, so I'm not sure if these are usable strings/commands for writing scripts, or if these are just used internally by uBASIC. Seeing them listed in these files with the other uBASIC camera commands raised my curiosity to know if these can be used in writing our own scripts.
I understand what the get/set_TV/AV commands would refer to and how to use them, but I'm not sure on the _REL ones and how those would be used (if at all possible in scripts).
Could you explain a bit about them IF they are usable in scripts? I could then add this into the tutorial section with the other camera commands.
One other thing, have you given any more thought on a better way to implement the ZOOM_IN/OUT commands, such as with a ZOOM_TO? With the zoom_in/out uBASIC command working so painfully slow, and seeing how fast the camera can zoom with the rocker-switch, I wonder why it can't be made better for scripting.
Again, I thank you for all the wonderful work you are doing on this. The words "thank-you" just don't seem to be enough to express how grateful I am for how much you have improved my camera and digital-photography experience.
Restructured this article Edit
I restructured this page because I think it might have looked a bit confusing for beginners. I tried to achieve this: First the "easy part" (small explantion how to use scripts and where to get them), and then the "advanced part" (links to how to write your own scripts). I hope this is okay for you. Btw, do we need the uBASIC syntax short manual any more? I think Keeo's manual is better and more up to date. --Harvester 19:37, 14 May 2007 (UTC)
- Looks good. And in case you missed my swan-song post on the chdk/talk page, I thought someone might just take the sections from the tutorial scratchpad I created and put them into the one GrAnd started when they were good enough to add in. I was just using the scrachpad page I made as a work-sheet to record some ways of explaining everything, hoping others would jump in to correct a lot of errors I might be making. I think there's some important info on the page GrAnd started on this, the info should be consolidated somehow. (meaning: I don't think GrAnd's info is outdated.) In fact I didn't go into the subroutine info as much as was needed because GrAnd covered that better in some ways. Feel free to bend-fold-spindle-mutilate the tutorial stuff I did to make a comprehensible tutorial section any way you see fit. Restructuring it completely if needed, or just pulling out the good bits for something nicer on GrAnd's page. (That's what I was thinking at first as I was doing the scratchpad tutorial.) Keoeeit 16:41, 16 May 2007 (UTC)
Motion Detection Version - Start to add to the Tutorial? Edit
I read the post at dpreview about the new motion detection version, which is still in Alpha phase. I downloaded it and have been testing it (very little testing, busy with other things). I looked over the source code for it and with the comments in there it seems like I can figure out some of the main commands, along with the 2 sample *.bas files that MX3 included for testing purposes.
Would it be too soon to start to add a page on how to use these new uBASIC commands to the tutorial? I thought of starting one so that I could post what I figured out so far, and that others might add in all the blanks.
I also notice that many of his commands are commented as "maybe not needed". I hope they aren't removed. For example, being able to choose the color channel to detect on, would be a huge asset when wanting to trigger the camera by a red laser light and have it ignore some other light sources.
For those of you that aren't aware of this version yet, it can be found at http://mx3.ip-com.com.ua/chdk/ and the short post listing the commands (also available from the source code download) can be read about here http://forums.dpreview.com/forums/readflat.asp?forum=1010&thread=24662492&page=2
If not added to the scripting tutorial, could we start another page where we could list what we figured out on how to use it? I'm anxious to figure out how all of those commands are used, but I know I wouldn't be able to figure them all out on my own from such scant information so far.