PDA

View Full Version : trigger problem



icemake
April 26, 2013, 11:43:25
hi,
already, sorry if my english is hard to understand (i'm french)


I program in C and I want to use the features of trigger but I fail to understand how it works
Can you help me?

Stefan Geissler
April 26, 2013, 11:50:40
Hi

Which C Compiler do you use?
Which camera model do you use?
What do you want to achieve?

icemake
April 26, 2013, 11:55:01
I use MinGW as compiler
the model of my camera is DMK 23GP031

I would like the camera to take a picture when the strobe flash
I do not know if it is very clear

Stefan Geissler
April 26, 2013, 12:10:59
Hi

As shown in the "ansi.c" sample, the trigger is enabled as follows:


//////////////////////////////////////////////////////////////////////////
/*!
*/
void SetTrigger()
{
HGRABBER hGrabber = IC_ShowDeviceSelectionDialog(NULL);

if( IC_IsTriggerAvailable(hGrabber) == IC_SUCCESS )
{


IC_EnableTrigger(hGrabber,1);
IC_StartLive(hGrabber,1);

printf("Triggered, there should be new images only if a trigger pulse occurred\n");

printf("Press any key to continue!\n");
_getch();
}
else
{
printf("The device does not support triggering!\n");
}

IC_ReleaseGrabber(&hGrabber);
IC_CloseLibrary();

}


In order to be notified of a new image arrival, you add a callback, as shown in the "ansi.c" sample too. Then you only need to connect the cable, that lets your strobe flash parallel to the camera, so the camera is triggered together with the strobe flash.

icemake
April 29, 2013, 14:36:17
thank you for your response

but its not working
what is the minimum time of the pulse?
a pulse of 5V is enough?

if I replace the line HGRABBER hGrabber= IC_ShowDeviceSelectionDialog(NULL) by hGrabber=IC_CreateGrabber() does this work anyway

icemake
April 29, 2013, 16:32:50
I ask stupid questions
I tried HGRABBER hGrabber IC_ShowDeviceSelectionDialog = (NULL)
I don't need to this line if I manually return the data normally
so for now I sent a 5V signal for 1 ms and its not working I also try with 2 and 4 ms without success
I put the program I did, you maybe find why it does not work

void photo(char *nomcam,char *format,char *type,char *trigger)
{
int trig;
FILE *prephoto;
HGRABBER hGrabber;
trig = atoi(trigger);
if( IC_InitLibrary(0) == IC_SUCCESS )
{
hGrabber = IC_CreateGrabber();
if( hGrabber )
{
if( IC_OpenVideoCaptureDevice(hGrabber,nomcam) == IC_SUCCESS )
{
if(!(strcmp(format,"Y800")))
IC_SetFormat (hGrabber, Y800); //initialise le format de la camera
else if(!(strcmp(format,"RGB24")))
IC_SetFormat (hGrabber, RGB24); //initialise le format de la camera
else
IC_SetFormat (hGrabber, RGB32); //initialise le format de la camera
if( IC_IsTriggerAvailable(hGrabber) == IC_SUCCESS )
{
if(trig==0)
{
if(IC_StartLive (hGrabber, 0)==IC_SUCCESS)
{
if(!(strcmp(type,"BMP")))
IC_SaveImage ( hGrabber, image, FILETYPE_BMP,50);
else
IC_SaveImage ( hGrabber, image, FILETYPE_JPEG,50);
}
}
else if(trig==1)
{
IC_EnableTrigger(hGrabber,1);
if(IC_ StartLive (hGrabber, 0)==IC_SUCCESS)
{

do{
prephoto = fopen(image,"r");
}while(prephoto == NULL);
}
}
IC_StopLive (hGrabber); //stop la camera
IC_EnableTrigger(hGrabber,0);
}
}
// suprime les choses créé pour eviter les fuite de memoire
IC_CloseVideoCaptureDevice( hGrabber );
IC_ReleaseGrabber( &hGrabber );
}
//IC_CloseLibrary();
}
}

Stefan Geissler
April 29, 2013, 16:58:45
Well, the main issue is, that you do not snap an image at all. e.g. call IC_SnapImage(). Therefore, there is nothing to save.

Have a look ImageProcessing() function in the ansi.c sample



IC_StartLive(hGrabber, 1);
IC_SnapImage(hGrabber, 2000); // Snap a frame into memory
IC_SaveImage(hGrabber, "Test.jpg",FILETYPE_JPEG,90); // Save the snapped frame to harddisk


Try this without trigger first.

icemake
April 30, 2013, 09:16:56
I have already try it without the trigger and my program planted because of IC_SnapImage so I removed this and after the program without the trigger worked well
I also find it odd that he can record an image without IC_SnapImage but it works
and with the program of above if I do not use the trigger it work as I want
but with trigger its not working
I do not know if this is because of the trigger or because of the program but it does not work

icemake
May 2, 2013, 09:24:40
could i have a response please ?

Stefan Geissler
May 2, 2013, 10:51:34
I am very sorry, but there was holiday on May 1st.

icemake
May 2, 2013, 11:32:31
yes I understand
you have an idea of ​​the reason for which it does not work?

Stefan Geissler
May 2, 2013, 17:13:27
Hello

Your source code snippet works fine, if you pass "0" as trigger parameter to your photo function.

I wonder, what


IC_EnableTrigger(hGrabber,1);
if(IC_StartLive (hGrabber, 0)==IC_SUCCESS)
{
do{
prephoto = fopen(image,"r");
}while(prephoto == NULL);
}

is supposed to do, because I see no code, that saves an image. I also see no callback for doing this. However, the loop will terminate, in case the file "image" exists.

icemake
May 3, 2013, 09:14:05
In this snippet, I did not put recording function because I thought I understood that the photo is taken automatically when it has a trigger signal but if I put IC_SaveImage (hGrabber image, FILETYPE_BMP, 50); he does not expect the trigger signal to save the image

in what I thought, the camera waits for the trigger signal takes and saves the image and leave the loop when the image is saved

Stefan Geissler
May 3, 2013, 10:02:27
You are right, the camera takes the photo automatically and sends it to the computer, when the trigger pulse occurred. But in your code is nothing, that will handle the incoming image.

Therefore, I would add a callback function, that is called, when the image arrives automatically and save the image in there. You must call


IC_SetContinuousMode(hGrabber,0);

so the incoming images are saved into the internal ringbuffer automatically.

Please have a look at the "SoftwareTrigger()" and "CallbackTest()" sample functions in the "ansi.c" sample. (It does not matter, whether you use software or hardware trigger, in both cases the same happens in the camera.)

icemake
May 3, 2013, 11:20:08
I've looked and I was inspired to write her:

int photo(char *nomcam,char *format,char *type,char *trigger)
{
int trig;
int ImageReceived; // Flag that is set in the callback to 1 if an image is received.
int Tries;
//FILE *prephoto;
HGRABBER hGrabber;
trig = atoi(trigger);
if( IC_InitLibrary(0) == IC_SUCCESS )
{
hGrabber = IC_CreateGrabber();
if( hGrabber )
{
if( IC_OpenVideoCaptureDevice(hGrabber,"DMK 23GP031") == IC_SUCCESS )
{
if(!(strcmp(format,"Y800")))
IC_SetFormat (hGrabber, Y800); //initialise le format de la camera
else if(!(strcmp(format,"RGB24")))
IC_SetFormat (hGrabber, RGB24); //initialise le format de la camera
else
IC_SetFormat (hGrabber, RGB32); //initialise le format de la camera
if( IC_IsTriggerAvailable(hGrabber))
{
if(trig==0)
{
if(IC_StartLive (hGrabber, 0)==IC_SUCCESS) //lance la camera sans ouvrir de fenetre visualisant le contenu
{
if(IC_SnapImage(hGrabber, -1)==IC_SUCCESS)
{
if(!(strcmp(type,"BMP")))
IC_SaveImage ( hGrabber, image, FILETYPE_BMP,50);
else
IC_SaveImage ( hGrabber, image, FILETYPE_JPEG,50);
}
}
}
else if(trig==1)
{
IC_EnableTrigger(hGrabber,1);
IC_SetFrameReadyCallback (hGrabber, *TriggerCallback, (void*)&ImageReceived);
IC_SetContinuousMode(hGrabber,0);
if(IC_StartLive (hGrabber, 0)==IC_SUCCESS) //lance la camera sans ouvrir de fenetre visualisant le contenu
{
ImageReceived = 0; // Set the flag for image received to 0;
Tries = 60; // Tries for time out. Depends on the Sleep time and the frame rate.
while(Tries > 0 && ImageReceived == 0)
{
Sleep( 1000 );
Tries--;
}
if( ImageReceived == 1 )
{
if(!(strcmp(type,"BMP")))
IC_SaveImage ( hGrabber, image, FILETYPE_BMP,50);
else
IC_SaveImage ( hGrabber, image, FILETYPE_JPEG,50);
}
}
}
IC_StopLive (hGrabber); //stop la camera
IC_EnableTrigger(hGrabber,0);
}
}
// suprime les choses créé pour eviter les fuite de memoire
IC_CloseVideoCaptureDevice( hGrabber );
IC_ReleaseGrabber( &hGrabber );
}
//IC_CloseLibrary();
}

}



but its not working, ImageReceived remains at 0 it can be the signal that I'm sending who is not good
I send a 5V signal for 2ms

Stefan Geissler
May 3, 2013, 13:04:05
Hi

I checked this on my own and it is working fine. I would like you to try IC Capture and see, whether you can trigger with IC Capture. This is to make sure, your hardware is working fine.
IC Capture can be downloaded from http://www.theimagingsource.com/fr_FR/support/downloads/

Also make sure, the trigger is connected correctly: inside +, outside -

icemake
May 3, 2013, 13:36:18
I do not really know how it works I tried to click the button and it blocks the image directly without I put trigger

Stefan Geissler
May 3, 2013, 14:48:53
Did you debug your program code step by step, so you can be sure, that the correct branches are executed?
The camera wont send any image data, if the trigger is enabled no trigger pulse occurs

icemake
May 3, 2013, 14:59:38
yes I have debug my program step by step
I do not understand what you mean in your second sentence
the image is not supposed to be frozen when I click on "Enable external trigger" and I do not apply the trigger
is that you wanted to say?

icemake
May 7, 2013, 09:09:12
can you help me ?

Stefan Geissler
May 7, 2013, 09:23:30
Sorry, there is an "and" missing in the second sentence.

Enable trigger means calling
IC_EnableTrigger(hGrabber,1);

Now the camera should not provide an image, until an external trigger pulse (5V) occurs. You got it right, the live video is frozen.

However, if you snapped image previously, the image ring buffer are still filled with these older images. These images can be saved to hard disc.

icemake
May 7, 2013, 09:56:19
ok but if the image is frozen there must be a problem, no ?

would it not be because of that that its not working?

Stefan Geissler
May 7, 2013, 10:40:57
No. If the waiting for trigger is enabled, the camera does not provide an image. The camera waits for the trigger and then one single image is sent.

icemake
May 7, 2013, 11:03:31
I will try
but its rule not problem of my program :/

EDIT : I've tried plugging a external signal (5V) nothing changed the image is frozen and I have no window that opens like when I click on "Save Image"

Stefan Geissler
May 7, 2013, 15:57:28
did you create a 5V pulse? The camera need a change, it reacts on the edge of signal

icemake
May 7, 2013, 16:30:03
yes, I created a 0-5V square wave signal with 2ms at high level and 8ms at low level

Stefan Geissler
May 7, 2013, 16:52:51
That means, your trigger frequency is 10Hz. If the camera is running with a frame rate set above 10 Hz and a short enough exposure time, you should receive image with 10 Hz = 10 images per second.

Does this happen?

icemake
May 7, 2013, 17:09:56
No, as soon as I click the trigger button, the picture freezes and does not change that there was an external signal or not

Stefan Geissler
May 8, 2013, 09:22:35
Hello

Does the same happen in IC Capture, if waiting for trigger is enabled?

icemake
May 10, 2013, 09:10:06
yes
every test I've done since we've been in "page 2" I've done in IC capture

Stefan Geissler
May 10, 2013, 11:52:26
Then please ckeck your trigger signal. Check the polarization. Inside should be +, outside -

icemake
May 10, 2013, 14:12:40
I connect the signal directly to the supply
therefore the polarity is good

Stefan Geissler
May 10, 2013, 14:42:30
I connect the signal directly to the supply
therefore the polarity is good

The trigger signal should come from a trigger source into the trigger in of the camera, resp. the trigger cable. This is a BNC connector on the cable.

icemake
May 10, 2013, 14:54:58
yes, i created a triggering signal that I enter the cable trigger via a BNC connector

Stefan Geissler
May 10, 2013, 16:32:00
Sorry for asking: When you want the image, you change the voltage from 0V to 5V and back again. If IC Capture does not change the image, then there must be something wrong. I must admit, I run out of ideas.

icemake
May 10, 2013, 16:48:17
I created a periodic signal between 0 and 5V with 0v for 8ms and 5v for 2ms
in IC Capture, if I click on nothing I have a live video, but if I click on "external trigger" the picture freezes same if i connected a signal on the trigger
if I click again I recover over live video but he has not ask if I wanted to record an image

Stefan Geissler
May 13, 2013, 12:15:04
There must be something wrong with your trigger connection. Can you please show me, how you did it? E.g. a photo?

icemake
May 13, 2013, 13:14:09
here is a picture I do not know if that's what you want
the end of the cable is directly connected to the power
1550

Stefan Geissler
May 13, 2013, 14:38:03
The connection looks perfectly correct to me.


I created a periodic signal between 0 and 5V with 0v for 8ms and 5v for 2ms
in IC Capture, if I click on nothing I have a live video, but if I click on "external trigger" the picture freezes same if i connected a signal on the trigger
if I click again I recover over live video but he has not ask if I wanted to record an image

First of all, IC Capture will not ask, whether you want to save an image, if a trigger pulse occurs. I a trigger pulse occurs, the camera sends an image to the camera and IC Capture should display the new image. That is all. (Some web cams have a button, when it is pressed, a software pops up and asks where to save the image. But this behavior is unwanted for industrial cameras. )

From what you write, I read, that no new images are shown, regardless, whether there is a trigger pulse. The image in IC Capture is still frozen, right?

icemake
May 13, 2013, 14:48:53
the image is frozen from the moment when I click on "external triggering" and never changes

Stefan Geissler
May 13, 2013, 15:22:12
the image is frozen from the moment when I click on "external triggering" and never changes
Even, if you create a trigger pulse? Please let me know the specification of the pulse: Voltage is 5V and power is? And the scene in front of your camera changes?

icemake
May 13, 2013, 15:54:16
yes, even if there is a trigger pulse, image remains frozen
I did not really understand what you mean by "Voltage is 5V and power is?"

and I has still not received the lens I work without. so I can see if there is a change I open to or close the cover of the camera

Stefan Geissler
May 13, 2013, 17:19:57
I did not really understand what you mean by "Voltage is 5V and power is?"

I would like to know the amperes.

icemake
May 13, 2013, 17:59:29
I have 1.5 mA with a 1k resistor

Stefan Geissler
May 14, 2013, 09:24:14
Are you sure, its 1.5mA? Not 1.5A?

icemake
May 14, 2013, 10:12:50
yes, I was wrong
it is 1A I have not good seen

Stefan Geissler
May 14, 2013, 11:14:18
OK, that is, what I expected.

However, could you use a batter, e.g.4.5 volts and simply make a connection with wires to the trigger input, plus inside, minus outside? Just a short contact is fine and see, what happens?

icemake
May 14, 2013, 11:50:51
I tried doing and the trigger works
but if I leave it connected it's not working

Stefan Geissler
May 14, 2013, 12:30:10
I tried doing and the trigger works
Fine.


but if I leave it connected it's not working
Of course it does nothing. The triggers means expose one image on one trigger pulse. That means, only each time the level changes, an image is exposure. This is, how triggering is intended to work.

icemake
May 14, 2013, 13:11:56
So that would mean I have to have a time to the high level shorter and a time to the low level longer?

Stefan Geissler
May 14, 2013, 14:34:09
I think, this means, your standard 5V, 1A power supply is either not connected correctly, e.g. +/- switched, or it does not work at all.

Your pulse times, as you described them, are fine.

The camera will react on the rising edge of the pulse.

icemake
May 14, 2013, 14:44:20
I do not think because it is with this power that I do the test
I have not use ​​continuous feed
I used the same signal as usual, but for a short connection between two connectors

Stefan Geissler
May 15, 2013, 10:41:06
You wrote, using the battery works. When connecting the wires, you receive one image. That means, the camera works as expected.

However, the issue seems to be your signal. I suggest to check it with an oscilloscope, if possible.

icemake
May 15, 2013, 11:08:05
I always use an oscilloscope when I created my signal

Stefan Geissler
May 15, 2013, 11:17:27
Well,

I am lost know. We found, the camera reacts on the rising or falling edge of a trigger signal.

However, this does not seem to work in your desired environment. So you have to check, what is different. I can not do this from here.

icemake
May 15, 2013, 11:52:07
ok I'll get

icemake
May 16, 2013, 15:34:09
I have a little advanced if it can help you to find my problem
in IC Capture there is a place where you can change the fps and when he is 25 if I put 25Hz, he works
and 7.7 fps if I make 1 images all secondes, he works
for 25 fps for example he work between 23Hz and 26Hz but then it does not work below and above
Does it help you to find my problem?
thank you in advance

icemake
May 16, 2013, 16:32:19
after several test I got this the result:
the trigger works for a frequency between 0 and 12.7hz and 24.65 and 25.40hz, else its not working
but that does not bother me because my program used the trigger at the most every second, he works in IC capture I thought as it works in my program but no :/

I did not touch the program since I have shown you if you had any idea why it doesn't work :/

thank you in advance for your answers

Stefan Geissler
May 16, 2013, 16:52:52
First off all, all trigger frequencies should work, that a smaller than the frame rate. Please keep in mind, if the camera is still busy with exposure or image delivery to the computer, incoming trigger pulses are ignored.

Did you try
IC_SetContinuousMode(hGrabber,1);
in the branch, were you use the trigger input?

icemake
May 16, 2013, 17:02:46
ok


yes I have it in my program, but its not working
(so that you have the right information: I changed my trigger signal for a impution 2 ms for a period of 1s)

Stefan Geissler
May 17, 2013, 11:02:45
Since you mention this: "0V for 8ms and 5v for 2ms" This is 10ms. That means 100Hz trigger frequency. This can be done, but the frame rate must be much more than 100 fps and the exposure time must be very very short :-)

