supplierdeeply

CHDK Script for controlling SX120IS in Skywalker X8 Flying Wing

  • 12 Replies
  • 1769 Views
Advertisements
Hi all,
I have spent hours trying to make this work but as a farmer my coding skills are not great!
I am flying a Skywalker X8 with an APM 2.6 autopilot.  I have constructed a cable which converts the PWM signal from the APM to voltage pulses which CHDK can read.  The cable uses an Arduino nano to convert the signal. 
I want the camera to have 3 modes
- Play mode with lens retracted
- Shoot photos with lens wide open
- Shoot photos with lens zoomed in
I have got the camera taking photos but can't get it to go into play mode and retract the lens.  It either keeps going in and out, or goes in and stays in and I can't switch to any other modes.  I want the lens to be retracted for take off and landing.
Here is the code I am using, can CHDK read USB pulses while in play mode?  When I switch to ch1up, the lens retracts and I get a UBASIC48 parse error and the script terminates.  I want the lens to go in and stay in until I switch to another mode.  Thanks in advance for any help, will provide guidance on building cable and code for arduino if anyone is interested.


@title 3DR Shooter
rem author Brandon Basso, 3D Robotics
rem author Dave Mitchell - [email protected]
rem This script is based on the basic Gentled CHDK2 script
rem It takes pictures and sets zooms to a few different levels

@param o Zoom-extended
@default o 100
@param i Zoom-stowed
@default i 0
@param s Zoom-shoot
@default s 0

while 1
   do
      k = get_usb_power
   until k>0
   if k < 2 then gosub "ch1up"
   if k > 2 and k < 8 then gosub "ch1mid"
   if k > 7 and k < 11 then gosub "ch1down"
   if k > 19 then print "error"
wend
end

:ch1up
   print "Stowed"; k
   set_record 0
   while not get_mode() do
   sleep 2000
   return

   
:ch1mid
   print "Shoot"; k
   set_zoom s
   shoot
   sleep 2000
   return


:ch1down
   print "Extended"; k
   set_zoom o
   shoot
   sleep 2000
   return




Re: CHDK Script for controlling SX120IS in Skywalker X8 Flying Wing
« Reply #1 on: 04 / August / 2015, 08:30:48 »
Taking a quick look via my mobile phone I think I see a couple of possible problems
  • The code you are using for :ch1up appears to have been cut & pasted from a Lua script.  That will not work when using uBASIC
  • You use set_record 0  to enter playback mode but never issue a set_record 1 to re-enter shooting mode.  While the  shoot  command will probably do that for you, it's not a really good way to do so
  • I suggest putting a   sleep 2000  after each set_zoom  command to give the lens time to actually move
Ported :   A1200    SD940   G10    Powershot N    G16

Re: CHDK Script for controlling SX120IS in Skywalker X8 Flying Wing
« Reply #2 on: 04 / August / 2015, 15:10:33 »
Thank you waterwingz,
I have changed the :ch1up section to:

:ch1up
   print "Stowed"; k
   set_record 0
   sleep 10000
   return

and removed the set_record function.  Once I move the switch on my transmitter the camera prints 'Stowed0' and then retracts the lens and enters play mode.  While it is in play mode I am able to go move the switch on my transmitter and go back to taking photos however after only about 5 seconds in play mode the screen turns off and it won't go back to taking photos.  Is there a way to make it stay in play mode for longer?

Thanks very much!

Re: CHDK Script for controlling SX120IS in Skywalker X8 Flying Wing
« Reply #3 on: 04 / August / 2015, 18:52:05 »
I'll take a look at this later tonight.
Ported :   A1200    SD940   G10    Powershot N    G16


Re: CHDK Script for controlling SX120IS in Skywalker X8 Flying Wing
« Reply #4 on: 05 / August / 2015, 09:42:11 »
Once I move the switch on my transmitter the camera prints 'Stowed0' and then retracts the lens and enters play mode. 
Please post the entire modified script as an attachment.  Looking at your current code,  there is no way for a 'Stowed0' message to be generated.  It should have been 'Stowed1' I think?

Incidentally, you appear to be trying to use very short pulses relative to the standard CHDK USB pulse detection capability.  As you have your own arduino code, I would suggest using longer pulses  ( 40 mSec, 80 msec, 120 msec for example ).   Either that or use the set_remote_timing 1000 function to increase the pulse detection resolution (with suitable changes to the ranges checked in your script)
Ported :   A1200    SD940   G10    Powershot N    G16

