15 #include "usermotor.h"
18 REGISTER_TYPE(
XDriverList, FlexCRK,
"OrientalMotor FLEX CRK motor controller");
19 REGISTER_TYPE(
XDriverList, FlexAR,
"OrientalMotor FLEX AR/DG2 motor controller");
20 REGISTER_TYPE(
XDriverList, EMP401,
"OrientalMotor EMP401 motor controller");
22 XFlexCRK::XFlexCRK(
const char *name,
bool runtime,
23 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas) :
25 interface()->setSerialBaudRate(57600);
26 interface()->setSerialStopBits(1);
27 interface()->setSerialParity(XCharInterface::PARITY_EVEN);
32 interface()->presetSingleResistor(0x45, 1);
33 interface()->presetSingleResistor(0x45, 0);
36 XFlexCRK::clearPosition() {
38 interface()->presetSingleResistor(0x4b, 1);
39 interface()->presetSingleResistor(0x4b, 0);
42 XFlexCRK::getStatus(
const Snapshot &shot,
double *position,
bool *slipping,
bool *ready) {
44 uint32_t output = interface()->readHoldingTwoResistors(0x20);
45 *slipping = output & 0x2000000u;
47 uint16_t alarm = interface()->readHoldingSingleResistor(0x100);
48 gErrPrint(
getLabel() + i18n(
" Alarm %1 has been emitted").arg((
int)alarm));
49 interface()->presetSingleResistor(0x40, 1);
50 interface()->presetSingleResistor(0x40, 0);
53 uint16_t warn = interface()->readHoldingSingleResistor(0x10b);
54 gWarnPrint(
getLabel() + i18n(
" Code = %1").arg((
int)warn));
60 *ready = (output & 0x20000000u);
62 if(shot[ *hasEncoder()])
63 *position = static_cast<int32_t>(interface()->readHoldingTwoResistors(0x11e))
66 *position =
static_cast<int32_t
>(interface()->readHoldingTwoResistors(0x118))
70 XFlexCRK::changeConditions(
const Snapshot &shot) {
72 interface()->presetSingleResistor(0x21e, lrint(shot[ *
currentRunning()]));
73 interface()->presetSingleResistor(0x21f, lrint(shot[ *
currentStopping()]));
74 interface()->presetSingleResistor(0x236, 0);
75 interface()->presetTwoResistors(0x224, lrint(shot[ *
timeAcc()] * 1e3));
76 interface()->presetTwoResistors(0x226, lrint(shot[ *
timeDec()] * 1e3));
77 interface()->presetTwoResistors(0x312, lrint((
double)shot[ *
stepEncoder()]));
78 interface()->presetTwoResistors(0x314, lrint((
double)shot[ *
stepMotor()]));
79 interface()->presetTwoResistors(0x502, lrint(shot[ *
speed()]));
80 unsigned int microstep = shot[ *microStep()] ? 6 : 0;
81 if(interface()->readHoldingSingleResistor(0x311) != microstep) {
82 gWarnPrint(i18n(
"Store settings to NV memory and restart, microstep div.=10."));
83 interface()->presetSingleResistor(0x311, microstep);
89 interface()->diagnostics();
90 tr[ *
currentRunning()] = interface()->readHoldingSingleResistor(0x21e);
91 tr[ *
currentStopping()] = interface()->readHoldingSingleResistor(0x21f);
92 tr[ *microStep()] = (interface()->readHoldingSingleResistor(0x311) != 0);
93 tr[ *
timeAcc()] = interface()->readHoldingTwoResistors(0x224) * 1e-3;
94 tr[ *
timeDec()] = interface()->readHoldingTwoResistors(0x226) * 1e-3;
95 tr[ *
stepEncoder()] = interface()->readHoldingTwoResistors(0x312);
96 tr[ *
stepMotor()] = interface()->readHoldingTwoResistors(0x314);
97 tr[ *
speed()] = interface()->readHoldingTwoResistors(0x502);
98 tr[ *
target()] =
static_cast<int32_t
>(interface()->readHoldingTwoResistors(0x402))
100 tr[ *round()].setUIEnabled(
false);
101 tr[ *roundBy()].setUIEnabled(
false);
102 tr[ *active()] = (interface()->readHoldingSingleResistor(0x1e) & 0x2000u) == 1;
103 interface()->presetSingleResistor(0x203, 0);
104 interface()->presetSingleResistor(0x200, 0);
105 interface()->presetSingleResistor(0x20b, 0);
106 interface()->presetSingleResistor(0x20c, 0);
107 interface()->presetSingleResistor(0x20d, 0);
108 interface()->presetSingleResistor(0x202, 1);
109 interface()->presetSingleResistor(0x601, 1);
113 sendStopSignal(
false);
116 XFlexCRK::sendStopSignal(
bool wait) {
117 for(
int i = 0;; ++i) {
118 uint32_t output = interface()->readHoldingTwoResistors(0x20);
119 bool isready = (output & 0x20000000u);
122 interface()->presetSingleResistor(0x1e, 0x3001u);
123 interface()->presetSingleResistor(0x1e, 0x2001u);
136 interface()->presetSingleResistor(0x1e, 0x2201u);
141 interface()->presetSingleResistor(0x1e, 0x2401u);
144 XFlexCRK::setTarget(
const Snapshot &shot,
double target) {
146 sendStopSignal(
true);
147 interface()->presetTwoResistors(0x402, lrint(target / 360.0 * shot[ *
stepMotor()]));
148 interface()->presetSingleResistor(0x1e, 0x2101u);
149 interface()->presetSingleResistor(0x1e, 0x2001u);
152 XFlexCRK::setActive(
bool active) {
155 interface()->presetSingleResistor(0x1e, 0x2001u);
158 sendStopSignal(
true);
159 interface()->presetSingleResistor(0x1e, 0x0001u);
163 XFlexCRK::setAUXBits(
unsigned int bits) {
164 interface()->presetSingleResistor(0x206, 11);
165 interface()->presetSingleResistor(0x207, 12);
166 interface()->presetSingleResistor(0x208, 15);
167 interface()->presetSingleResistor(0x209, 16);
168 interface()->presetSingleResistor(0x1f, bits & 0xfu);
174 interface()->presetTwoResistors(0x192, 1);
175 interface()->presetTwoResistors(0x192, 0);
178 XFlexAR::clearPosition() {
180 interface()->presetTwoResistors(0x18a, 1);
181 interface()->presetTwoResistors(0x18a, 0);
184 XFlexAR::getStatus(
const Snapshot &shot,
double *position,
bool *slipping,
bool *ready) {
186 uint32_t output = interface()->readHoldingTwoResistors(0x7e);
187 *ready = output & 0x20;
188 *slipping = output & 0x8000;
190 uint32_t alarm = interface()->readHoldingTwoResistors(0x80);
191 gErrPrint(
getLabel() + i18n(
" Alarm %1 has been emitted").arg((
int)alarm));
192 interface()->presetTwoResistors(0x180, 1);
193 interface()->presetTwoResistors(0x180, 0);
194 interface()->presetTwoResistors(0x182, 1);
195 interface()->presetTwoResistors(0x182, 0);
196 interface()->presetTwoResistors(0x184, 1);
197 interface()->presetTwoResistors(0x184, 0);
200 uint32_t warn = interface()->readHoldingTwoResistors(0x96);
201 gWarnPrint(
getLabel() + i18n(
" Code = %1").arg((
int)warn));
203 if(shot[ *hasEncoder()])
204 *position =
static_cast<int32_t
>(interface()->readHoldingTwoResistors(0xcc))
207 *position =
static_cast<int32_t
>(interface()->readHoldingTwoResistors(0xc6))
211 XFlexAR::changeConditions(
const Snapshot &shot) {
213 interface()->presetTwoResistors(0x240, lrint(shot[ *
currentRunning()] * 10.0));
214 interface()->presetTwoResistors(0x242, lrint(shot[ *
currentStopping()] * 10.0));
215 interface()->presetTwoResistors(0x28c, 0);
216 interface()->presetTwoResistors(0x280, lrint(shot[ *
timeAcc()] * 1e3));
217 interface()->presetTwoResistors(0x282, lrint(shot[ *
timeDec()] * 1e3));
218 interface()->presetTwoResistors(0x284, 0);
219 interface()->presetTwoResistors(0x480, lrint(shot[ *
speed()]));
221 bool conf_needed =
false;
222 if(shot[ *
stepMotor()] != interface()->readHoldingTwoResistors(0x380) * 1000.0 / interface()->readHoldingTwoResistors(0x382)) {
228 int a = lrint(shot[ *
stepMotor()]/1000.0*b);
229 interface()->presetTwoResistors(0x380, a);
230 interface()->presetTwoResistors(0x382, b);
233 int b_micro = shot[ *microStep()] ? 1 : 0;
234 if(interface()->readHoldingTwoResistors(0x1028) != b_micro) {
236 interface()->presetTwoResistors(0x1028, b_micro);
238 int b_round = shot[ *round()] ? 1 : 0;
239 if(interface()->readHoldingTwoResistors(0x38e) != b_round) {
241 interface()->presetTwoResistors(0x38e, b_round);
243 int num_round = std::max(lrint((
double)shot[ *roundBy()]), 1L);
244 if(interface()->readHoldingTwoResistors(0x390) != num_round) {
246 interface()->presetTwoResistors(0x390, num_round);
247 interface()->presetTwoResistors(0x20a, lrint((
double)shot[ *roundBy()]) / 2);
248 interface()->presetTwoResistors(0x20c, 0);
252 sendStopSignal(
true);
253 interface()->presetTwoResistors(0x18c, 1);
254 interface()->presetTwoResistors(0x18c, 0);
260 interface()->diagnostics();
261 tr[ *
currentRunning()] = interface()->readHoldingTwoResistors(0x240) * 0.1;
262 tr[ *
currentStopping()] = interface()->readHoldingTwoResistors(0x242) * 0.1;
263 tr[ *microStep()] = (interface()->readHoldingTwoResistors(0x1028) != 0);
264 tr[ *
timeAcc()] = interface()->readHoldingTwoResistors(0x280) * 1e-3;
265 tr[ *
timeDec()] = interface()->readHoldingTwoResistors(0x282) * 1e-3;
266 tr[ *
stepMotor()] = interface()->readHoldingTwoResistors(0x380) * 1000.0 / interface()->readHoldingTwoResistors(0x382);
268 tr[ *hasEncoder()] =
true;
269 tr[ *
speed()] = interface()->readHoldingTwoResistors(0x480);
270 tr[ *
target()] =
static_cast<int32_t
>(interface()->readHoldingTwoResistors(0x400))
272 tr[ *round()] = (interface()->readHoldingTwoResistors(0x38e) == 1);
273 tr[ *roundBy()] = interface()->readHoldingTwoResistors(0x390);
274 tr[ *active()] = (interface()->readHoldingTwoResistors(0x7c) & 0x40u) == 0;
276 interface()->presetTwoResistors(0x200, 3);
277 interface()->presetTwoResistors(0x500, 1);
278 interface()->presetTwoResistors(0x119e, 71);
279 interface()->presetTwoResistors(0x1140, 32);
280 interface()->presetTwoResistors(0x1142, 33);
282 interface()->presetTwoResistors(0x1146, 35);
283 interface()->presetTwoResistors(0x1148, 36);
284 interface()->presetTwoResistors(0x114a, 37);
285 interface()->presetTwoResistors(0x1160, 32);
286 interface()->presetTwoResistors(0x1162, 33);
288 interface()->presetTwoResistors(0x1166, 35);
289 interface()->presetTwoResistors(0x1168, 36);
290 interface()->presetTwoResistors(0x116a, 37);
293 XFlexAR::setTarget(
const Snapshot &shot,
double target) {
295 sendStopSignal(
true);
297 interface()->presetTwoResistors(0x400, lrint(target / 360.0 * steps));
298 interface()->presetTwoResistors(0x7c, 0x100u);
299 interface()->presetTwoResistors(0x7c, 0x0u);
303 sendStopSignal(
false);
306 XFlexAR::sendStopSignal(
bool wait) {
307 for(
int i = 0;; ++i) {
308 uint32_t output = interface()->readHoldingTwoResistors(0x7e);
309 bool isready = output & 0x20;
312 interface()->presetTwoResistors(0x7c, 0x20u);
313 interface()->presetTwoResistors(0x7c, 0x0u);
326 interface()->presetTwoResistors(0x7c, 0x4000u);
331 interface()->presetTwoResistors(0x7c, 0x8000u);
334 XFlexAR::setActive(
bool active) {
337 interface()->presetTwoResistors(0x7c, 0x0u);
340 sendStopSignal(
true);
341 interface()->presetTwoResistors(0x7c, 0x40u);
345 XFlexAR::setAUXBits(
unsigned int bits) {
346 interface()->presetSingleResistor(0x7d, bits & 0x3fu);
349 XEMP401::XEMP401(
const char *name,
bool runtime,
350 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas) :
352 interface()->setSerialBaudRate(9600);
354 interface()->setSerialParity(XCharInterface::PARITY_NONE);
355 interface()->setSerialHasEchoBack(
true);
356 interface()->setEOS(
"\r\n");
358 hasEncoder()->disable();
361 roundBy()->disable();
370 XEMP401::clearPosition() {
372 interface()->send(
"RTNCR");
376 XEMP401::waitForCursor() {
378 interface()->receive(1);
379 if(interface()->buffer()[0] ==
'>')
385 XEMP401::getStatus(
const Snapshot &shot,
double *position,
bool *slipping,
bool *ready) {
387 interface()->send(
"R");
389 interface()->receive();
391 if(interface()->scanf(
" PC =%d", &x) == 1) {
395 if(interface()->scanf(
" Ready =%d", &x) == 1) {
403 XEMP401::changeConditions(
const Snapshot &shot) {
405 interface()->queryf(
"T,%d", (
int)lrint(shot[ *
timeAcc()] * 10));
407 if(shot[ *microStep()])
410 interface()->queryf(
"UNIT,%.4f,%.1f", 1.0 / shot[ *
stepMotor()], n2);
412 interface()->queryf(
"V,%d", (
int)lrint(shot[ *
speed()]));
414 interface()->queryf(
"VS,%d", (
int)lrint(shot[ *
speed()]));
420 interface()->query(
"T");
422 if(interface()->scanf(
"%*d: T = %d", &x) != 1)
427 interface()->query(
"V");
428 if(interface()->scanf(
"%*d: V = %d", &x) != 1)
433 interface()->query(
"UNIT");
435 if(interface()->scanf(
"%*d: UNIT = %lf,%lf", &n1, &n2) != 2)
437 tr[ *microStep()] = (n2 > 1.1);
444 interface()->setSerialHasEchoBack(
false);
445 interface()->write(
"\x1b", 1);
446 interface()->setSerialHasEchoBack(
true);
448 interface()->send(
"S");
450 interface()->query(
"ACTL 0,0,0,0");
457 interface()->query(
"H,+");
459 interface()->send(
"SCAN");
466 interface()->query(
"H,-");
468 interface()->send(
"SCAN");
472 XEMP401::setTarget(
const Snapshot &shot,
double target) {
475 interface()->queryf(
"D,%+.2f", target);
477 interface()->send(
"ABS");
481 XEMP401::setActive(
bool active) {
490 XEMP401::setAUXBits(
unsigned int bits) {
491 interface()->queryf(
"OUT,%1u%1u%1u%1u%1u%1u",
492 (bits / 32u) % 2u, (bits / 16u) % 2u, (bits / 8u) % 2u, (bits / 4u) % 2u, (bits / 2u) % 2u, bits % 2u);