Author Topic: Bolt trigger module test results (bolt_rec.mo)  (Read 86106 times)

dlrpgmsvc

  • Senior
  • ****
  • Posts: 398
  • The 7D and 50D Robin Hood
Bolt trigger module test results (bolt_rec.mo)
« on: June 09, 2013, 12:56:21 AM »
Updated October 20th by Renato for a quick how to guide:

Two versions available, one with ring-buffering option (buf_raw.mo + buf_bolt.mo)  and one without ring buffer (bolt_raw.mo).  The ring-buffering option allows to record more frames before and after the bolt while  the bolt_raw.mo only record one or a few frames after the bolt.  Also there are some compatibility issues for the ring-buffering options as noted below.
-----------------------------
Ring-buffering option can be used with cameras that have a CF card.   Tested cameras: 5D3 (works best), 7D with Tragic lantern for fps override.
Raw Video: https://bitbucket.org/mk11174/magic-lantern/downloads/buf_raw.mo  (This is an older raw_rec.mo so do not load current raw_rec.mo at the same time)
Bolt Trigger: https://bitbucket.org/mk11174/magic-lantern/downloads/buf_bolt.mo
Copy these modules to the modules directory. 
Load the modules, camera in M mode, camera in video mode, enable Bolt Trigger RAW video and Bolt trigger Pre Buf modules located on Movie tab.  Set fps override to 15 with Low light option i.e  fps=14.985.  When you enable Bolt trigger the shutter speed should drop to 1/16, if this does not happen you will get more damaged frames.
For 5D3 I change the default  setup of Bolt trigger to:  Post-bolt frame count to 50, Abs trigger enabled ON, Rel: trigger enable OFF
For 7D leave the default settings.
Set your ISO to 100 and play these settings until you think you understand how this works.
Press Record button and the ring buffer will fill up but no recording (red led) will begin until the trigger detects a flash or light.  Test this with a flash or a bright light (on-off). When finished recording press the stop button (recording button) and then use the RAW  video playback found in Bolt Trigger RAW video to see the results.  When all works as expected download the raw file and have a look a the frames captured.
--------------------------------
bolt_raw.mo is the second option. This works on cameras with SD and CF cards.  Tested cameras: 5D3, 5D2, 7D, 550D, 600D, maybe will work: 60D and 650D
Download: https://bitbucket.org/mk11174/magic-lantern/downloads/bolt_raw.mo
Copy this module to your module directory.
Load the module, camera in M mode, camera in video mode, enable Bolt trigger  located on Movie tab. 
Set fps override to 15 with Low light option i.e  fps=14.985. 
When you enable Bolt trigger the shutter speed should drop to 1/16, if this does not happen you will get more damaged frames.
I have only tested default settings and work.  May have to adjust  Trigger value or take Auto exposure if you do not like how it exposes.  This feature changes the f-stop to adjust the scene exposure.
Set your ISO to 100 and play these settings until you think you understand how this works.
Press Record button and BOLTS CAPTURED  should stay at zero until a flash is detected and the captured frames will be recorded (red led).  Test this with a flash or a bright light (on-off).  When finished recording press the stop button (recording button) and then use the RAW  video playback to see the results.   When all works as expected download the raw file and have a look a the frames captured.

Jump to this post for more information: http://www.magiclantern.fm/forum/index.php?topic=6303.msg55463#msg55463


Here is more info from mk11174 on how to use other features of bolt_raw.mo!!!

My favorite feature I added was Autoexposure option, not sure if it works on any other camera though, but works perfect on the 550D, this allows me to walk away and control my video cameras while the autoexposure feature adjusts the trigger line right above the graph by controlling the aperture value and I made it slow so it does not re adjust when a flash happens, only when the sky changes gradually during a storm. Without this feature you have to watch the trigger line the whole time, if you want a bolt captured your goal is to keep that trigger line right above the graph to catch even the weakest bolts and since you have to do this, you will have to keep adjusting the aperture manually to keep the graph under the trigger line. The only thing you have to remember, is I set it to react slow, so when you first set your cam up at the sky you have to give the feature a chance to settle the graph under the trigger line, once it does, then you can start recording.

If the sky has a dark cloud layer and a medium grey layer it is best to use 1 scan line because the module will see the dark clouds and will adjust brighter which is bad cause then sky will get over exposed, that is why I added ability to see scan lines so you know what the detection lines are aimed at, if you have a nice even gradient sky, and it fills your view then you can use all scan lines with no issues.

The way I have it set up now allows me to turn it on and walk away and when I come back I have many bolts to enjoy without even touching the cam. So when used correctly which will take practice in my experience, it works really well.

The timelapse is a neat feature I added to it, but not always used, I only use it when I get really cool textured skies that I know will be worth a timelapse, it just saves a frame by itself while it captures bolts, it basically just sets off a false detection every so many seconds. Post gets harder because you have to manually separate the timelapse captures from the bolt captures so you don't get uneven motioned timelapses.


------------------------------------------

Original post by dlrpgmsvc