However, I will look into your program code again and come back to you.

Stefan Geissler
May 17, 2013, 11:10:08
Hello

I checked this code


IC_EnableTrigger(hGrabber,1);
IC_SetFrameReadyCallback (hGrabber, *TriggerCallback, (void*)&ImageReceived);
IC_SetContinuousMode(hGrabber,0);

if(IC_StartLive (hGrabber, 0)==IC_SUCCESS)
{
Tries = 60; // Tries for time out. Depends on the Sleep time and the frame rate.
while(Tries > 0 && ImageReceived == 0)
{
Sleep( 1000 );
Tries--;
}

printf("Loop ended\n");
}


And it works as expected.

IC_SetContinuousMode(hGrabber,0);

is correct, the paramater must be "0".

icemake
May 17, 2013, 11:55:58
in my program its not working
So if you said that it is correct, it's another place that has the bug but I do not think so because when I am not using the trigger works its impecable

the test where I did plugging the cable that very briefly that does not work with my program

icemake
May 17, 2013, 14:41:33
I have another little question at the same time
esque these lines of code can be used under Linux?

Stefan Geissler
May 17, 2013, 15:19:33
Hello

No, these lines can not be used in Linux. Unfortunately I have no Linux support at this point of time.

icemake
May 17, 2013, 15:56:32
ok

I will continue on windows until then
thank you for your answers

icemake
May 21, 2013, 09:54:25
I'm thinking about the program that you have shown and there is something I do not understand how can ImageReceived changed state by looking at the program there is no place where he can change?


and you know when you can have support for Linux?
because I'd like my program runs under Windows and Linux

thank you in advance for your answers

Stefan Geissler
May 21, 2013, 11:50:37
Hi

I copied a snipped of the complete program a few pages before. Its the one, you created. The ImageReceived changes state in the callback, I guess. However, in there is the position, where to save.


and you know when you can have support for Linux?
No. Sorry for that.

icemake
May 21, 2013, 12:07:20
ok I'm inspired ANSIC to write
therefore, after what you said
void _cdecl TriggerCallback (HGRABBER hGrabber, unsigned char * pData, unsigned long frameNumber, void * data)
that changes the value if I understand but I do not see when it is called
I ask this because in my ImageReceived program never changes so I searched or it changed because as long as it does not change the camera take not image, I use the same signal in ICcapture and ICcapture he takes out a picture every second as I would

ok

icemake
May 22, 2013, 15:42:00
have you any idea?

Stefan Geissler
May 22, 2013, 17:01:16
TriggerCallback is a callback. It is called by the grabber, when a new image arrived and IC_SetContinuousMode(hGrabber,0); was called once.

