116,20 → 116,16 |
#include <utility.h> |
#include "ThorlabsLTS_ui.h" |
|
|
#include "ThorlabsMotionControlIntegratedStepperMotors.h" |
#include "ThorlabsLTS.h" |
|
|
void LTS_waitMove(int i, int timeout); |
void LTS_waitHome(int i, int timeout); |
char serialNumbers[][9] = {"45388004", "45387934","45388034"}; |
|
// Set number of microsteps, found in APT communications protocol. Should be changed to 136533 if using K10CR1 |
int StepsPerMm = 409600; |
double SingleMove=1; // in mm |
|
int LTSTimerOut=0; |
int p1_h; |
int pth=0,tctrl; |
|
|
int CVICALLBACK LTS_Timeout (int panel, int control, int event, |
150,34 → 146,76 |
SetCtrlAttribute (p1_h, P1_TIMEOUT, ATTR_ENABLED, 0); |
} |
*/ |
|
// tout in ms |
void LTS_Tmlnk (int tout) { |
if (!pth) { |
pth = NewPanel (0, "Timeout pannel", 0, 0, 200, 200); |
tctrl = NewCtrl (pth, CTRL_TIMER, "Timeout", 0, 0); |
SetCtrlAttribute (pth, tctrl, ATTR_CALLBACK_FUNCTION_POINTER, LTS_Timeout); |
SetCtrlAttribute (pth, tctrl, ATTR_ENABLED, 0); |
SetCtrlAttribute (pth, tctrl, ATTR_CTRL_MODE, VAL_INDICATOR); |
// SetActiveCtrl (pth, tctrl); |
} |
LTSTimerOut = 0; |
SetCtrlAttribute (p1_h, P1_TIMEOUT, ATTR_INTERVAL, (float)tout/1000.); |
SetCtrlAttribute (p1_h, P1_TIMEOUT, ATTR_ENABLED, 1); |
SetCtrlAttribute (pth, tctrl, ATTR_INTERVAL, (double)tout/1000.); |
SetCtrlAttribute (pth, tctrl, ATTR_ENABLED, 1); |
} |
|
void LTS_Tmulk ( void ) { |
SetCtrlAttribute (p1_h, P1_TIMEOUT, ATTR_ENABLED, 0); |
SetCtrlAttribute (pth, tctrl, ATTR_ENABLED, 0); |
LTSTimerOut = 0; |
} |
|
void LTS_Home(int i,int wait){ |
//Waits should only be used for Home commands. The home command has a different status return. |
void LTS_waitHome(int i, int tout)// Waits until a single axis is homed. |
{ |
WORD messageType=0; |
WORD messageId=0; |
DWORD messageData=0; |
int condition=0; |
LTS_Tmlnk (tout); |
do { |
while (!ISC_MessageQueueSize(serialNumbers[i])){ |
Sleep(250); |
ProcessSystemEvents(); |
if (LTSTimerOut) break; |
} |
if (LTSTimerOut){ |
printf( "Timeout in axis [%d] pos: %f messageType %d, messageId %d\n",i,LTS_GetPosition(i), messageType, messageId); |
break; |
} |
ISC_GetNextMessage(serialNumbers[i], &messageType, &messageId, &messageData); |
printf( "axis [%d] pos: %f messageType %d, messageId %d\n",i,LTS_GetPosition(i), messageType, messageId); |
condition = (messageType == 2) && (messageId == 0); |
} while (!condition); |
|
LTS_Tmulk(); |
} |
|
//Set up homing parameters. |
MOT_HomingParameters homingParams; |
ISC_GetHomingParamsBlock(serialNumbers[i], &homingParams); |
homingParams.direction = MOT_Reverse; |
ISC_SetHomingParamsBlock(serialNumbers[i], &homingParams); |
|
//Clear existing messages in the hardware buffer. |
ISC_ClearMessageQueue(serialNumbers[i]); |
|
//Home the stage and wait for the return message before continuing. |
ISC_Home(serialNumbers[i]); |
printf( "Start Homing...\n"); |
if (wait) LTS_waitHome(i, wait); |
// printf( "Homed...\n"); |
void LTS_waitMove(int i, int tout)// Waits until axis is stopped. |
{ |
WORD messageType=0; |
WORD messageId=0; |
DWORD messageData=0; |
int condition=0; |
LTS_Tmlnk (tout); |
do { |
while (!ISC_MessageQueueSize(serialNumbers[i])){ |
Sleep(250); |
ProcessSystemEvents(); |
if (LTSTimerOut) break; |
} |
if (LTSTimerOut){ |
printf( "Timeout in axis [%d] pos: %f messageType %d, messageId %d\n",i,LTS_GetPosition(i), messageType, messageId); |
break; |
} |
ISC_GetNextMessage(serialNumbers[i], &messageType, &messageId, &messageData); |
// printf( "axis [%d] pos: %f messageType %d, messageId %d\n",i,LTS_GetPosition(i), messageType, messageId); |
condition = (messageType == 2) && (messageId == 1); |
} while (!condition); |
|
|
LTS_Tmulk(); |
} |
|
int LTS_Init(int i){ |
195,7 → 233,8 |
if (errorReturn == 0){ |
printf( "Device %d (serial %s) Connected... \n",i, serialNumbers[i]); |
//Settings are loaded based on Stage Name. The integrated stepper class holds LTS and K10CR1 Information. |
ISC_SetLEDswitches(serialNumbers[i], 0); // disable LED |
ISC_SetLEDswitches(serialNumbers[i], 0); // disable LED |
Sleep(100); |
ISC_StartPolling(serialNumbers[i], 50); |
Sleep(1000); |
} else { |
204,6 → 243,21 |
return errorReturn; |
} |
|
int LTS_Open(){ |
|
TLI_BuildDeviceList(); |
TLI_DeviceInfo info; |
int err=0; |
for (int i=0;i<3;i++){ |
TLI_GetDeviceInfo(serialNumbers[i], &info); |
Sleep(100); |
err = LTS_Init(i); |
printf("%s err=%x\n", info.description, err); |
if (err) return err; |
} |
return 0; |
} |
|
void LTS_Close(int i){ |
//Close the stage |
ISC_StopPolling(serialNumbers[i]); |
211,6 → 265,25 |
printf( "Device Disconnected...\n"); |
} |
|
// wait in ms |
void LTS_Home(int i,int wait){ |
|
//Set up homing parameters. |
MOT_HomingParameters homingParams; |
ISC_GetHomingParamsBlock(serialNumbers[i], &homingParams); |
homingParams.direction = MOT_Reverse; |
ISC_SetHomingParamsBlock(serialNumbers[i], &homingParams); |
|
//Clear existing messages in the hardware buffer. |
ISC_ClearMessageQueue(serialNumbers[i]); |
|
//Home the stage and wait for the return message before continuing. |
ISC_Home(serialNumbers[i]); |
printf( "Start Homing...\n"); |
if (wait) LTS_waitHome(i, wait); |
printf( "Homed...\n"); |
} |
|
void LTS_StopProfiled(int i){ |
ISC_StopProfiled(serialNumbers[i]); |
} |
218,6 → 291,8 |
void LTS_MoveAbsolute(int i, double position, int wait){ |
ISC_SetMoveAbsolutePosition(serialNumbers[i], (position*StepsPerMm)); |
ISC_MoveAbsolute(serialNumbers[i]); |
//Clear existing messages in the hardware buffer. |
ISC_ClearMessageQueue(serialNumbers[i]); |
if (wait) LTS_waitMove(i, wait); |
|
} |
225,6 → 300,8 |
void LTS_MoveRelative(int i, double distance, int wait){ |
ISC_SetMoveRelativeDistance(serialNumbers[i], (distance*StepsPerMm)); |
ISC_MoveRelativeDistance(serialNumbers[i]); |
//Clear existing messages in the hardware buffer. |
ISC_ClearMessageQueue(serialNumbers[i]); |
if (wait) LTS_waitMove(i, wait); |
} |
|
257,22 → 334,6 |
return ISC_GetNumberPositions(serialNumbers[i]); |
} |
|
int LTS_Open(){ |
|
TLI_BuildDeviceList(); |
TLI_DeviceInfo info; |
int err=0; |
for (int i=0;i<3;i++){ |
TLI_GetDeviceInfo(serialNumbers[i], &info); |
Sleep(100); |
err = LTS_Init(i); |
printf("%s err=%x\n", info.description, err); |
if (err) return err; |
} |
return 0; |
} |
|
|
void LTS_RegisterMessageCallback(int i, void (* functionPointer)()){ |
ISC_RegisterMessageCallback(serialNumbers[i], functionPointer ); |
} |
284,60 → 345,13 |
void LTS_GetDeviceUnitFromRealValue(int i, double real_unit, int *device_unit, int unitType){ |
ISC_GetDeviceUnitFromRealValue(serialNumbers[i], real_unit, device_unit, unitType); |
} |
//Waits should only be used for Home commands. The home command has a different status return. |
void LTS_waitHome(int i, int tout)// Waits until a single axis is homed. |
{ |
WORD messageType=0; |
WORD messageId=0; |
DWORD messageData=0; |
int condition=0; |
LTS_Tmlnk (tout); |
do { |
while (!ISC_MessageQueueSize(serialNumbers[i])){ |
Sleep(250); |
if (LTSTimerOut) break; |
} |
if (LTSTimerOut){ |
printf( "Timeout in axis [%d] pos: %f messageType %d, messageId %d\n",i,LTS_GetPosition(i), messageType, messageId); |
break; |
} |
ISC_GetNextMessage(serialNumbers[i], &messageType, &messageId, &messageData); |
condition = (messageType == 2) && (messageId == 0); |
|
} while (!condition || !LTSTimerOut); |
|
LTS_Tmulk(); |
} |
|
void LTS_waitMove(int i, int tout)// Waits until axis is stopped. |
{ |
WORD messageType=0; |
WORD messageId=0; |
DWORD messageData=0; |
int condition=0; |
LTS_Tmlnk (tout); |
do { |
while (!ISC_MessageQueueSize(serialNumbers[i])){ |
Sleep(250); |
if (LTSTimerOut) break; |
} |
if (LTSTimerOut){ |
printf( "Timeout in axis [%d] pos: %f messageType %d, messageId %d\n",i,LTS_GetPosition(i), messageType, messageId); |
break; |
} |
ISC_GetNextMessage(serialNumbers[i], &messageType, &messageId, &messageData); |
condition = (messageType == 2) && (messageId == 1); |
|
} while (!condition); |
|
|
LTS_Tmulk(); |
} |
//******************************************************************* |
|
#ifdef LTS_MAIN |
|
|
int p1_h; |
int rID, tfID; |
|
#define MAX_THREADS 10 |
462,12 → 476,13 |
double n2; |
int comled; |
int enabled=0; |
|
double SingleMove=1; // in mm |
|
|
SetSleepPolicy(VAL_SLEEP_MORE); |
CmtNewThreadPool (MAX_THREADS, &poolHandle); |
SetStdioPort (CVI_STDIO_WINDOW); |
if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ |
if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; // out of memory |
|
p1_h = LoadPanel (0,"ThorlabsLTS_ui.uir", P1); |
//p1_h = BuildP1 (0); |
515,33 → 530,33 |
LTS_MoveRelative(2,-SingleMove, 0); |
break; |
case P1_HO: |
LTS_Home(0,0); |
LTS_Home(0,180000); |
break; |
case P1_HO_2: |
LTS_Home(1,0); |
LTS_Home(1,180000); |
break; |
case P1_HO_3: |
LTS_Home(2,0); |
LTS_Home(2,180000); |
break; |
case P1_GX: |
GetCtrlVal (p1_h, P1_XG, &n2); |
LTS_MoveAbsolute(0,n2,0); |
LTS_MoveAbsolute(0,n2,15000); |
break; |
case P1_GY: |
GetCtrlVal (p1_h, P1_YG, &n2); |
LTS_MoveAbsolute(1,n2,0); |
LTS_MoveAbsolute(1,n2,15000); |
break; |
case P1_GZ: |
GetCtrlVal (p1_h, P1_ZG, &n2); |
LTS_MoveAbsolute(2,n2,0); |
LTS_MoveAbsolute(2,n2,15000); |
break; |
case P1_G: |
GetCtrlVal (p1_h, P1_XG, &n2); |
LTS_MoveAbsolute(0,n2,0); |
LTS_MoveAbsolute(0,n2,15000); |
GetCtrlVal (p1_h, P1_YG, &n2); |
LTS_MoveAbsolute(1,n2,0); |
LTS_MoveAbsolute(1,n2,15000); |
GetCtrlVal (p1_h, P1_ZG, &n2); |
LTS_MoveAbsolute(2,n2,0); |
LTS_MoveAbsolute(2,n2,15000); |
break; |
case P1_B3: // reset |
case P1_B3_2: // reset |
633,6 → 648,7 |
#else |
// ************************************* |
|
/* |
int main(int argc, char ** argv) |
{ |
//Sets up simulations. Comment in if running on physical hardware. |
660,7 → 676,7 |
for (int k=0;k<10;k++){ |
LTS_MoveAbsolute(i,k); |
printf( "Moving ...\n"); |
waitMove(i); |
LTS_waitMove(i); |
printf( "Move Complete...\n"); |
} |
|
676,4 → 692,5 |
Delay(10); |
return 0; |
} |
*/ |
#endif |