This thread was created for mk11174 in order to publish tests results of a module developed by gg30s. This module should start a raw video recording triggered by light and/or motion variations.
If you think it's impossible, you have lost beforehand

mk11174

  • Hero Member
  • *****
  • Posts: 775
Re: Bolt trigger module test results
« Reply #1 on: June 09, 2013, 02:09:25 AM »
Thanks for the post! Just waiting on some storms to start posting results!
500D/T1i  550D/T2i  600D/T3i  700D/T5i

mk11174

  • Hero Member
  • *****
  • Posts: 775
Re: Bolt trigger module test results
« Reply #2 on: June 09, 2013, 03:28:02 AM »
Just a test, I went out trying to get it before dark because really for night lightning i would be using photo mode to take bulb mode high res raw stills. But for a evening sky where it is still to bright to do long exposure for night lightning I went to test the sensitivty of the trigger.

My test setup was using a a/c external flash bulb from 70 feet away and my first test was with scanline set to 1, it did not pick anything up, so I went to 20 scan lines, then it created a huge spike on the graph. So I went down by 5 and success till I went below 5 scan lines and the spike was smaller and smaller the less scan lines I used.

So if it can pick up the little light, it should easily pick up a lightning bolt even on a lighter grey storm sky, the darker the sky of coarse the more likely it will work.

Are only issue will be the rolling shutter cutting the images in half, but I found using a strobe light I tested the best fps and shutter speed to have greater success to reduce the gap between the scan line plus have more full frame captures without cut off.

My best success was set camera to 1920x1080 30p mode in Canon menu, then in ML turn on fps hack and set to EXACT at 15fps, then use exposure override to set shutter to 1/15, this will make the cut off line as skinny as possible which maybe allow for merging the cut offs together, because when setting the fps to 15 it seems to capture any cut in half images on 2 differ frames so you can merge them and make a full frame out of them. Plus setting to 15fps also captured more strobe flashes within a certain amount of frames as well.

Any lower then 15fps you risk the sky washing over the flash cause day skies are bright, so you dont want to long of a shutter plus the slower the fps and shutter the less the bolt trigger works. But to fast of fps and shutter the less flashes you will capture and the more cut in half images you will end up with.


1280x720x60P canon mode works as well, but not at a shutter of 1/60, it misses a lot of flashes, not the trigger, just the live view, the trigger works well in all my tests except long exposure, so avoid them.

If you go 60p mode then set fps to 30 or 15 and adjust shutter to 1/15 or 1/30 depending on what fps you go with, both work fine.

But on T2i when in 1280x720 mode, whether your taking a MOV or using Raw, this cam has banding issues and antialias issues plus I like using 5x mode to get 2512x1080 res. I can achieve this because I just have the bolt trigger capture 1 post frame, so just in case the bolt gets cut in half the main detection frame will be caught on the first frame and the other half will be on the post frame, would be cool to get 1 pre frame when the module gets set up for pre buffer capture if it is possible just in case a half for some reason gets caught on the  frame before the detection.

Well, these are my findings from my tests just to get this thread started  :D

By the way, I live in the US in Florida, so I am in the heart of lightning season, expecting action any day now.

I have been a lightning photographer for 10 years now.



500D/T1i  550D/T2i  600D/T3i  700D/T5i

dlrpgmsvc

  • Senior
  • ****
  • Posts: 398
  • The 7D and 50D Robin Hood
Re: Bolt trigger module test results
« Reply #3 on: June 09, 2013, 10:38:44 AM »
What is the advantage of using raw video vs photo mode with ml light trigger ? Photo mode have more resolution and can be raw. If you want to capture a lightning movie you should use a pre-buffer not to lose the very first instants, so a circular self-deleting buffer all-time active, right?
If you think it's impossible, you have lost beforehand

MA Visuals

  • Freshman
  • **
  • Posts: 83
Re: Bolt trigger module test results
« Reply #4 on: June 09, 2013, 10:57:55 AM »
Posted a quick test using the new ML Bolt module.  Not perfect conditions or camera settings, but I have to say that it worked admirably!
http://www.magiclantern.fm/forum/index.php?topic=6308.0

See Vimeo link for more details... https://vimeo.com/67976426


mk11174

  • Hero Member
  • *****
  • Posts: 775
Re: Bolt trigger module test results
« Reply #5 on: June 09, 2013, 04:58:03 PM »
What is the advantage of using raw video vs photo mode with ml light trigger ? Photo mode have more resolution and can be raw. If you want to capture a lightning movie you should use a pre-buffer not to lose the very first instants, so a circular self-deleting buffer all-time active, right?
I am not interested in capturing a movie, just daytime stills, which is very hard without a lightning trigger, during night I would just take regular stills to get full camera resolution, no lightning trigger needed just hand and bulb triggering.

I have an HDV camera for video of day lightning, I just want to use this trigger system to capture a nice high quality day time still of the main connection with all the branching. I can get stills from the video footage, but not going to be as high quality as dslr still if this works out.
500D/T1i  550D/T2i  600D/T3i  700D/T5i


