Skip to content

Instantly share code, notes, and snippets.

@carandraug
Last active August 24, 2017 16:28
Show Gist options
  • Save carandraug/1f363eee285e781572752159cb975599 to your computer and use it in GitHub Desktop.
Save carandraug/1f363eee285e781572752159cb975599 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <asdkWrapper.h>
#include <Windows.h>
// cl /I "C:\Programs Files\Alpao\SDK\Include" /c dm-test.c
// cl dm-test.obj "C:\Program Files\Alpao\SDK\Lib\x86\ASDK.lib"
// dm-test.exe
int
main ()
{
// Four patterns, each one with a feature on four opposite sides.
// Our mirror has 69 actuators.
double patterns[69 * 4] = { 0.0 };
patterns[8] = 1.0; // E
patterns[69 + 27] = 1.0; // N
patterns[69 * 2 + 32] = 1.0; // S
patterns[69 * 3 + 60] = 1.0; // W
asdkDM* dm = asdkInit ("BIL103");
if (! dm)
{
puts ("Failed to initialize -- got a NULL pointer");
asdkPrintLastError ();
return 1;
}
else if (asdkGetLastError(NULL,NULL,0) == SUCCESS)
{
// Instanciation succeed, but error exist
puts ("Failed to initialize -- Error detected");
asdkPrintLastError ();
return 1;
}
// Documentation states that a NULL pointer is returned if it fails
// to initialize. We found that it is not true, at least in the
// case of not finding the mirror config files (usually because of a
// type on the serial number). A simple check is to try to get the
// number of actuators.
double n;
if (asdkGet (dm, "NbOfActuator", &n) != SUCCESS)
{
puts ("Failed to initialize even though not a NULL pointer");
asdkPrintLastError ();
return 1;
}
printf ("We have %i actuators\n", (int)n);
puts ("Reset mirror to start test");
if (asdkReset (dm) != SUCCESS)
{
asdkPrintLastError ();
return 1;
}
for (int i = 0; i < 4; i++)
{
printf ("Applying pattern %i\n", i);
if (asdkSend (dm, &patterns[69*i]) != SUCCESS)
{
asdkPrintLastError ();
return 1;
}
Sleep (2000);
}
puts ("Reset mirror again before sending patterns for hardware trigger");
if (asdkReset (dm) != SUCCESS)
{
asdkPrintLastError();
return 1;
}
puts ("Enabling hardware trigger on falling edge");
if (asdkSet (dm, "TriggerIn", 2.0) != SUCCESS)
{
asdkPrintLastError ();
return 1;
}
puts ("Sending all patterns");
if (asdkSendPattern (dm, patterns, 4, 4) != SUCCESS)
{
asdkPrintLastError ();
return 1;
}
puts ("Patterns sent. Trigger mirror to apply or press enter to exit");
getchar ();
// Always disable trigger input at end
puts ("Disabling hardware trigger on falling edge");
if (asdkSet (dm, "TriggerIn", 0.) != SUCCESS)
{
asdkPrintLastError ();
return 1;
}
puts ("Release deformable mirror");
if (asdkRelease( dm ) != SUCCESS)
{
asdkPrintLastError ();
return 1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment