2 #include "XYZControlSutter.h"
3 #include "controllers/ScopeLogger.h"
5 #ifdef SCOPE_USE_SUTTER_XYZSTAGE
9 XYZControlSutter::XYZControlSutter(
void)
11 , microstepspermicron(5) {
14 XYZControlSutter::~XYZControlSutter(
void) {
18 void XYZControlSutter::Initialize(parameters::XYZControlSutter& _params) {
19 microstepspermicron = _params.microstepspermicron();
22 sc = std::unique_ptr<SutterController>(
new SutterController(_params.comstring()));
24 ScopeLogger scope_logger;
25 scope_logger.Log(L
"Connected XYControlSutter to Sutter controller", log_info);
33 UpdatePositionValues();
35 scope_logger.Log( L
"Initialized XYZControlSutter", log_info);
44 uint16_t XYZControlSutter::BytesToInt16(
const std::vector<BYTE>& _bytevec,
const uint32_t& _from) {
45 if ( _bytevec.size() < (_from+2) )
50 b.charval[0] = _bytevec[_from];
51 b.charval[1] = _bytevec[_from+1];
55 std::vector<BYTE> XYZControlSutter::Int16ToBytes(
const uint16_t& _i) {
58 std::vector<BYTE> bytevec(2,0);
59 bytevec[0] = b.charval[0];
60 bytevec[1] = b.charval[1];
64 uint32_t XYZControlSutter::BytesToInt32(
const std::vector<BYTE>& _bytevec,
const uint32_t& _from) {
65 if ( _bytevec.size() < (_from+4) )
70 b.charval[0] = _bytevec[_from];
71 b.charval[1] = _bytevec[_from+1];
72 b.charval[2] = _bytevec[_from+2];
73 b.charval[3] = _bytevec[_from+3];
77 std::vector<BYTE> XYZControlSutter::Int32ToBytes(
const uint32_t& _i) {
80 std::vector<BYTE> bytevec(4,0);
81 bytevec[0] = b.charval[0];
82 bytevec[1] = b.charval[1];
83 bytevec[2] = b.charval[2];
84 bytevec[3] = b.charval[3];
88 void XYZControlSutter::UpdateStatus() {
89 std::vector<BYTE> ret = sc->Command(
"s\r", 33);
91 stepdiv = BytesToInt16(ret, 24);
92 stepmult = BytesToInt16(ret, 26);
93 speed = BytesToInt16(ret, 28);
94 version = BytesToInt16(ret, 30);
97 void XYZControlSutter::SetVelocity(
const uint16_t& _vel) {
102 uint16_t devvel(_vel);
103 const bool highres = (speed > 32786);
106 if ( highres && (devvel > 1310) )
108 if ( !highres && (devvel > 3000) )
115 std::string cmd =
"V";
116 cmd.append(reinterpret_cast<char*>(Int16ToBytes(devvel).data()));
119 std::vector<BYTE> ret = sc->Command(cmd, 1);
124 void XYZControlSutter::UpdatePositionValues() {
126 std::vector<BYTE> ret = sc->Command(
"c\r", 13);
128 uint32_t x = BytesToInt32(ret, 0);
129 uint32_t y = BytesToInt32(ret, 4);
130 uint32_t z = BytesToInt32(ret, 8);
132 xyzpos[0]->Set(static_cast<double>(x) / microstepspermicron);
133 xyzpos[1]->Set(static_cast<double>(y) / microstepspermicron);
134 xyzpos[2]->Set(static_cast<double>(z) / microstepspermicron);
139 void XYZControlSutter::SetZero() {
141 sc->Command(
"o\r", 1);
146 void XYZControlSutter::MoveRelative(
const double& _xrel,
const double& _yrel,
const double& _zrel) {
149 std::vector<BYTE> ret = sc->Command(
"c\r", 13);
151 double xum = BytesToInt32(ret, 0) / microstepspermicron;
152 double yum= BytesToInt32(ret, 4) / microstepspermicron;
153 double zum = BytesToInt32(ret, 8) / microstepspermicron;
155 std::string cmd(
"m");
156 cmd.append(reinterpret_cast<char*>(Int32ToBytes(round2ui32((xum+_xrel)*microstepspermicron)).data()));
157 cmd.append(reinterpret_cast<char*>(Int32ToBytes(round2ui32((yum+_yrel)*microstepspermicron)).data()));
158 cmd.append(reinterpret_cast<char*>(Int32ToBytes(round2ui32((zum+_zrel)*microstepspermicron)).data()));
161 ret = sc->Command(cmd, 1);
165 UpdatePositionValues();
168 void XYZControlSutter::MoveAbsolute(
const double& _xabs,
const double& _yabs,
const double& _zabs) {
170 std::string cmd(
"m");
171 cmd.append(reinterpret_cast<char*>(Int32ToBytes(round2ui32(_xabs*microstepspermicron)).data()));
172 cmd.append(reinterpret_cast<char*>(Int32ToBytes(round2ui32(_yabs*microstepspermicron)).data()));
173 cmd.append(reinterpret_cast<char*>(Int32ToBytes(round2ui32(_zabs*microstepspermicron)).data()));
176 std::vector<BYTE> ret = sc->Command(cmd, 1);
180 UpdatePositionValues();
This is the include file for standard system include files, or project specific include files that ar...
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.
virtual void Initialize(parameters::XYZControl &_params)
Initialize hardware.