MA Visuals

  • Freshman
  • **
  • Posts: 83
Re: Bolt trigger module test results
« Reply #7 on: June 10, 2013, 12:28:38 AM »
Next time, was thinking of trying mk11174's recommending 15 fps and 15 shutter.  Goal is for the most usable film footage, even if some post work is involved.  I'm not actually sure that's even possible given the rolling shutter CMOS sensor. Any other suggestions to help minimize rolling shutter effects as well as improve overall quality of lightning capture would be most welcome.

mk11174

  • Hero Member
  • *****
  • Posts: 775
Re: Bolt trigger module test results
« Reply #8 on: June 10, 2013, 01:55:29 AM »
Next time, was thinking of trying mk11174's recommending 15 fps and 15 shutter.  Goal is for the most usable film footage, even if some post work is involved.  I'm not actually sure that's even possible given the rolling shutter CMOS sensor. Any other suggestions to help minimize rolling shutter effects as well as improve overall quality of lightning capture would be most welcome.
Sounds good, I am anxious to see your results, I had my first chance this season today, not many bolts though, only 4 that were in my area that I counted, non in my view, I even had 2 cams covering a wider range, all 4 hit out of view in random areas, so frustrating! I just want 1 for now just to see how the setting I came up with handle the rolling shutter.

More testing last night I found I can make the scan line cut even smaller by using Low Light option in FPS hack rather then EXACT. So if you set that first, then goto change your shutter to 1/15 or in case you have 2, 1/15 in menu, just go with the most open one before it resets to 1/4000 or 1/8000 depending on your camera, you just want most open shutter and not using Canon shutter option, has to be ML shutter control, it opens it a hair more which is crucial to minimize the scan line gap.

Hope it works though!  ;)
500D/T1i  550D/T2i  600D/T3i  700D/T5i

MA Visuals

  • Freshman
  • **
  • Posts: 83
Re: Bolt trigger module test results
« Reply #9 on: June 10, 2013, 11:01:18 PM »

Kim.dh

  • New to the forum
  • *
  • Posts: 43
Re: Bolt trigger module test results
« Reply #10 on: June 11, 2013, 03:01:12 AM »
thats the plan.
Awesome! I made a feature request for this function some days back. Glad to hear you are working on it.

mk11174

  • Hero Member
  • *****
  • Posts: 775
Re: Bolt trigger module test results
« Reply #11 on: June 11, 2013, 09:27:09 PM »


Finally got a day storm to test things!

Only issue was, the latest code is not working right, I tested last night with flash testing and it was not saving like code before the prebuffer was added, The last code captured the detection and post and saved fine, the new code saves the pre and post frames but not detection, I tested it with differ fps settings, differ res modes, no good and I confirmed it today with an actual bolt, it actually detected a real weak rain wrapped bolt in the distant and recorded the frames from buffer, but clearly all but the main flash that was detected, so that stinks, but at least it works for sure like I was hoping.

This was captured with Silent Picture Burst using the End Trigger setting, I just did a half shutter press till a bolt flashed in view and let it go and it captured and saved pre, main flash and post as much as my buffer fit for the mode I was in.

I was in 1920x1080 at 30p in Canon menu, I turned FPS on and set to 15 fps Low Light, then went and set my shutter using ML exposure override to closest shutter to 360 degrees 1/15 and just set my aperture a tiny bit above exposed correctly and used ND8 filter because it was a brighter grey sky. I then zoomed x5 because they were far away and far apart and this mode gives me a wider bigger res DNG which fit them fine.

I got many bolts today, most weak and far away but all worked great! I even got 1 or 2 split ones from the rolling shutter so I am anxious to see if my idea of putting the 2 cuts together will work out ok to where it is useable. Ill post later, this is the only shot I looked at so far.
500D/T1i  550D/T2i  600D/T3i  700D/T5i

mk11174

  • Hero Member
  • *****
  • Posts: 775
Re: Bolt trigger module test results
« Reply #12 on: June 11, 2013, 09:56:04 PM »

Ok, here is a split shot that was from the rolling shutter, but good thing was I barely got any splits with this storm, most were actually full frame, but anyway, this was split almost in the middle, easily in post was fixable because each split is captured on separate frames, only issue is, if its windy and your tripod moved it will be a tad bit tricker to merge them like in this shot on the left side you will see some ghosting because I did not make my remote trigger yet so I had to manually hold the shutter button which slightly moves the cam, but worked out fine considering.
500D/T1i  550D/T2i  600D/T3i  700D/T5i

mk11174

  • Hero Member
  • *****
  • Posts: 775
Re: Bolt trigger module test results
« Reply #13 on: June 11, 2013, 10:23:57 PM »


I wont upload all of them, don't want to fill page, but just to show how much you can push these raw images, I am able to go with a nice dark sky and bring out the bolt without screwing the image up like if it was from the HDV cam or a JPG, RAW Rocks!!!

THANK YOU ML for your Silent Picture End Trigger feature!

And of course thank you g3gg0 cause I know he will figure out what is wrong with the trigger because IT DOES WORK!
500D/T1i  550D/T2i  600D/T3i  700D/T5i


mk11174

  • Hero Member
  • *****
  • Posts: 775
Re: Bolt trigger module test results
« Reply #15 on: June 12, 2013, 01:42:19 AM »
updated the code.
it will record a bit longer than the specified number of frames, but thats no show stopper.
tried with a laser and seem to work fine.
Ok, it seems to catch the detection now, only thing is, not sure if it is planned like this, but the only way you can save each detection is to stop the recording after each detection. And then start a new record everytime. If you try to let all detections get caught on same raw file then I guess things get over written because I let it record and flash 6 flashes and when I do this, I get none captured. Only if I stop recording after each flash.

The 1st bolt trigger got every detection all in one recording and seemed more stable because the last 2 updates with pre buffer for some reason after a few detections it starts recording constant all by itself and you have to shut cam down to make it work right again?

Personally I will use the 1st trigger without pre buffer because I liked how it just captured everything in one record session, here in Florida storms move fast and bolts come very fast in between eachother, it takes to long to stop recording wait a couple scs then start it back up, plus if I have to sit right there at the cam it is easier to just get remote trigger and use the silent picture end trigger feature because you dont have to set anything up there.

But I do like the 1st trigger module the best and will prefer that over the silent picture end trigger feature.

One thing I do like about the Silent picture is after each bolt when you let go of the shutter it shows you a preview of the frames so you know if you got any bolts or if you have to adjust your exposure in case a bolt get over exposed.

But I really need to make a remote trigger for the half shutter cause your arm gets tired holding it in there air so long, or Ill just use the 1st trigger module which is probably what I will do next time to make sure it captures the bolts on time which I am sure it will at this point. But I want to be in the feild giving it a test for a full storm first to make my final choice.

Thanks again for all your hard work.
500D/T1i  550D/T2i  600D/T3i  700D/T5i

mk11174

  • Hero Member
  • *****
  • Posts: 775
Re: Bolt trigger module test results
« Reply #16 on: June 13, 2013, 05:42:59 PM »
Hi, in case anyone interested in the bolt trigger but is having issues with the pre-buffer version, here is the version that works for me before  pre buffer, it detects the main flash and records it plus post frames just fine. It should get you by till g3gg0 finishes tweaking up the pre buffer version.

By the way, I updated it to work with the config file save as well so your settings will save now. Not my code, all g3gg0's code, I just copied the needed files and pasted into this first version.

There are a few things I added just for my personal pref, but it is still g3gg0's code, but if you don't like the pref I added then blame me not him, his was fine, I just set it up for myself mainly but since the pre buffer version is having trouble right now I wanted you guys to have something that works, and this version was the one I already tweaked.

Things differ:
Position
Ability to change forground and background color
Separated plots so you only see plot that you enable so you can turn them on and off
Med font for Rec On and Off
Changed border a bit to go with separate plots.

All minor tweaks to my taste so full credit for working trigger goes to g3gg0!

http://www.mediafire.com/download/cnao9watwfy21p6/bolt_rec.mo

Geez, very important, this is only for people who compiled themselves and have modules turned on and if you want config save to work you must make and install the xml_cfg module.
500D/T1i  550D/T2i  600D/T3i  700D/T5i


mk11174

  • Hero Member
  • *****
  • Posts: 775
Re: Bolt trigger module test results
« Reply #18 on: June 14, 2013, 03:53:29 AM »
can you share your changes?
of coarse but i dont know how to do the whole bitbucket thing, could i just give you the whole file? i only know basic stuff.

Code: [Select]
/**
 * bolt_rec:
 * This module is designed to be used together with raw_rec.
 * It will extend raw_rec to trigger on lightning bolts and record for a defined amount of frames.
 * Due to the modular design of raw_rec, you don't have to change or configure it for bolt_rec.
 * As soon bolt_rec is being loaded, raw_rec knows what to do.
 *
 * It has two detection modes, absolute and relative.
 *
 * absolute:
 *   When a single pixel brightness gets above defined level (default=10000), recording starts.
 *
 * relative:
 *   Pixel brightness is compared to the previous level and starts when a single pixel delta (unsigned) gets above defined level (default=1000)
 *
 * As it would be too expensive to check every single pixel in the image, there are only a few pixels that get checked.
 * I decided to do it by lines, called "scanlines". A scanline is a complete horizontal row of pixels.
 * Please remind that we are working on raw bayer pattern, so it will scan RGRGRGRG or GBGBGBGB depending on the line count.
 * But I dont think that is an issue, as we want to record lightnings that are usually white. At least in germany they are ;)
 *
 * Scanlines are distributed over the whole image. If you select 1, then there is a single scanline in the center of the screen.
 * When selecting 2 scanlines, they will divide the image into 3 blocks, so one is at y = 1/3 * yRes.
 * Generic formula: distance = yRes / (scanlines + 1)
 *
 * Still missing is the "pre-buffering" as it requires a lot of changes in raw_rec that I didn't start yet.
 *
 * Please share your results :)
 *
 * __
 * g3gg0
 */

