13 #include "../../libMagAOX/libMagAOX.hpp"
27 template<
class parentT>
116 int name(
const std::string & n );
234 const std::string & repBuff
252 const std::string & command
307 template<
class parentT>
313 template<
class parentT>
320 template<
class parentT>
326 template<
class parentT>
333 template<
class parentT>
336 return m_deviceAddress;
339 template<
class parentT>
342 m_deviceAddress = da;
346 template<
class parentT>
352 template<
class parentT>
359 template<
class parentT>
362 return m_commandStatus;
365 template<
class parentT>
368 return m_deviceStatus;
371 template<
class parentT>
377 template<
class parentT>
383 template<
class parentT>
389 template<
class parentT>
395 template<
class parentT>
401 template<
class parentT>
407 template<
class parentT>
413 template<
class parentT>
419 template<
class parentT>
425 template<
class parentT>
431 template<
class parentT>
437 template<
class parentT>
443 template<
class parentT>
449 template<
class parentT>
455 template<
class parentT>
461 template<
class parentT>
467 template<
class parentT>
473 template<
class parentT>
479 template<
class parentT>
485 template<
class parentT>
491 template<
class parentT>
497 template<
class parentT>
503 template<
class parentT>
509 template<
class parentT>
515 template<
class parentT>
521 template<
class parentT>
527 template<
class parentT>
529 const std::string & repBuff
533 int rv =
za_decode(&rep, repBuff.c_str());
538 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return rv;
541 MagAOXAppT::log<software_error>({__FILE__, __LINE__, rv,
"za_decode !=Z_SUCCESS"});
545 return getResponse(response, rep);
548 template<
class parentT>
555 if(rep.
reply_flags[0] ==
'O') m_commandStatus =
true;
556 else m_commandStatus =
false;
561 if(m_deviceStatus ==
'I' && m_homing)
576 MagAOXAppT::log<software_error>({__FILE__, __LINE__, 0,
"wrong device"});
581 template<
class parentT>
584 const std::string & command
589 za_send(port, command.c_str());
595 int rv =
za_receive(port, buff,
sizeof(buff));
600 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return rv;
603 MagAOXAppT::log<software_error>({__FILE__, __LINE__, 0,
"Z_ERROR_TIMEOUT"});
610 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return rv;
613 MagAOXAppT::log<software_error>({__FILE__, __LINE__, 0,
"za_receive !=Z_SUCCESS"});
626 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return rv;
629 MagAOXAppT::log<software_error>({__FILE__, __LINE__, 0,
"za_decode !=Z_SUCCESS"});
633 if(rep.
device_address == m_deviceAddress)
return getResponse(response, rep);
641 template<
class parentT>
644 if(m_deviceAddress < 1)
646 return MagAOXAppT::log<
software_error, -1>({__FILE__, __LINE__,
"stage " + m_name +
" with with s/n " + m_serial +
" not found in system."});
649 std::string com =
"/" + mx::ioutils::convertToString(m_deviceAddress) +
" ";
650 com +=
"get limit.max";
652 std::string response;
654 int rv = sendCommand(response, port, com);
658 if( m_commandStatus )
660 m_maxPos = mx::ioutils::convertFromString<long>(response);
667 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
670 MagAOXAppT::log<software_error>({__FILE__, __LINE__, rv,
"get limit.max Command Rejected"});
676 MagAOXAppT::log<software_error>({__FILE__, __LINE__});
679 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
686 template<
class parentT>
689 if(m_deviceAddress < 1)
691 return MagAOXAppT::log<
software_error, -1>({__FILE__, __LINE__,
"stage " + m_name +
" with with s/n " + m_serial +
" not found in system."});
694 std::string com =
"/" + mx::ioutils::convertToString(m_deviceAddress) +
" ";
697 std::string response;
699 int rv = sendCommand(response, port, com);
703 if( m_commandStatus )
705 m_rawPos = mx::ioutils::convertFromString<long>(response);
712 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
715 MagAOXAppT::log<software_error>({__FILE__, __LINE__, rv,
"get pos Command Rejected"});
723 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
726 MagAOXAppT::log<software_error>({__FILE__, __LINE__});
731 template<
class parentT>
734 if(m_deviceAddress < 1)
736 return MagAOXAppT::log<
software_error, -1>({__FILE__, __LINE__,
"stage " + m_name +
" with with s/n " + m_serial +
" not found in system."});
739 std::string com =
"/" + mx::ioutils::convertToString(m_deviceAddress) +
" ";
740 com +=
"get driver.temperature";
742 std::string response;
744 int rv = sendCommand(response, port, com);
748 if( m_commandStatus )
750 m_temp = mx::ioutils::convertFromString<float>(response);
757 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
760 MagAOXAppT::log<software_error>({__FILE__, __LINE__, rv,
"get driver.temperature Command Rejected"});
768 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
771 MagAOXAppT::log<software_error>({__FILE__, __LINE__});
776 template<
class parentT>
779 if(m_deviceAddress < 1)
781 return MagAOXAppT::log<
software_error, -1>({__FILE__, __LINE__,
"stage " + m_name +
" with with s/n " + m_serial +
" not found in system."});
784 std::string com =
"/" + mx::ioutils::convertToString(m_deviceAddress) +
" ";
787 std::string response;
789 int rv = sendCommand(response, port, com);
793 if( m_commandStatus )
801 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
804 MagAOXAppT::log<software_error>({__FILE__, __LINE__, rv, m_name +
" stop Command Rejected"});
812 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
815 MagAOXAppT::log<software_error>({__FILE__, __LINE__});
820 template<
class parentT>
823 if(m_deviceAddress < 1)
825 return MagAOXAppT::log<
software_error, -1>({__FILE__, __LINE__,
"stage " + m_name +
" with with s/n " + m_serial +
" not found in system."});
828 std::string com =
"/" + mx::ioutils::convertToString(m_deviceAddress) +
" ";
831 std::string response;
833 int rv = sendCommand(response, port, com);
837 if( m_commandStatus )
845 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
848 MagAOXAppT::log<software_error>({__FILE__, __LINE__, rv, m_name +
" estop Command Rejected"});
856 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
859 MagAOXAppT::log<software_error>({__FILE__, __LINE__});
864 template<
class parentT>
867 if(m_deviceAddress < 1)
869 return MagAOXAppT::log<
software_error, -1>({__FILE__, __LINE__,
"stage " + m_name +
" with with s/n " + m_serial +
" not found in system."});
872 std::string com =
"/" + mx::ioutils::convertToString(m_deviceAddress) +
" ";
875 std::string response;
877 int rv = sendCommand(response, port, com);
881 if( m_commandStatus )
890 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
893 MagAOXAppT::log<software_error>({__FILE__, __LINE__, rv, m_name +
"Home Command Rejected"});
901 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
904 MagAOXAppT::log<software_error>({__FILE__, __LINE__});
909 template<
class parentT>
914 if(m_deviceAddress < 1)
916 return MagAOXAppT::log<
software_error, -1>({__FILE__, __LINE__,
"stage " + m_name +
" with with s/n " + m_serial +
" not found in system."});
919 std::string com =
"/" + mx::ioutils::convertToString(m_deviceAddress) +
" ";
920 com +=
"move abs " + std::to_string(rawPos);
924 std::string response;
926 int rv = sendCommand(response, port, com);
930 if( m_commandStatus )
938 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
941 MagAOXAppT::log<software_error>({__FILE__, __LINE__, rv, m_name +
"move abs Command Rejected"});
949 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
952 MagAOXAppT::log<software_error>({__FILE__, __LINE__});
957 template<
class parentT>
986 template<
class parentT>
991 MagAOXAppT::log<text_log>(m_name +
" Driver Disabled (FD): The driver has disabled itself due to overheating." ,
logPrio::LOG_EMERGENCY);
995 else if(warn ==
"FQ")
997 MagAOXAppT::log<text_log>(m_name +
" Encoder Error (FQ): The encoder-measured position may be unreliable. [home recommended]" ,
logPrio::LOG_WARNING);
1001 else if(warn ==
"FS")
1003 MagAOXAppT::log<text_log>(m_name +
" Stalled and Stopped (FS): Stalling was detected and the axis has stopped itself. " ,
logPrio::LOG_WARNING);
1007 else if(warn ==
"FT")
1009 MagAOXAppT::log<text_log>(m_name +
" Excessive Twist (FT): The lockstep group has exceeded allowable twist and has stopped. " ,
logPrio::LOG_WARNING);
1013 else if(warn ==
"FB")
1015 MagAOXAppT::log<text_log>(m_name +
" Stream Bounds Error (FB): A previous streamed motion could not be executed because it failed a precondition" ,
logPrio::LOG_WARNING);
1019 else if(warn ==
"FP")
1021 MagAOXAppT::log<text_log>(m_name +
" Interpolated Path Deviation (FP): Streamed or sinusoidal motion was terminated because an axis slipped and thus the device deviated from the requested path. " ,
logPrio::LOG_WARNING);
1025 else if(warn ==
"FE")
1027 MagAOXAppT::log<text_log>(m_name +
" Limit Error (FE): The target limit sensor cannot be reached or is faulty. " ,
logPrio::LOG_WARNING);
1031 else if(warn ==
"WH")
1033 if(m_warnWHreported ==
false)
1035 MagAOXAppT::log<text_log>(m_name +
" Device not homed (WH): The device has a position reference, but has not been homed." ,
logPrio::LOG_WARNING);
1036 m_warnWHreported =
true;
1041 else if(warn ==
"WL")
1043 MagAOXAppT::log<text_log>(m_name +
" Unexpected Limit Trigger warning (WL): A movement operation did not complete due to a triggered limit sensor." ,
logPrio::LOG_WARNING);
1047 else if(warn ==
"WP")
1049 MagAOXAppT::log<text_log>(m_name +
" Invalid calibration type (WP): The saved calibration data type is unsupported" ,
logPrio::LOG_WARNING);
1053 else if(warn ==
"WV")
1055 MagAOXAppT::log<text_log>(m_name +
" Voltage Out of Range (WV): The supply voltage is outside the recommended operating range of the device" ,
logPrio::LOG_WARNING);
1059 else if(warn ==
"WT")
1061 MagAOXAppT::log<text_log>(m_name +
" Controller Temperature High (WT): The internal temperature of the controller has exceeded the recommended limit for the device." ,
logPrio::LOG_WARNING);
1065 else if(warn ==
"WM")
1067 MagAOXAppT::log<text_log>(m_name +
" Displaced when Stationary (WM): While not in motion, the axis has been forced out of its position." ,
logPrio::LOG_WARNING);
1071 else if(warn ==
"WR")
1073 if(m_warnWRreported ==
false)
1076 m_warnWRreported =
true;
1081 else if(warn ==
"NC")
1083 MagAOXAppT::log<text_log>(m_name +
" Manual Control (NC): Axis is busy due to manual control via the knob." ,
logPrio::LOG_WARNING);
1087 else if(warn ==
"NI")
1091 if(m_homing ==
true || warnWR())
return 0;
1093 MagAOXAppT::log<text_log>(m_name +
" Command Interrupted (NI): A movement operation (command or manual control) was requested while the axis was executing another movement command." ,
logPrio::LOG_WARNING);
1097 else if(warn ==
"ND")
1099 MagAOXAppT::log<text_log>(m_name +
" Stream Discontinuity (ND): The device has slowed down while following a streamed motion path because it has run out of queued motions." ,
logPrio::LOG_WARNING);
1103 else if(warn ==
"NU")
1105 MagAOXAppT::log<text_log>(m_name +
" Setting Update Pending (NU): A setting is pending to be updated or a reset is pending." ,
logPrio::LOG_WARNING);
1109 else if(warn ==
"NJ")
1111 MagAOXAppT::log<text_log>(m_name +
" Joystick Calibrating (NJ): Joystick calibration is in progress." ,
logPrio::LOG_WARNING);
1118 MagAOXAppT::log<software_warning>({__FILE__, __LINE__, m_name +
" unknown stage warning: " + warn});
1125 template<
class parentT>
1128 size_t nwarn = std::stoi( response.substr(0, 2));
1130 if(nwarn > 0) m_warn =
true;
1132 for(
size_t n =0; n< nwarn; ++n)
1134 if(response.size() < 3 + n*3)
1138 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
1141 MagAOXAppT::log<software_error>({__FILE__, __LINE__,
"parsing incomplete warning response"});
1145 std::string warn = response.substr(3 + n*3, 2);
1147 int rv = processWarning(warn);
1152 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
1155 MagAOXAppT::log<software_error>({__FILE__, __LINE__});
1161 if(m_warnWHreported)
1163 if(!m_warnWH) m_warnWHreported =
false;
1166 if(m_warnWRreported)
1171 m_warnWRreported =
false;
1179 template<
class parentT>
1182 if(m_deviceAddress < 1)
1184 return MagAOXAppT::log<
software_error, -1>({__FILE__, __LINE__,
"stage " + m_name +
" with with s/n " + m_serial +
" not found in system."});
1187 std::string com =
"/" + mx::ioutils::convertToString(m_deviceAddress) +
" ";
1190 std::string response;
1192 int rv = sendCommand(response, port, com);
1196 if( m_commandStatus )
1199 return parseWarnings(response);
1206 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
1209 MagAOXAppT::log<software_error>({__FILE__, __LINE__, rv,
"warnings Command Rejected"});
1217 if(m_parent->powerState() != 1 || m_parent->powerStateTarget() != 1)
return -1;
1220 MagAOXAppT::log<software_error>({__FILE__, __LINE__});
1225 template<
class parentT>
1228 m_commandStatus =
true;
1230 m_deviceStatus =
'U';
1241 m_warnWRreported =
false;
static int log(const typename logT::messageT &msg, logPrioT level=logPrio::LOG_DEFAULT)
Make a log entry.
A class to manage the details of one stage in a Zaber system.
long m_maxPos
The max position allowed for the device, set by config. Will be set to no larger m_maxPosHW.
int getMaxPos(z_port port)
int serial(const std::string &s)
Set the device serial.
char deviceStatus()
Get the device status.
int axisNumber(const int &an)
Set the axis number.
int getWarnings(z_port port)
Get warnings from the device.
float m_temp
The driver temperature, in C.
long rawPos()
Get the current raw position, in counts.
int processWarning(std::string &warn)
Process a single warning from the device, setting the appropriate flag.
std::string name()
Get the device name.
bool m_commandStatus
The status of the last command sent. true = OK, false = RJ (rejected)
long maxPos()
Get the max position, in counts.
bool homing()
Get the homing status.
long tgtPos()
Get the current tgt position, in counts.
int sendCommand(std::string &response, z_port port, const std::string &command)
int m_axisNumber
The axis number at the address (normally 0 in MagAO-X)
int deviceAddress(const int &da)
Set the device address.
int onPowerOff()
Clear all state so that when the system is powered back on we get the correct new state.
int moveAbs(z_port port, long rawPos)
int axisNumber()
Get the axis number.
zaberStage(parentT *parent)
long m_rawPos
The raw position reported by the device, in microsteps.
int updatePos(z_port port)
int parseWarnings(std::string &response)
Parse the warning response from the device.
std::string serial()
Get the device serial number.
bool commandStatus()
Get the command status.
long m_tgtPos
The tgt position last sent to the device, in microsteps.
std::string m_serial
The stage's serial number.
int updateTemp(z_port port)
int name(const std::string &n)
Set the device name.
int deviceAddress()
Get the device address.
int getResponse(std::string &response, const za_reply &rep)
Get a response from the device, after a command has been sent.
int m_deviceAddress
The device's address, a.k.a. its order in the chain.
char m_deviceStatus
Current status. Either 'I' for IDLE or 'B' for BUSY. Intializes to 'U' for UNKOWN.
float temp()
Get the temperature, in C.
int getResponse(std::string &response, const std::string &repBuff)
Get a response from the device, after a command has been sent.
std::string m_name
The stage's name.
bool warningState()
Get the warning state.
int unsetWarnings()
Sets all warning flags to false.
constexpr static logPrioT LOG_DEBUG2
Used for debugging, providing a 2nd level.
constexpr static logPrioT LOG_EMERGENCY
Normal operations of the entire system should be shut down immediately.
constexpr static logPrioT LOG_WARNING
A condition has occurred which may become an error, but the process continues.
int za_decode(struct za_reply *destination, const char *reply)
int za_receive(z_port port, char *destination, int length)
int za_send(z_port port, const char *command)
Provides a set of functions for interacting with Zaber devices in the ASCII protocol.