Scope
XYZControl.cpp
1 #include "StdAfx.h"
2 #include "XYZControl.h"
3 #include "parameters/Devices.h"
4 
5 namespace scope {
6 
7 XYZControl::XYZControl()
8  : initialized(false)
9  , pollinterval(1000) {
10 }
11 
13  StopPolling();
14 }
15 
17  xyzpos[0] = &_params.xpos;
18  xyzpos[1] = &_params.ypos;
19  xyzpos[2] = &_params.zpos;
20  pollinterval = round2ui32(_params.pollinterval());
21  // Polling more frequently will most definitely lead to problems...
22  if ( pollinterval > 100 ) {
23  // we need to call from the this pointer to call the most derived version of StartPolling
24  this->StartPolling();
25  }
26  initialized = true;
27 }
28 
30  fut = std::async([this]() {
31  while (!stop.IsSet()) {
33  std::this_thread::sleep_for(std::chrono::milliseconds(pollinterval));
34  }
35  return true;
36  } );
37 }
38 
40  stop.Set();
41  if ( fut.valid() )
42  fut.wait();
43 }
44 
46  // Do nothing
47 }
48 
50  SetZeroXAxis();
51  SetZeroYAxis();
52  SetZeroZAxis();
53 }
54 
55 }
ScopeNumber< double > zpos
position in micron of z axis
Definition: Devices.h:31
uint32_t pollinterval
interval (in milliseconds) to poll device
Definition: XYZControl.h:30
~XYZControl()
If pollthread was started, request stop and wait for finish.
Definition: XYZControl.cpp:12
virtual void SetZero()
Sets current xyz position as zero.
Definition: XYZControl.cpp:49
std::future< bool > fut
future for the async polling thread
Definition: XYZControl.h:24
bool initialized
true if initialized called successfully
Definition: XYZControl.h:18
ScopeNumber< double > ypos
position in micron of y axis
Definition: Devices.h:28
virtual void SetZeroYAxis()
Sets current Y position as zero.
Definition: XYZControl.h:77
ScopeNumber< double > xpos
position in micron of x axis
Definition: Devices.h:25
ScopeNumber< double > pollinterval
interval in milliseconds to poll device, be careful: long intervals slow quitting of Scope (since to ...
Definition: Devices.h:34
This is the include file for standard system include files, or project specific include files that ar...
StopCondition stop
to signal the async polling thread to stop
Definition: XYZControl.h:21
virtual void SetZeroZAxis()
Sets current Z position as zero.
Definition: XYZControl.h:80
virtual void SetZeroXAxis()
Sets current X position as zero.
Definition: XYZControl.h:74
Parameters for a general XYZ stage.
Definition: Devices.h:19
virtual void UpdatePositionValues()
Updates xpos, ypos, and zpos with the current device position.
Definition: XYZControl.cpp:45
void Set(const bool &_a=true)
Definition: helpers.h:108
virtual void Initialize(parameters::XYZControl &_params)
Initialize hardware.
Definition: XYZControl.cpp:16
virtual void StopPolling()
Stop the worker function.
Definition: XYZControl.cpp:39
std::array< ScopeNumber< double > *, 3 > xyzpos
pointers to a ScopeNumber that is updated with the polled x, y, and z positions
Definition: XYZControl.h:27
virtual void StartPolling()
Start the worker function in the pollthread.
Definition: XYZControl.cpp:29
bool IsSet() const
Definition: helpers.h:105