#include <module.h>
#include <dryos.h>
#include <property.h>
#include <bmp.h>
#include <menu.h>
#include <config.h>
#include <shoot.h>
#include "raw.h"

#define LOG_ENTRIES   110
#define MAX_SCANLINES 20
#define MAX_WIDTH     6000

/* interface functions required by raw_rec */
unsigned int raw_rec_cbr_starting();
unsigned int raw_rec_cbr_stopping();
unsigned int raw_rec_cbr_skip_frame(unsigned char *frame_data);
unsigned int raw_rec_cbr_skip_buffer(unsigned int buffer_index, unsigned int frame_count, unsigned int buffer_count);


/* recording options */
unsigned CONFIG_INT("enabled", bolt_rec_enabled, 0);
unsigned CONFIG_INT("post_frames", bolt_rec_post_frames, 5);
unsigned CONFIG_INT("plot_height", bolt_rec_plot_height, 105);
unsigned CONFIG_INT("color", plot_color, 15);
unsigned CONFIG_INT("bg_color", plot_bg_color, 3);

unsigned int plot_tb_position = 85;
unsigned int plot_lr_position = 594;
unsigned int bolt_rec_buffered = 0;

/* state variables */
unsigned int bolt_rec_recording = 0;
unsigned int bolt_rec_post_frames_recorded = 0;
unsigned int bolt_rec_vsync_calls = 0;

/* trigger method options */
unsigned CONFIG_INT("scanlines",   bolt_rec_scanlines,   6);
unsigned CONFIG_INT("rel_enabled", bolt_rec_rel_enabled, 0);
unsigned CONFIG_INT("rel_trigger", bolt_rec_rel_trigger, 2200);
unsigned CONFIG_INT("abs_enabled", bolt_rec_abs_enabled, 1);
unsigned CONFIG_INT("abs_trigger", bolt_rec_abs_trigger, 4000);

/* trigger method data */
unsigned short bolt_rec_rel_max = 800;
unsigned int bolt_rec_rel_log_pos = 0;
unsigned short bolt_rec_rel_peak[LOG_ENTRIES];
unsigned short *bolt_rec_rel_scanlines[MAX_SCANLINES];
unsigned short bolt_rec_rel_scanline_buf[MAX_SCANLINES * MAX_WIDTH];

unsigned short bolt_rec_abs_max = 800;
unsigned int bolt_rec_abs_log_pos = 0;
unsigned short bolt_rec_abs_peak[LOG_ENTRIES];
unsigned short bolt_rec_abs_avg[LOG_ENTRIES];


/* resolution dependent information, updated every callback */
unsigned int bolt_rec_y_step = 0;
unsigned int bolt_rec_x_start = 0;
unsigned int bolt_rec_x_end = 0;


/* this function reads raw_info */
static void bolt_rec_update_resolution()
{
    bolt_rec_y_step = raw_info.height / (bolt_rec_scanlines + 1);
    bolt_rec_x_start = raw_info.active_area.x1;
    bolt_rec_x_end = raw_info.active_area.x2;
}

static unsigned int bolt_rec_calculate_abs(unsigned char *buf)
{
    unsigned int pixelCount = 0;
    unsigned int peak = 0;
    unsigned int sum = 0;

    if(!bolt_rec_abs_enabled)
    {
        return 0;
    }

    for(unsigned int scanLine = 0; scanLine < bolt_rec_scanlines; scanLine++)
    {
        for(unsigned int pos = 0; pos < (bolt_rec_x_end-bolt_rec_x_start); pos++)
        {
            unsigned short value = raw_get_pixel_ex(buf, bolt_rec_x_start + pos, (scanLine + 1) * bolt_rec_y_step);

            sum += value;
            peak = MAX(value, peak);
            pixelCount++;
        }
    }

    sum /= pixelCount;

    /* update maximum value for plot */
    bolt_rec_abs_max = MAX(bolt_rec_abs_max, peak);

    /* put avg and max value into plot buffers */
    bolt_rec_abs_avg[bolt_rec_abs_log_pos] = sum;
    bolt_rec_abs_peak[bolt_rec_abs_log_pos] = peak;
    bolt_rec_abs_log_pos = (bolt_rec_abs_log_pos + 1) % LOG_ENTRIES;

    /* check if the detection routine detected activity */
    if(peak > bolt_rec_abs_trigger)
    {
        return 1;
    }

    return 0;
}

