2 #include "XYControlStanda.h"
3 #include "ScopeDefines.h"
4 #include "parameters/Devices.h"
6 #include "helpers/ScopeException.h"
7 #include "controllers/ScopeLogger.h"
9 #ifdef SCOPE_USE_STANDA_XYFPUSTAGE
13 XYControlStanda::XYControlStanda()
15 , microsteps_per_micron(3.226) {
18 XYControlStanda::~XYControlStanda(
void) {
21 std::lock_guard<std::mutex> lock(mutex);
31 void XYControlStanda::Initialize(parameters::XYControlStanda& _params) {
33 std::lock_guard<std::mutex> lock(mutex);
35 ScopeLogger scope_logger;
36 std::stringstream msg;
37 msg <<
"XYControlStanda connected\r\n";
38 for ( uint32_t i = 0 ; i < devices.NOD ; i++ )
39 msg <<
"Device " << i <<
" - " << devices.Serial[i] <<
" - " << devices.Version[i] <<
"\r\n";
40 CA2W tmp(msg.str().c_str());
41 scope_logger.Log(std::wstring(tmp), log_info);
46 dev[0] =
static_cast<DWORD
>(_params.devicex());
47 dev[1] =
static_cast<DWORD
>(_params.devicey());
48 speed =
static_cast<float>(_params.speed());
49 microsteps_per_micron = _params.microstepspermicron();
50 for ( uint32_t d = 0 ; d < 2 ; d++ )
56 std::wstring msg2(L
"Initialized XYControlStanda");
57 scope_logger.Log(msg2, log_info);
65 _params.stageinfo = L
"XYControlStanda\r\n\r\nStart Parameters\r\n" + GetStartParameters() + L
"\r\n\r\nParameters\r\n"+ GetParameters() + L
"\r\n\r\nMode\r\n" + GetMode();
68 void XYControlStanda::InitAxis(
const DWORD& _device) {
71 mode.SyncINOp =
false;
75 CheckError(USMC_GetStartParameters(_device, stprms));
77 stprms.SlStart =
true;
78 stprms.LoftEn =
false;
79 stprms.WSyncIN =
false;
80 stprms.ForceLoft =
false;
83 void XYControlStanda::TurnOffAndSaveToFlash(
const DWORD& _device) {
92 std::this_thread::sleep_for(std::chrono::milliseconds(50));;
94 }
while(state.Power == TRUE);
96 prms.StartPos = state.CurPos;
97 CheckError(USMC_SetParameters( _device, prms));
99 CheckError(USMC_SaveParametersToFlash( _device ));
103 void XYControlStanda::StartPolling() {
106 fut = std::async([
this]() {
107 while (!stop.IsSet()) {
109 std::lock_guard<std::mutex> lock(mutex);
110 UpdatePositionValues();
113 std::this_thread::sleep_for(std::chrono::milliseconds(pollinterval));
120 void XYControlStanda::UpdatePositionValues() {
121 for ( uint32_t d = 0 ; d < 2 ; d++ ) {
124 double micron = round(static_cast<double>(state.CurPos)/microsteps_per_micron * 10.0) / 10.0;
126 pos[d]->Set(micron,
true,
false);
130 void XYControlStanda::SetZero() {
132 std::lock_guard<std::mutex> lock(mutex);
133 for ( uint32_t d = 0 ; d < 2 ; d++ )
134 CheckError(USMC_SetCurrentPosition(dev[d], 0));
135 std::this_thread::sleep_for(std::chrono::milliseconds(500));
140 void XYControlStanda::MoveRelative(
const double& _xrel,
const double& _yrel) {
142 std::lock_guard<std::mutex> lock(mutex);
143 for ( uint32_t d = 0 ; d < 2 ; d++ ) {
145 DBOUT(L
"XYControlStanda::MoveRelative from " << state.CurPos << L
" by " << _xrel << L
" " << _yrel);
146 CheckError(USMC_Start(dev[d], state.CurPos+round2i32(microsteps_per_micron*((d==0)?_xrel:_yrel)), speed, stprms));
148 std::this_thread::sleep_for(std::chrono::milliseconds(500));
154 void XYControlStanda::MoveAbsolute(
const double& _xabs,
const double& _yabs) {
156 std::lock_guard<std::mutex> lock(mutex);
157 for ( uint32_t d = 0 ; d < 2 ; d++ ) {
159 DBOUT(L
"XYControlStanda::MoveAbsolute to " << _xabs << L
" " << _yabs);
160 CheckError(USMC_Start(dev[d], round2i32(microsteps_per_micron*((d==0)?_xabs:_yabs)), speed, stprms));
162 std::this_thread::sleep_for(std::chrono::milliseconds(500));
167 void XYControlStanda::CheckError(
const DWORD& errorcode) {
168 if ( errorcode != 0 ) {
169 char perrorstring[256];
170 USMC_GetLastErr(perrorstring, 256);
171 throw( ScopeException(perrorstring) );
175 std::wstring XYControlStanda::GetParameters() {
176 std::lock_guard<std::mutex> lock(mutex);
177 std::wstringstream stream;
179 for ( uint32_t d = 0 ; d < 2 ; d++ ) {
181 stream << L
"Axis: " << d << L
" Device: " << dev[d] << L
"\r\nAccel time (ms): " << prms.AccelT << L
"\r\nDecel time (ms): " << prms.DecelT << L
"\r\nCurrent reduction time (ms): ";
182 stream << prms.PTimeout << L
"\r\nTime to speed B time (ms): " << prms.BTimeout1 << L
"\r\nReset time (ms): " << prms.BTimeoutR;
183 stream << L
"\r\nSpeed at reset (steps/s): " << prms.MinP << L
"\r\nSpeed B (steps/s): " << prms.BTO1P << L
"\r\nSteps for backlash: " << prms.MaxLoft;
184 stream << L
"\r\nPosition in flash: " << prms.StartPos << L
"\r\nSteps per revolution: " << prms.RTDelta << L
"\r\nSteps missed for error flag: ";
185 stream << prms.RTMinError << L
"\r\nMax temperature (C): " << prms.MaxTemp << L
"\r\nSync out pulse duration: " << prms.SynOUTP;
186 stream << L
"\r\nLast phase backlash speed: " << prms.LoftPeriod << L
"\r\nEncoder steps per rev/SM steps per rev: " << prms.EncMult << L
"\r\n";
193 std::wstring XYControlStanda::GetMode() {
194 std::lock_guard<std::mutex> lock(mutex);
195 std::wstringstream stream;
197 for ( uint32_t d = 0 ; d < 2 ; d++ ) {
199 stream << L
"Axis: " << d << L
" Device: " << dev[d] << L
"\r\nButtons disabled: " << mode.PMode << L
"\r\nCurrent reduction: " << mode.PReg << L
"\r\nReset: " << mode.ResetD;
200 stream << L
"\r\nQuick power off: " << mode.EMReset << L
"\r\nTrailer 1: " << mode.Tr1T << L
"\r\nTrailer 2: " << mode.Tr2T << L
"\r\nRotary transducer: ";
201 stream << mode.RotTrT << L
"\r\nTrailers swapped: " << mode.TrSwap << L
"\r\nTrailer 1 operation: " << mode.Tr1En << L
"\r\nTrailer 2 operation: ";
202 stream << mode.Tr2En << L
"\r\nRotary transducer operation: " << mode.RotTeEn << L
"\r\nRotary transducer operation select: " << mode.RotTrOp;
203 stream << L
"\r\nButton 1: " << mode.Butt1T << L
"\r\nButton 2: " << mode.Butt2T << L
"\r\nReset rotary transducer: " << mode.ResetRT;
204 stream << L
"\r\nSync Out enabled: " << mode.SyncOUTEn << L
"\r\nSync Out counter reset: " << mode.SyncOUTR << L
"\r\nSync In mode: " << mode.SyncINOp;
205 stream << L
"\r\nSync count: " << mode.SyncCount << L
"\r\nSync invert: " << mode.SyncInvert << L
"\r\nEnable Encoder: " << mode.EncoderEn;
206 stream << L
"\r\nInvert Encoder: " << mode.EncoderInv << L
"\r\nReset Encoder position: " << mode.ResBEnc << L
"\r\nReset SM position to encoder position: ";
207 stream << mode.ResEnc << L
"\r\n";
214 std::wstring XYControlStanda::GetState() {
215 std::lock_guard<std::mutex> lock(mutex);
216 std::wstringstream stream;
218 for ( uint32_t d = 0 ; d < 2 ; d++ ) {
220 stream << L
"Axis: " << d << L
" Device: " << dev[d] << L
"\r\nCurrent position: " << state.CurPos << L
"\r\nTemperature: " << state.Temp << L
"\r\nStep divisor: " << state.SDivisor;
221 stream << L
"\r\nBacklash status: " << state.Loft << L
"\r\nFull power: " << state.FullPower << L
"\r\nCurrent direction: " << state.CW_CCW;
222 stream << L
"\r\nPower: " << state.Power << L
"\r\nFull speed: " << state.FullSpeed << L
"\r\nAfter reset: " << state.AReset << L
"\r\nRotating: ";
223 stream << state.RUN << L
"\r\nInput sync state: " << state.SyncIN << L
"\r\nOutput sync state: " << state.SyncOUT << L
"\r\nRotary transducer state: ";
224 stream << state.RotTr << L
"\r\nRotary transducer error: " << state.RotTrErr << L
"\r\nEmergeny disable state: " << state.EmReset << L
"\r\nTrailer 1 state: ";
225 stream << state.Trailer1 << L
"\r\nTrailer 2 state: " << state.Trailer2 << L
"\r\nVoltage: " << state.Voltage << L
"\r\n";
232 std::wstring XYControlStanda::GetStartParameters() {
233 std::lock_guard<std::mutex> lock(mutex);
234 std::wstringstream stream;
236 for ( uint32_t d = 0 ; d < 2 ; d++ ) {
237 CheckError(USMC_GetStartParameters(dev[d], stprms));
238 stream << L
"Axis: " << d << L
" Device: " << dev[d] << L
"\r\nStep divisor: " << stprms.SDivisor << L
"\r\nBacklash direction: " << stprms.DefDir << L
"\r\nAutomatic backlash: ";
239 stream << stprms.LoftEn << L
"\r\nSlow start/stop enabled: " << stprms.SlStart << L
"\r\nWait for input sync signal: " << stprms.WSyncIN;
240 stream << L
"\r\nReset sync out counter: " << stprms.SyncOUTR << L
"\r\nForce backlash: " << stprms.ForceLoft << L
"\r\n";
virtual void Initialize(parameters::XYControl &_params)
Initialize hardware.
This is the include file for standard system include files, or project specific include files that ar...
bool CheckError(const int32 &error)
Checks return value of NI DAQmx function for error, prints out error information and throws an except...
#define DBOUT(s)
A debug output to the debug console.
void ScopeExceptionHandler(const std::string &_origin, const bool &_log, const bool &_showmessagebox, const bool &_trace, const bool &_rethrow)
Handles all exceptions and does nice logging.
Various helper functions and classes for Scope.