Scope
Devices.cpp
1 #include "stdafx.h"
2 #include "Devices.h"
3 #include "Scope.h"
4 
5 namespace scope {
6 
7 namespace parameters {
8 
9 // Save some typing here...
10 using namespace boost::property_tree;
11 
12 XYZControl::XYZControl()
13  : xpos(0, -10000, 10000, L"XPosition_um")
14  , ypos(0, -10000, 10000, L"YPosition_um")
15  , zpos(0, -10000, 10000, L"ZPosition_um")
16  , pollinterval(1000, 0, 10000, L"PollInterval_ms") {
17 }
18 
19 void XYZControl::Load(const wptree& pt) {
24 }
25 
26 void XYZControl::Save(wptree& pt) const {
31 }
32 
33 XYZControlGalil::XYZControlGalil()
34  : comstring(L"COM7 19200", L"RS232Connection")
35  , xcountspermicron(2, 1.0, 100, L"XEncoderCountsPerMicrometer")
36  , ycountspermicron(2, 1.0, 100.0, L"YEncoderCountsPerMicrometer")
37  , zcountspermicron(4, 1.0, 100.0, L"ZEncoderCountsPerMicrometer"){
38 }
39 
40 void XYZControlGalil::Load(const wptree& pt) {
41  XYZControl::Load(pt);
46 }
47 
48 void XYZControlGalil::Save(wptree& pt) const {
49  XYZControl::Save(pt);
54 }
55 
56 XYZControlSutter::XYZControlSutter()
57  : comstring(L"COM10", L"RS232COMPORT")
58  , microstepspermicron(1.0, 1.0, 2000.0, L"MicrostepsPerMicrometer") {
59 }
60 
61 void XYZControlSutter::Load(const wptree& pt) {
62  XYZControl::Load(pt);
65 }
66 
67 void XYZControlSutter::Save(wptree& pt) const {
68  XYZControl::Save(pt);
71 }
72 
73 FastZControl::FastZControl()
74  : minoutput(0, -10, 10, L"MinOutput_V")
75  , maxoutput(4, -10, 10, L"MaxOutput_V")
76  , calibrationfile(L"None", L"CalibrationFile") {
77  calibration.emplace(std::pair<double, double>(0.0, 0.0));
78 }
79 
80 bool FastZControl::LoadCalibration(const std::wstring& _filepath) {
81  std::ifstream file(_filepath);
82  if ( !file.good() ) {
83  DBOUT(L"FastZControl::LoadCalibration file is not good, load aborted");
84  return false;
85  }
86  calibration.clear();
87  double key = 0.0;
88  double value = 0.0;
89  while ( file.good() ) {
90  file >> key >> value;
91  calibration.emplace(std::pair<double, double>(key, value));
92  }
93  calibrationfile = _filepath;
94  DBOUT(L"FastZControl::LoadCalibration loaded file " << _filepath);
95  return true;
96 }
97 
98 double FastZControl::PositionToVoltage(const double& _positionum) {
99  double zvolt = 0;
100  auto hit = calibration.find(_positionum);
101  if ( hit != calibration.end() ) {
102  zvolt = hit->second;
103  return zvolt;
104  }
105  auto lower = calibration.upper_bound(_positionum); // upper_bound returns element with key that is greater than _position
106  if ( lower == calibration.begin() ) { // if we are to low we use the lowest value in calibration
107  zvolt = lower->second;
108  return zvolt;
109  }
110  if ( lower == calibration.end() ) // be careful when no calibration is loaded or we are at the end
111  lower--;
112  auto upper = lower == (calibration.begin())?lower:lower--;
113 
114  // do linear interpolation
115  double divider = (upper->first - lower->first);
116  divider = (divider==0)?1:divider; // avoid division by zero
117  zvolt = ((upper->second - lower->second) / divider ) * (_positionum - lower->first) + lower->second;
118  DBOUT(L"New ETL voltage: " << zvolt);
119  return zvolt;
120 }
121 
122 void FastZControl::Load(const wptree& pt) {
126  if ( (calibrationfile() != L"") && (calibrationfile() != L"None") )
128 }
129 
130 void FastZControl::Save(wptree& pt) const {
134 }
135 
136 
137 FastZControlETL::FastZControlETL() {
138 }
139 
140 void FastZControlETL::Load(const wptree& pt) {
141  FastZControl::Load(pt);
142 }
143 
144 void FastZControlETL::Save(wptree& pt) const {
145  FastZControl::Save(pt);
146 }
147 
148 XYControl::XYControl()
149  : xpos(0, -100000, 100000, L"XPosition_um")
150  , ypos(0, -100000, 100000, L"YPosition_um")
151  , pollinterval(1000, 0, 10000, L"PollInterval_ms")
152  , buttonstepsize(10, 0, 1000, L"StepSizeForButtons_um")
153  , stageinfo(L"", L"StageInformation") {
154 }
155 
156 void XYControl::Load(const wptree& pt) {
161 }
162 
163 void XYControl::Save(wptree& pt) const {
168 }
169 
170 XYControlGalil::XYControlGalil()
171  : comstring(L"COM5 19200", L"RS232Connection")
172  , countspermicron(1024.0, 1.0, 10000.0, L"EncoderCountsPerMicrometer") {
173 }
174 
175 void XYControlGalil::Load(const wptree& pt) {
176  XYControl::Load(pt);
178 }
179 
180 void XYControlGalil::Save(wptree& pt) const {
181  XYControl::Save(pt);
183 }
184 
185 XYControlStanda::XYControlStanda()
186  : devicex(0, 0, 10, L"DeviceNumberX")
187  , devicey(1, 0, 10, L"DeviceNumberY")
188  , speed(10, 0, 500, L"MovementSpeed_stepspersec")
189  , microstepspermicron(3.226, 0.1, 100.0, L"MicrostepsPerMicrometer") {
190 }
191 
192 void XYControlStanda::Load(const wptree& pt) {
193  XYControl::Load(pt);
198 }
199 
200 void XYControlStanda::Save(wptree& pt) const {
201  XYControl::Save(pt);
206 }
207 
208 }
209 
210 }
ScopeNumber< double > minoutput
Minimum output voltage to fast z, for ETL usually 0V.
Definition: Devices.h:97
void Save(wptree &pt) const override
save parameters into a boost:property_tree
Definition: Devices.cpp:67
ScopeNumber< double > zpos
position in micron of z axis
Definition: Devices.h:31
void Load(const wptree &pt) override
load parameters from a boost::property_tree
Definition: Devices.cpp:175
void Load(const wptree &pt) override
load parameters from a boost::property_tree
Definition: Devices.cpp:140
ScopeNumber< uint32_t > devicey
Standa device number for y axis.
Definition: Devices.h:188
virtual bool LoadCalibration(const std::wstring &_filepath)
Loads calibration data from a file, overwrites old calibration map.
Definition: Devices.cpp:80
void AddToPropertyTree(boost::property_tree::wptree &pt) const
Adds the value to a Boost property tree, using its name and value.
Definition: ScopeValue.h:103
ScopeNumber< double > speed
movement speed in steps/sec
Definition: Devices.h:191
void Load(const wptree &pt) override
load parameters from a boost::property_tree
Definition: Devices.cpp:40
void Load(const wptree &pt) override
load parameters from a boost::property_tree
Definition: Devices.cpp:61
ScopeNumber< double > ypos
position in micron of y axis
Definition: Devices.h:28
void Save(wptree &pt) const override
save parameters into a boost:property_tree
Definition: Devices.cpp:163
void Save(wptree &pt) const override
save parameters into a boost:property_tree
Definition: Devices.cpp:26
ScopeNumber< double > xpos
position in micron of x axis
Definition: Devices.h:25
void Load(const wptree &pt) override
load parameters from a boost::property_tree
Definition: Devices.cpp:192
void Save(wptree &pt) const override
save parameters into a boost:property_tree
Definition: Devices.cpp:48
ScopeNumber< double > xcountspermicron
conversion factor between encoder counts and micrometers for x axis
Definition: Devices.h:52
ScopeNumber< double > pollinterval
interval in milliseconds to poll device, be careful: long intervals slow quitting of Scope (since to ...
Definition: Devices.h:34
ScopeString calibrationfile
calibration file name
Definition: Devices.h:103
ScopeNumber< double > zcountspermicron
conversion factor between encoder counts and micrometers for z axis
Definition: Devices.h:58
This is the include file for standard system include files, or project specific include files that ar...
void Load(const wptree &pt) override
load parameters from a boost::property_tree
Definition: Devices.cpp:156
void Save(wptree &pt) const override
save parameters into a boost:property_tree
Definition: Devices.cpp:180
void Load(const wptree &pt) override
load parameters from a boost::property_tree
Definition: Devices.cpp:19
virtual double PositionToVoltage(const double &_positionum)
Converts a position in micron to voltage.
Definition: Devices.cpp:98
#define DBOUT(s)
A debug output to the debug console.
Definition: helpers.h:153
void Save(wptree &pt) const override
save parameters into a boost:property_tree
Definition: Devices.cpp:200
ScopeNumber< uint32_t > devicex
Standa device number for x axis.
Definition: Devices.h:185
ScopeNumber< double > buttonstepsize
size of the step for up/down/left/right buttons
Definition: Devices.h:149
ScopeNumber< double > ycountspermicron
conversion factor between encoder counts and micrometers for y axis
Definition: Devices.h:55
ScopeString comstring
connection string for Galil controller
Definition: Devices.h:167
ScopeString comstring
connection string for Galil controller
Definition: Devices.h:49
ScopeNumber< double > xpos
x position of xy device
Definition: Devices.h:140
ScopeNumber< double > pollinterval
interval in milliseconds to poll device, be careful: long intervals slow quitting of Scope (since to ...
Definition: Devices.h:146
void Load(const wptree &pt) override
load parameters from a boost::property_tree
Definition: Devices.cpp:122
void SetFromPropertyTree(const boost::property_tree::wptree &pt)
Set value from a Boost property, using its name as a key.
Definition: ScopeValue.h:108
std::map< double, double > calibration
calibration map, key is absolute position in microns, value is corresponding output voltage ...
Definition: Devices.h:94
ScopeString comstring
connection string for Sutter controller
Definition: Devices.h:73
ScopeNumber< double > ypos
y position of xy device
Definition: Devices.h:143
ScopeNumber< double > microstepspermicron
number of microsteps (1/8 full step) per micrometer, 3.226 microsteps per micrometer from Standa 8MTF...
Definition: Devices.h:194
ScopeNumber< double > microstepspermicron
conversion factor between encoder counts (microsteps) and micrometers for x axis usually 0...
Definition: Devices.h:77
void Save(wptree &pt) const override
save parameters into a boost:property_tree
Definition: Devices.cpp:130
void Save(wptree &pt) const override
save parameters into a boost:property_tree
Definition: Devices.cpp:144
ScopeNumber< double > maxoutput
Maximum output voltage to fast z, for ETL usually 4V.
Definition: Devices.h:100