static unsigned int bolt_rec_calculate_rel(unsigned char *buf)
{
    unsigned int peak = 0;

    if(!bolt_rec_rel_enabled)
    {
        return 0;
    }

    for(unsigned int scanLine = 0; scanLine < bolt_rec_scanlines; scanLine++)
    {
        unsigned short *line = bolt_rec_rel_scanlines[scanLine];

        for(unsigned int pos = 0; pos < MIN((bolt_rec_x_end-bolt_rec_x_start), MAX_WIDTH); pos++)
        {
            unsigned short value = raw_get_pixel_ex(buf, bolt_rec_x_start + pos, (scanLine + 1) * bolt_rec_y_step);
            unsigned short last = line[pos];
            unsigned short delta = ABS(value-last);

            peak = MAX(delta, peak);
            line[pos] = value;
        }
    }

    /* update maximum value for plot */
    bolt_rec_rel_max = MAX(bolt_rec_rel_max, peak);

    /* put max value into plot buffers */
    bolt_rec_rel_peak[bolt_rec_rel_log_pos] = peak;
    bolt_rec_rel_log_pos = (bolt_rec_rel_log_pos + 1) % LOG_ENTRIES;

    /* check if the detection routine detected activity */
    if(peak > bolt_rec_rel_trigger)
    {
        return 1;
    }

    return 0;
}

static void bolt_rec_calculate(unsigned char *buffer)
{
    unsigned int abs_detection = bolt_rec_calculate_abs(buffer);
    unsigned int rel_detection = bolt_rec_calculate_rel(buffer);

    /* yet is is hardcoded */
    if(abs_detection || rel_detection)
    {
bolt_rec_recording = 1;
        bolt_rec_post_frames_recorded = 0;
    }
    else
    {
        if(bolt_rec_recording)
        {
            if(bolt_rec_post_frames_recorded < bolt_rec_post_frames)
            {
                bolt_rec_post_frames_recorded++;
            }
            else
            {
                /* stop recording, but make sure that the buffered frames get saved */
                bolt_rec_recording = 0;

            }
        }
    }
}

static unsigned int bolt_rec_vsync_cbr(unsigned int unused)
{
    if(!bolt_rec_enabled)
    {
        bolt_rec_rel_max = 0;
        bolt_rec_abs_max = 0;
        return 0;
    }

    bolt_rec_update_resolution();

    /* we are increasing that variable on every call, where the raw_rec callback resets is.
       this is for detecting where the values should be calculated.
      */
    if(bolt_rec_vsync_calls > 10)
    {
        bolt_rec_calculate(raw_info.buffer);
    }

    bolt_rec_vsync_calls++;
    return 0;
}

/* public function, is linked with raw_rec */
unsigned int raw_rec_cbr_skip_frame(unsigned char *buf)
{
    /* when bolt_rec is disabled, dont skip any frames */

    if(!bolt_rec_enabled)
    {
        bolt_rec_rel_max = 0;
        bolt_rec_abs_max = 0;

        return 0;
    }

    bolt_rec_update_resolution();

    /* make sure the vsync function doesnt calculate */
    bolt_rec_vsync_calls = 0;

    /* run detection algorithms */
    bolt_rec_calculate(buf);

    return !bolt_rec_recording;

}

/* we always throw away the buffered frames and save the new ones */
unsigned int raw_rec_cbr_skip_buffer(unsigned int buffer_index, unsigned int frame_count, unsigned int buffer_count)
{
    if(!bolt_rec_enabled)
    {
        return 0;
    }
   
    bolt_rec_buffered -= frame_count;
    return 1;

}

/* REL GRAPH */

static void bolt_rec_rel_plot(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned short *bg_plot, unsigned short *fg_plot, unsigned int start, unsigned int entries, unsigned short trigger, unsigned short max)
{
    /* fill background */
    bmp_fill(plot_bg_color, x, y, w, h);

    /* plot values */
    int offset = start;
    for(unsigned int entry = 0; entry < entries; entry++)
    {
        int pos = (offset + entry) % entries;
        int line_x = x + entry;
        int line_y = y + h;

        if(bg_plot)
        {
            draw_line(line_x, line_y, line_x, line_y - (bg_plot[pos] * h / max), plot_color);
        }
    }

    /* draw trigger value */
    unsigned int trigVal = MIN(h,trigger * h / max);
    draw_line(x - 1, y + h - trigVal, x + w + 1, y + h - trigVal, COLOR_WHITE);
}

void bolt_rec_rel_update_plots(int x, int y)
{
/* Paint Borders Around Plots */
    bmp_fill(COLOR_GRAY(30), x - 6, y - 6 + bolt_rec_plot_height, LOG_ENTRIES + 12, bolt_rec_plot_height + 12);
 
/* paint plots */
    bolt_rec_rel_plot(x, y + bolt_rec_plot_height, LOG_ENTRIES, bolt_rec_plot_height, bolt_rec_rel_peak, NULL, bolt_rec_rel_log_pos, LOG_ENTRIES, bolt_rec_rel_trigger, bolt_rec_rel_max);

/* print text into plot */
    bmp_printf(SHADOW_FONT(FONT_MED), x + 2, y + bolt_rec_plot_height + 8, "Rec: %s", bolt_rec_recording?"ON ":"OFF");
}

/* ABS PLOTS */