Re: CHDK Script for controlling SX120IS in Skywalker X8 Flying Wing
« Reply #5 on: 05 / August / 2015, 10:28:43 »
Had a few more minutes to play with this.   Updated script attached.   I think your problem with the script hanging is that uBASIC does not seem to like it if you call set_record 0 when the camera is already in playback mode.

Also,  I was unable to get set_remote_timing to work in uBASIC (syntax error).   I'll have to look at that later.
Ported :   A1200    SD940   G10    Powershot N    G16

Re: CHDK Script for controlling SX120IS in Skywalker X8 Flying Wing
« Reply #6 on: 06 / August / 2015, 07:26:02 »
Quote
'You’ll see the a value to be dancing around between 0 and 1. This is it reading the 15 millisecond standby pulses'

This is the link I used to build my Arduino cable.  The script on that page is written in Lua and it is for an intervalometer, it also looks much more complicated that what I am working with!

http://www.otherhand.org/home-page/drones/a-remotely-actuated-intervalometer-for-aerial-mapping-using-canon-cameras/

The script you submitted does work but once the camera enters 'Play' mode it only shows the previous photo for about 5 or 6 seconds before the screen turns off.  I think the code on the Arduino is working as the camera is registering the different modes but it would be great if the camera would stay in Play mode indefinitely so that I could wake it up at any time and have it start taking photos!  Thanks again for having a look, greatly appreciated.  Maybe it is something to do with the camera I am using and it doesn't like to wait in Play mode

Re: CHDK Script for controlling SX120IS in Skywalker X8 Flying Wing
« Reply #7 on: 06 / August / 2015, 08:49:52 »
Quote
'You’ll see the a value to be dancing around between 0 and 1. This is it reading the 15 millisecond standby pulses'
That's why I wanted to see the script you are using.  If you are still using this code
Code: [Select]
   do
      k = get_usb_power
   until k>0
then you need to understand that get_usb_power returns 0 if there have been no pulses.  It will return 1 for a pulse between 0 and 20 mSec.  It returns immediately each time that it is called - it does not wait for a pulse. 

As written, you can't get a 'Stowed0' message because it never leaves that loop unless k is greater than zero !

Quote
This is the link I used to build my Arduino cable.  The script on that page is written in Lua and it is for an intervalometer, it also looks much more complicated that what I am working with!
Complicated?  Hmmm ...kap_uav.lua would actually be pretty easy to adapt for your application.

Quote
The script you submitted does work but once the camera enters 'Play' mode it only shows the previous photo for about 5 or 6 seconds before the screen turns off. Maybe it is something to do with the camera I am using and it doesn't like to wait in Play mode
If you go into the CHDK menu and open the CHDK Settings menu,  there is a menu item that says Disable LCD Off [  ].  Make sure it is set to [ Always ] ?
« Last Edit: 06 / August / 2015, 08:55:55 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16


Re: CHDK Script for controlling SX120IS in Skywalker X8 Flying Wing
« Reply #8 on: 09 / August / 2015, 06:05:52 »
Hi waterwingz,
I have changed the Arduino code to give pulses of 40, 80 and 120 mSec as you suggested.  I have tried running the code that you submitted again and I get a 'uBASIC:6 Unk stmt' error. 

I have checked in the CHDK settings that [Disable LCD Off] is set to 'Always' but the camera still turns off after a few seconds in review mode.

If you think the camera is the reason that it shuts down in play mode then I will give up but if you think there is something that can be changed in the code then I will persevere.
Apologies for the late reply, has been a busy weekend.

*

Offline zeno

  • *****
  • 881
Re: CHDK Script for controlling SX120IS in Skywalker X8 Flying Wing
« Reply #9 on: 09 / August / 2015, 07:23:32 »
That error message means that line 6 of the script has an error - "6 Unk stmt' means line 6 is an unknown statement. I'm not sure when the @chdk_version statement got added to CHDK (some time last year?) but maybe it's a lua-only thing and your script is in Ubasic. Anyway, it won't do any harm to remove that line.
A570, S100, Ixus 127
Author of ASSIST, STICK, WASP, ACID, SDMInst, LICKS, WICKS, MacBoot, UBDB, CFGEdit

 

Related Topics