KAP & UAV Exposure Control Intervalometer Script - page 57 - Completed and Working Scripts - CHDK Forum

KAP & UAV Exposure Control Intervalometer Script

  • 1068 Replies
  • 409647 Views
Re: KAP & UAV Exposure Control Intervalometer Script
« Reply #560 on: 08 / July / 2015, 22:36:04 »
Advertisements
I successfully forced my will on the pixhawk and I got the PWM up to 32767 which is 32ms for the Canon.
Would you mind posting screen shots of what you setup in the Arduplane Mission Planner software to do this?

Edit : I'm doing a little digging into the ardupilot world (the firmware that runs on pixhawk and other flight controllers).  It looks like you could actually edit the MAVLink file and change the DO_SET_SERVO second paramter value to something outside of its normal range of 1000 to 2000. That would let you use values up to 65 mSec.  The ardupilot code just passes that through to the flight controller hardware so if the hardware can do it then longer values seem possible.  Or I could have this completely wrong.
« Last Edit: 08 / July / 2015, 23:41:53 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

Re: KAP & UAV Exposure Control Intervalometer Script
« Reply #561 on: 09 / July / 2015, 09:13:50 »
That would let you use values up to 65 mSec. 
YOu got that right and I did go up to 65000 initially and it was stable BUT at the first restart it automatically rewrote to 32767.
Even though I can only speculate, as I am neither a computer nor an electronics expert, the 32*1024 on a 32 bit CPU looks to me as some system limit that I don't want to mess with.

I have made the circuit ready but it is not working correctly for some reason. It gets some PWMs, but it doesn't make sense.
Code: [Select]
--[[
@title PWM Tester
--]]

set_console_layout(1, 1, 44, 10)
print("USB pwm test started")
set_config_value(121,1) -- make sure USB remote is enabled
count=0
repeat
    x=get_usb_power(0)
    if ( x > 0 ) then
        print("width ="..(x*1).." mSec")
        count=count+1
    end
until is_pressed("menu")
set_config_value(121,0) -- make sure USB remote is disabled

Could you please throw together a minimal script that list and logs the PWM inputs exactly as the camera receives it?
« Last Edit: 09 / July / 2015, 09:50:10 by netptl39 »
S110, SX200is,

Re: KAP & UAV Exposure Control Intervalometer Script
« Reply #562 on: 09 / July / 2015, 10:38:19 »
YOu got that right and I did go up to 65000 initially and it was stable BUT at the first restart it automatically rewrote to 32767.
How did you set that?  In Mission Planner? Or manually editing the MAVLink file?

Quote
Even though I can only speculate, as I am neither a computer nor an electronics expert, the 32*1024 on a 32 bit CPU looks to me as some system limit that I don't want to mess with.
32767 is the largest positive 16 bit signed number.  The code I looked at was using unsigned 16 bit numbers but somewhere in there some piece of code is probably switching between signed and unsigned.

Quote
I have made the circuit ready but it is not working correctly for some reason. It gets some PWMs, but it doesn't make sense.
Thie script needs to enable precision timing.    Add this to the start of your code
Code: [Select]
set_remote_timing(1000)
Ported :   A1200    SD940   G10    Powershot N    G16

Re: KAP & UAV Exposure Control Intervalometer Script
« Reply #563 on: 09 / July / 2015, 12:11:56 »
YOu got that right and I did go up to 65000 initially and it was stable BUT at the first restart it automatically rewrote to 32767.
How did you set that?  In Mission Planner? Or manually editing the MAVLink file?
Both telemetry and on-board log confirmed .
See attachment on how.
Quote
Even though I can only speculate, as I am neither a computer nor an electronics expert, the 32*1024 on a 32 bit CPU looks to me as some system limit that I don't want to mess with.
32767 is the largest positive 16 bit signed number.  The code I looked at was using unsigned 16 bit numbers but somewhere in there some piece of code is probably switching between signed and unsigned.

Quote
I have made the circuit ready but it is not working correctly for some reason. It gets some PWMs, but it doesn't make sense.
Thie script needs to enable precision timing.    Add this to the start of your code
Code: [Select]
set_remote_timing(1000)
[/quote]

YESSSS!!!! That little code fragment solved the precision problem!
I am getting 18-19 input @19000 output. Occasionally there is a 37-38 but I guess that is when it misses a pause. 
Over 19000 it stops listing any PWMs. When l pulled the USB out it gave me 3000ms.
If we work with PWM ranges of 1-5,6-10,11-15,16-20, we still have 4 command slots @3,8,13,18 and safe distances  .

Precision could be better, but that can come from the DIY electronics or the Camera.
S110, SX200is,