static void bolt_rec_abs_plot(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned short *bg_plot, unsigned short *fg_plot, unsigned int start, unsigned int entries, unsigned short trigger, unsigned short max)
{
    /* fill background */
    bmp_fill(plot_bg_color, x, y, w, h);

    /* plot values */
    int offset = start;
    for(unsigned int entry = 0; entry < entries; entry++)
    {
        int pos = (offset + entry) % entries;
        int line_x = x + entry;
        int line_y = y + h;

        if(bg_plot)
        {
            draw_line(line_x, line_y, line_x, line_y - (bg_plot[pos] * h / max), plot_color);
        }
    }

    /* draw trigger value */
    unsigned int trigVal = MIN(h,trigger * h / max);
    draw_line(x - 1, y + h - trigVal, x + w + 1, y + h - trigVal, COLOR_WHITE);
}

void bolt_rec_abs_update_plots(int x, int y)
{
/* Paint Borders Around Plots */
    bmp_fill(COLOR_GRAY(30), x - 6, y - 6, LOG_ENTRIES + 12, bolt_rec_plot_height + 12);

/* paint plots */
    bolt_rec_abs_plot(x, y, LOG_ENTRIES, bolt_rec_plot_height, bolt_rec_abs_peak, bolt_rec_abs_avg, bolt_rec_abs_log_pos, LOG_ENTRIES, bolt_rec_abs_trigger, bolt_rec_abs_max);

/* print text into plot */
    bmp_printf(SHADOW_FONT(FONT_MED), x + 2, y + 2, "Rec: %s", bolt_rec_recording?"ON ":"OFF");
}

static MENU_UPDATE_FUNC(bolt_rec_update_plot_menu)
{
    if(entry->selected && bolt_rec_enabled && bolt_rec_abs_enabled && lv)
    {
        bolt_rec_abs_update_plots(plot_lr_position, plot_tb_position);
    }
    if(entry->selected && bolt_rec_enabled && bolt_rec_rel_enabled && lv)
    {
        bolt_rec_rel_update_plots(plot_lr_position, plot_tb_position);
    }
}

static void bolt_rec_abs_plot_task()
{
    while(1)
    {
        if(!gui_menu_shown() && bolt_rec_enabled && bolt_rec_abs_enabled && lv)
        {
            bolt_rec_abs_update_plots(plot_lr_position, plot_tb_position);
        }
        msleep(100);
    }
}


static void bolt_rec_rel_plot_task()
{
    while(1)
    {
        if(!gui_menu_shown() && bolt_rec_enabled && bolt_rec_rel_enabled && lv)
        {
            bolt_rec_rel_update_plots(plot_lr_position, plot_tb_position);
        }
        msleep(100);
    }
}

static MENU_SELECT_FUNC(bolt_rec_toggle)
{
    bolt_rec_enabled = !bolt_rec_enabled;

    /* toggle the lv_save_raw flag from raw.c */
    if (bolt_rec_enabled)
    {
        raw_lv_request();
        raw_update_params();
    }
    else
    {
        raw_lv_release();
    }
    msleep(50);
}

static struct menu_entry bolt_rec_menu[] =
{
    {
        .name = "Bolt Trigger",
        .priv = &bolt_rec_enabled,
        .select = &bolt_rec_toggle,
        .max = 1,
        .submenu_width = 710,
        .depends_on = DEP_LIVEVIEW,
        .help = "Record 14-bit RAW video of lightning bolts.",
        .children =  (struct menu_entry[]) {
            {
                .name = "Post-bolt frame count",
                .priv = &bolt_rec_post_frames,
.update = &bolt_rec_update_plot_menu,
                .min = 0,
                .max = 1000,
            },
            {
                .name = "Plot FG Color",
                .priv = &plot_color,
.update = &bolt_rec_update_plot_menu,
                .min = 0,
                .max = 26,
            },
            {
                .name = "Plot BG Color",
                .priv = &plot_bg_color,
.update = &bolt_rec_update_plot_menu,
                .min = 0,
                .max = 26,
            },
            {
                .name = "Plot Height",
                .priv = &bolt_rec_plot_height,
.update = &bolt_rec_update_plot_menu,
                .min = 20,
                .max = 105,
            },
            {
                .name = "Scanlines",
                .priv = &bolt_rec_scanlines,
.update = &bolt_rec_update_plot_menu,
                .min = 1,
                .max = MAX_SCANLINES,
            },
            {
                .name = "Abs: trigger enabled",
                .priv = &bolt_rec_abs_enabled,
.update = &bolt_rec_update_plot_menu,
                .min = 0,
                .max = 1,
            },
            {
                .name = "Rel: trigger enabled",
                .priv = &bolt_rec_rel_enabled,
.update = &bolt_rec_update_plot_menu,
                .min = 0,
                .max = 1,
            },
            {
                .name = "Abs: trigger value",
                .priv = &bolt_rec_abs_trigger,
.update = &bolt_rec_update_plot_menu,
                .min = 0,
                .max = 16384,
            },
            {
                .name = "Rel: trigger value",
                .priv = &bolt_rec_rel_trigger,
.update = &bolt_rec_update_plot_menu,
                .min = 0,
                .max = 16384,
            },
            MENU_EOL,
        },
    }
};