icemake
May 23, 2013, 09:14:30
agreed
So it's really not logical that it does not work but works with IC Capture

icemake
May 27, 2013, 09:49:01
Have you found something to make it work?

Stefan Geissler
May 27, 2013, 12:38:44
Sorry, but you lost me.



IC_EnableTrigger(hGrabber,1);

This enables waiting for extern trigger in the camera. No images are provided now, until the trigger pulse generates a rising edge.


IC_SetFrameReadyCallback (hGrabber, *TriggerCallback, (void*)&ImageReceived);

This passes the address of the callback function to the internal grabber. Now the grabber knows, there is a callback, that shall be called, if a new image arrives.


IC_SetContinuousMode(hGrabber,0);

This tells the grabber to save all incoming image automatically in memory and call the callback function.


if(IC_StartLive (hGrabber, 0)==IC_SUCCESS)

This starts the live video. Now the grabber is waiting for incoming images.

The following is the implmentation of the callback:


void _cdecl TriggerCallback(HGRABBER hGrabber, unsigned char* pData, unsigned long frameNumber, void* Data)
{
int *pImageReceived;
pImageReceived = (int*) Data;
*pImageReceived = 1;
printf("Callback called.\n");
}

icemake
May 27, 2013, 13:27:29
yes this is what I have but it does not work yet
if I send an external signal (which works with IC Capture) my program does not record images variable "ImageReceived" never changes state

Stefan Geissler
May 27, 2013, 14:46:44
Set a breakpoint into the TriggerCallback function and check, whether it was called.
Play with the parameters of IC_SetContinuousMode(hGrabber,0);

Make sure, the live video was started.

I am very sorry, but this sample works fine on my computer. Therefore, I wonder, what happens on yours.

icemake
May 28, 2013, 09:58:52
it's good it works I do not understand why but it works
I just changed the time of my "Sleep" and the external signal I spent to 20ms high level

thank you for helping me all this time