Re: KAP & UAV Exposure Control Intervalometer Script
« Reply #564 on: 09 / July / 2015, 12:12:21 »
I have been thinking if we should fork this to a KAP_UAV_HS(high speed) as the HS part of it is still pretty far from stable, code has been heavily altered, and will work for extreme UAVs flying very low and/or very fast and also the logic is somewhat altered/reduced.
S110, SX200is,

Re: KAP & UAV Exposure Control Intervalometer Script
« Reply #565 on: 09 / July / 2015, 12:49:47 »
The code alterations are relatively minor and there is not likely to be other talk about the rest of the script so I would not favour a split.
Ported :   A1200    SD940   G10    Powershot N    G16

Re: KAP & UAV Exposure Control Intervalometer Script
« Reply #566 on: 09 / July / 2015, 13:10:03 »
The code alterations are relatively minor and there is not likely to be other talk about the rest of the script so I would not favour a split.
OK.  :)

S110, SX200is,

Re: KAP & UAV Exposure Control Intervalometer Script
« Reply #567 on: 09 / July / 2015, 13:59:34 »
Occasionally there is a 37-38 but I guess that is when it misses a pause. 
What determine the time between pulses?
Ported :   A1200    SD940   G10    Powershot N    G16


Re: KAP & UAV Exposure Control Intervalometer Script
« Reply #568 on: 09 / July / 2015, 14:53:11 »
Occasionally there is a 37-38 but I guess that is when it misses a pause. 
What determine the time between pulses?
It might sound strange, but I have no idea. I will look into it once I have a little time.

Meanwhile:

I have altered the code a little and ran a short test :
Code: [Select]
function pwm1(pwidth)
        if( repeat_check("mode=2",pwidth ) >= PWM_required_repeats ) then
           usb_shooting_mode = 2                                      -- request the next shot
        end
    end

    function pwm2(pwidth)
        if( repeat_check("mode=1",pwidth ) >= PWM_required_repeats ) then
          usb_shooting_mode = 1                                                       -- neutral position - do nothing
        end
    end

    function pwm3(pwidth)
        if( repeat_check("nothing",pwidth ) >= PWM_required_repeats ) then 
            --usb_shooting_mode = 1                                     -- set camera as waiting to shoot
        end
    end

    function pwm4(pwidth)
        repeat_check("shut down",pwidth)
        shut_down()
-- = 0                                          -- put camera into playback / sleep mode
    end



    function pwm_mode()                                                -- sample PWM code for Gentles gentwire-usb2 - note that values are in milliseconds
        local pw = get_usb_power(2) * usb_precision
        if  pw > 0  then
            if   ((pw < 1) or (pw > 20)) then repeat_check("invalid pulse",pw)
            elseif pw < 5  then pwm1(pw)
            elseif pw < 10  then pwm2(pw)
            elseif pw < 15 then pwm3(pw)
            elseif pw < 20 then pwm4(pw)
            elseif pw < 225 then repeat_check("idle pulse",pw)
            end
        end
   end

I would like to ask you to use this in the next beta version.
I made a small test 130+ pictures were taken and I have a feeling that the PWM control worked.

there are also a few bugs in B9:
Log was not updated
Screen was not updated
Menu button did not finish the script running
Shoot button did not interrupt the script running

I would like to ask you to add precise time stamp both for the picture and the camera PWM. Least for the beta testing. 

For Brainstorm:
Pixhawk generates output continuously so Camera continuously gets PWM input.
If each input is considered as executable we will have a huge backlog pile-up. this might be a problem.
The idea of executing only the first and disregard subsequent identical shoot inputs within 0.55s (so far the minimum shot interval I have seen) seems necessary.
Unfortunately this cannot be the same for the pause(usb_shooting_mode = 1 ) as 0.6-0.7s shot interval should be usable.

I will do a car-test with this tomorrow with both B8 and B9 and B??(if available). :-)
Let me know if there are any specific scenarios that you would like me to test.

Many thanks in advance!
S110, SX200is,

Re: KAP & UAV Exposure Control Intervalometer Script
« Reply #569 on: 09 / July / 2015, 17:39:56 »
Quote
What determine the time between pulses?
It might sound strange, but I have no idea. I will look into it once I have a little time.
Looking at the ardupilot source code,  the internal calls to the hardware abstraction layer pass the pulse width required (the stuff you set) but no setting for pulse frequency.   I'll do some more digging.

Quote
Pixhawk generates output continuously so Camera continuously gets PWM input.
If each input is considered as executable we will have a huge backlog pile-up. this might be a problem.
The idea of executing only the first and disregard subsequent identical shoot inputs within 0.55s (so far the minimum shot interval I have seen) seems necessary.   Unfortunately this cannot be the same for the pause(usb_shooting_mode = 1 ) as 0.6-0.7s shot interval should be usable.
The existing code handles receiving the same pulses repeatedly.  And there is risk of backlog pile-up in any case - requests are not queued.
Ported :   A1200    SD940   G10    Powershot N    G16

 

Related Topics