static unsigned int bolt_rec_init()
{
    for(int pos = 0; pos < MAX_SCANLINES; pos++)
    {
        bolt_rec_rel_scanlines[pos] = &bolt_rec_rel_scanline_buf[MAX_WIDTH * pos];
    }

    menu_add("Movie", bolt_rec_menu, COUNT(bolt_rec_menu));

    task_create("bolt_rec_rel_plot_task", 0x1e, 0x1000, bolt_rec_rel_plot_task, (void*)0);
    task_create("bolt_rec_abs_plot_task", 0x1e, 0x1000, bolt_rec_abs_plot_task, (void*)0);
    return 0;
}

static unsigned int bolt_rec_deinit()
{

    raw_lv_release();
    return 0;
}



MODULE_INFO_START()
    MODULE_INIT(bolt_rec_init)
    MODULE_DEINIT(bolt_rec_deinit)
MODULE_INFO_END()

MODULE_STRINGS_START()
    MODULE_STRING("Description", "start video on lightning")
    MODULE_STRING("License", "GPL")
    MODULE_STRING("Author", "g3gg0")
    MODULE_STRING("Credits", "a1ex (raw_rec)")
MODULE_STRINGS_END()

MODULE_CBRS_START()
    MODULE_CBR(CBR_VSYNC, bolt_rec_vsync_cbr, 0)
MODULE_CBRS_END()

MODULE_CONFIGS_START()
    MODULE_CONFIG(bolt_rec_enabled)
    MODULE_CONFIG(bolt_rec_post_frames)
    MODULE_CONFIG(bolt_rec_plot_height)
    MODULE_CONFIG(bolt_rec_scanlines)
    MODULE_CONFIG(bolt_rec_rel_enabled)
    MODULE_CONFIG(bolt_rec_rel_trigger)
    MODULE_CONFIG(bolt_rec_abs_enabled)
    MODULE_CONFIG(bolt_rec_abs_trigger)
    MODULE_CONFIG(plot_color)
    MODULE_CONFIG(plot_bg_color)
MODULE_CONFIGS_END()

Im sure anything useful I changed you probably know a much easier way of writing it out, shortcuts or whatever, lol! I just stared at your code for an hour trying to see how it was doing things then tried adding things and they worked out ok.  :)

Oh, and I only added unsigned to the CONFIG_INT lines to get rid of the warning, wasn't sure if the warnings mattered but it stopped them during compile.
500D/T1i  550D/T2i  600D/T3i  700D/T5i

mk11174

  • Hero Member
  • *****
  • Posts: 775
Re: Bolt trigger module test results
« Reply #19 on: June 14, 2013, 09:12:56 PM »
So is there anyway to link your trigger module to Silent Picture Burst End Trigger, I really like everything about how it works, other then you have to hold the shutter button down half till a bolt strike because sometimes I might be looking at another part of the sky and miss a bolt that struck in front of the cam. But the amount of frames it records before and after strike is perfect plus the preview it gives when saving to card, the whole thing is just perfect, but would be ultimate if your trigger just the way it is when the abs hits the trigger value it activates the half shutter so it starts saving. But also have a menu choice to start the capture which would be a press and hold half shutter.

The bolt trigger does work from detection and post, but sometimes scary when you can't see a quick preview because bolts can be overexposed and you may need to adjust your aperture along the way so its nice the way the silent picture end trigger works, I would not change anything about but ling your trigger as a half shutter press when trigger value is reach. And after use rel and abs, abs is the better one for bolts, less chance of it going off by something else other then lightning.

Or may just have it trigger half shutter press to save and we can use half shutter hold to keep start capturing?

500D/T1i  550D/T2i  600D/T3i  700D/T5i


mk11174

  • Hero Member
  • *****
  • Posts: 775
Re: Bolt trigger module test results
« Reply #21 on: June 15, 2013, 12:08:40 AM »
uh hehe. let me first try to find the bug you reported. :)
ok cool  :)
500D/T1i  550D/T2i  600D/T3i  700D/T5i

g3gg0

  • Developer
  • Hero Member
  • *****
  • Posts: 3017
Re: Bolt trigger module test results
« Reply #22 on: June 15, 2013, 05:24:35 PM »
i cannot reproduce the bug you said.
with a similar setup i fired the flash 4 times and waited a bit. every time it recorded what i expected.

i implemented a tracing module to see what is happening and found some things that i didnt think of, but that should not make any difference.
are you sure you used the latest one?

i set up an experimental fork here: https://bitbucket.org/g3gg0/magic-lantern


Kim.dh

  • New to the forum
  • *
  • Posts: 43
Re: Bolt trigger module test results
« Reply #24 on: June 15, 2013, 08:14:34 PM »
Mk, sorry for asking this (I am on a bad laptop on an expensive gprs connection or I would attempt it myself);
My build (v2.3 NEXT Jun 3rd for 550d) is unable to load the bolt module you linked (error: OldAPI Wrong version v1.3, expected 1.2).

If it wont take you too long and it is possible, could you compile it for v1.3? Thanks in advance.