23 #include <sys/ioctl.h> 32 #ifdef HAVE_LINUX_SERIAL_H 33 #include <linux/serial.h> 35 #define B500000 0010005 47 _sick_device_path(sick_device_path),
48 _curr_session_baud(SICK_BAUD_UNKNOWN),
49 _desired_session_baud(SICK_BAUD_UNKNOWN)
55 memset(&
_old_term,0,
sizeof(
struct termios));
83 std::cerr << sick_io_exception.
what() << std::endl;
89 std::cerr <<
"SickPLS::~SickPLS: Unknown exception!" << std::endl;
109 std::cout << std::endl <<
"\t*** Attempting to initialize the Sick PLS..." << std::endl << std::flush;
112 std::cout <<
"\tAttempting to open device @ " <<
_sick_device_path << std::endl << std::flush;
114 std::cout <<
"\t\tDevice opened!" << std::endl << std::flush;
119 std::cout <<
"\tAttempting to start buffer monitor..." << std::endl;
121 std::cout <<
"\t\tBuffer monitor started!" << std::endl;
125 std::cout <<
"\tAttempting to reset buffer monitor..." << std::endl;
127 std::cout <<
"\t\tBuffer monitor reset!" << std::endl;
133 std::cout <<
"\tAttempting to set session baud rate to " 135 <<
" as requested..." << std::endl;
146 std::cout <<
"\tFailed to set requested baud rate..." << std::endl << std::flush;
147 std::cout <<
"\tAttempting to detect PLS baud rate..." << std::endl << std::flush;
168 throw SickIOException(
"SickPLS::Initialize: failed to detect baud rate!");
170 std::cout << std::flush;
175 std::cout <<
"\tAttempting to setup desired baud (again)..." << std::endl << std::flush;
185 std::cerr <<
"SickPLS::Initialize: Unknown exception!" << std::endl;
204 std::cerr << sick_config_exception.
what() << std::endl;
212 std::cerr << sick_timeout_exception.
what() << std::endl;
220 std::cerr << sick_io_exception.
what() << std::endl;
228 std::cerr << sick_thread_exception.
what() << std::endl;
236 std::cerr <<
"SickPLS::Initialize: Unknown exception!" << std::endl;
241 std::cout <<
"\t*** Init. complete: Sick PLS is online and ready!" << std::endl;
242 std::cout <<
"\tScan Angle: " <<
GetSickScanAngle() <<
" (deg)" << std::endl;
245 std::cout << std::endl << std::flush;
259 std::cout << std::endl <<
"\t*** Attempting to uninitialize the Sick PLS..." << std::endl;
273 std::cout <<
"\tAttempting to stop buffer monitor..." << std::endl;
275 std::cout <<
"\t\tBuffer monitor stopped!" << std::endl;
278 std::cout <<
"\t*** Uninit. complete - Sick PLS is now offline!" << std::endl << std::flush;
283 catch(SickConfigException &sick_config_exception)
285 std::cerr << sick_config_exception.
what() <<
" (attempting to kill connection anyways)" << std::endl;
290 catch(SickTimeoutException &sick_timeout_exception)
292 std::cerr << sick_timeout_exception.
what() <<
" (attempting to kill connection anyways)" << std::endl;
297 catch(SickIOException &sick_io_exception)
299 std::cerr << sick_io_exception.
what() <<
" (attempting to kill connection anyways)" << std::endl;
304 catch(SickThreadException &sick_thread_exception)
306 std::cerr << sick_thread_exception.
what() <<
" (attempting to kill connection anyways)" << std::endl;
313 std::cerr <<
"SickPLS::Unintialize: Unknown exception!!!" << std::endl;
344 throw SickConfigException(
"SickPLS::GetSickScanAngle: Sick PLS is not initialized!");
362 throw SickConfigException(
"SickPLS::GetSickScanResolution: Sick PLS is not initialized!");
382 throw SickConfigException(
"SickPLS::GetSickMeasuringUnits: Sick PLS is not initialized!");
398 throw SickConfigException(
"SickPLS::GetSickScanAngle: Sick PLS is not initialized!");
470 for (
unsigned int i = 0; i < num_measurement_values; i++)
483 std::cerr << sick_config_exception.
what() << std::endl;
490 std::cerr << sick_timeout_exception.
what() << std::endl;
497 std::cerr << sick_io_exception.
what() << std::endl;
504 std::cerr << sick_thread_exception.
what() << std::endl;
511 std::cerr <<
"SickPLS::GetSickScan: Unknown exception!!!" << std::endl;
531 throw SickConfigException(
"SickPLS::ResetSick: Sick PLS is not initialized!");
541 std::cout <<
"\tResetting the device..." << std::endl;
542 std::cout <<
"\tWaiting for Power on message..." << std::endl;
550 std::cout <<
"\t\tPower on message received!" << std::endl;
551 std::cout <<
"\tWaiting for PLS Ready message..." << std::endl;
562 std::cerr <<
"SickPLS::ResetSick: Unexpected reply! (assuming device has been reset!)" << std::endl;
566 std::cout <<
"\t\tPLS Ready message received!" << std::endl;
568 std::cout << std::endl;
576 catch(SickTimeoutException &sick_timeout_exception)
578 std::cerr << sick_timeout_exception.
what() << std::endl;
583 catch(SickIOException &sick_io_exception)
585 std::cerr << sick_io_exception.
what() << std::endl;
590 catch(SickThreadException &sick_thread_exception)
592 std::cerr << sick_thread_exception.
what() << std::endl;
599 std::cerr <<
"SickPLS::ResetSick: Unknown exception!!!" << std::endl;
603 std::cout <<
"\tRe-initialization sucessful. PLS is ready to go!" << std::endl;
614 std::stringstream str_stream;
616 str_stream <<
"\t=============== Sick PLS Status ===============" << std::endl;
622 str_stream <<
"\tScan Angle: " <<
GetSickScanAngle() <<
" (deg)" << std::endl;
631 str_stream <<
"\t Unknown (Device is not initialized)" << std::endl;
635 str_stream <<
"\t===============================================" << std::endl;
637 return str_stream.str();
651 switch(scan_angle_int)
668 switch(scan_resolution_int)
742 std::istringstream input_stream(baud_str);
743 input_stream >> baud_int;
760 return "Error (possibly fatal)";
775 switch(sick_operating_mode)
778 return "Installation Mode";
780 return "Diagnostic Mode";
782 return "Stream mim measured values for each segment";
784 return "Min measured value for each segment when object detected";
786 return "Min vertical distance";
788 return "Min vertical distance when object detected";
790 return "Stream all measured values";
792 return "Request measured values";
794 return "Stream mean measured values";
796 return "Stream measured value subrange";
798 return "Stream mean measured value subrange";
800 return "Stream measured and field values";
802 return "Stream measured values from partial scan";
804 return "Stream range w/ reflectivity from partial scan";
806 return "Stream min measured values for each segment over a subrange";
808 return "Output navigation data records";
810 return "Stream range w/ reflectivity values";
831 return "Centimeters (cm)";
850 throw SickIOException(
"SickPLS::_setupConnection: - Unable to open serial port");
856 throw SickIOException(
"SickPLS::_setupConnection: tcgetattr() failed!");
865 catch(SickIOException &sick_io_exception)
867 std::cerr << sick_io_exception.
what() << std::endl;
872 catch(SickThreadException &sick_thread_exception)
874 std::cerr << sick_thread_exception.
what() << std::endl;
881 std::cerr <<
"SickPLS::_setupConnection: Unknown exception!" << std::endl;
902 throw SickIOException(
"SickPLS::_teardownConnection: tcsetattr() failed!");
908 throw SickIOException(
"SickPLS::_teardownConnection: close() failed!");
926 if (tcflush(
_sick_fd,TCIOFLUSH) != 0)
928 throw SickThreadException(
"SickPLS::_flushTerminalBuffer: tcflush() failed!");
937 catch(SickThreadException &sick_thread_exception)
939 std::cerr << sick_thread_exception.
what() << std::endl;
946 std::cerr <<
"SickPLS::_flushTerminalBuffer: Unknown exception!" << std::endl;
964 const unsigned int timeout_value,
968 uint8_t sick_reply_code = send_message.GetCommandCode() + 0x80;
993 std::cerr << sick_thread_exception.
what() << std::endl;
1000 std::cerr << sick_io_error.
what() << std::endl;
1007 std::cerr <<
"SickPLS::_sendMessageAndGetReply: Unknown exception!!!" << std::endl;
1023 const uint8_t reply_code,
1024 const unsigned int timeout_value,
1039 timeout_value, num_tries);
1052 std::cerr << sick_thread_exception.
what() << std::endl;
1059 std::cerr << sick_io_error.
what() << std::endl;
1066 std::cerr <<
"SickPLS::_sendMessageAndGetReply: Unknown exception!!!" << std::endl;
1083 std::cout<<
"Setting session baud from operating mode: " 1094 throw SickIOException(
"SickPLS::_setSessionBaud: Undefined baud rate!");
1099 payload[1] = baud_rate;
1122 std::cerr << sick_timeout_exception.
what() << std::endl;
1129 std::cerr << sick_io_exception.
what() << std::endl;
1136 std::cerr << sick_thread_exception.
what() << std::endl;
1143 std::cerr <<
"SickPLS::_getSickErrors: Unknown exception!!!" << std::endl;
1162 throw SickIOException(
"SickPLS::_testBaudRate: Undefined baud rate!");
1166 std::cout <<
"\t\tChecking " <<
SickBaudToString(baud_rate) <<
"..." << std::endl;
1189 std::cerr <<
"SickPLS::_testBaudRate: Unknown exception!" << std::endl;
1198 std::cerr << sick_io_exception.
what() << std::endl;
1205 std::cerr << sick_thread_exception.
what() << std::endl;
1212 std::cerr <<
"SickPLS::_testBaudRate: Unknown exception!!!" << std::endl;
1228 struct termios term;
1230 term.c_iflag |= INPCK;
1231 term.c_iflag &= ~IXOFF;
1232 term.c_cflag |= PARENB;
1239 throw SickIOException(
"SickPLS::_setTerminalBaud: Unable to get device attributes!");
1249 term.c_iflag |= INPCK;
1250 term.c_iflag &= ~IXOFF;
1251 term.c_cflag |= PARENB;
1253 cfsetispeed(&term,B9600);
1254 cfsetospeed(&term,B9600);
1261 term.c_iflag |= INPCK;
1262 term.c_iflag &= ~IXOFF;
1263 term.c_cflag |= PARENB;
1265 cfsetispeed(&term,B19200);
1266 cfsetospeed(&term,B19200);
1273 term.c_iflag |= INPCK;
1274 term.c_iflag &= ~IXOFF;
1275 term.c_cflag |= PARENB;
1277 cfsetispeed(&term,B38400);
1278 cfsetospeed(&term,B38400);
1285 term.c_iflag |= INPCK;
1286 term.c_iflag &= ~IXOFF;
1287 term.c_cflag |= PARENB;
1294 throw SickIOException(
"SickPLS::_setTerminalBaud: Unknown baud rate!");
1298 if(tcsetattr(
_sick_fd,TCSAFLUSH,&term) < 0 )
1300 throw SickIOException(
"SickPLS::_setTerminalBaud: Unable to set device attributes!");
1314 std::cerr << sick_io_exception.
what() << std::endl;
1321 std::cerr << sick_thread_exception.
what() << std::endl;
1328 std::cerr <<
"SickPLS::_setTerminalBaud: Unknown exception!!!" << std::endl;
1349 payload_buffer[0] = 0x32;
1365 std::cerr << sick_timeout_exception.
what() << std::endl;
1372 std::cerr << sick_io_exception.
what() << std::endl;
1379 std::cerr << sick_thread_exception.
what() << std::endl;
1386 std::cerr <<
"SickPLS::_getSickErrors: Unknown exception!!!" << std::endl;
1394 double num_errors = ((payload_length-2)/((
double)2));
1397 if (num_sick_errors)
1399 *num_sick_errors = (
unsigned int)num_errors;
1403 for (
unsigned int i = 0, k = 1; i < (
unsigned int)num_errors && (error_type_buffer || error_num_buffer); i++)
1407 if (error_type_buffer)
1409 error_type_buffer[i] = payload_buffer[k];
1414 if (error_num_buffer)
1416 error_num_buffer[i] = payload_buffer[k];
1449 catch(SickConfigException &sick_config_exception)
1451 std::cerr << sick_config_exception.
what() << std::endl;
1456 catch(SickTimeoutException &sick_timeout_exception)
1458 std::cerr << sick_timeout_exception.
what() << std::endl;
1463 catch(SickIOException &sick_io_exception)
1465 std::cerr << sick_io_exception.
what() << std::endl;
1470 catch(SickThreadException &sick_thread_exception)
1472 std::cerr << sick_thread_exception.
what() << std::endl;
1479 std::cerr <<
"SickPLS::_setSickOpModeInstallation: Unknown exception!!!" << std::endl;
1500 std::cout <<
"\tAttempting to enter diagnostic mode..." << std::endl;
1511 catch(SickConfigException &sick_config_exception)
1513 std::cerr << sick_config_exception.
what() << std::endl;
1518 catch(SickTimeoutException &sick_timeout_exception)
1520 std::cerr << sick_timeout_exception.
what() << std::endl;
1525 catch(SickIOException &sick_io_exception)
1527 std::cerr << sick_io_exception.
what() << std::endl;
1532 catch(SickThreadException &sick_thread_exception)
1534 std::cerr << sick_thread_exception.
what() << std::endl;
1541 std::cerr <<
"SickPLS::_setSickOpModeInstallation: Unknown exception!!!" << std::endl;
1548 std::cout <<
"Success!" << std::endl;
1574 catch(SickConfigException &sick_config_exception)
1576 std::cerr << sick_config_exception.
what() << std::endl;
1581 catch(SickTimeoutException &sick_timeout_exception)
1583 std::cerr << sick_timeout_exception.
what() << std::endl;
1588 catch(SickIOException &sick_io_exception)
1590 std::cerr << sick_io_exception.
what() << std::endl;
1595 catch(SickThreadException &sick_thread_exception)
1597 std::cerr << sick_thread_exception.
what() << std::endl;
1604 std::cerr <<
"SickPLS::_setSickOpModeMonitorRequestValues: Unknown exception!!!" << std::endl;
1626 std::cout <<
"\tRequesting measured value data stream..." << std::endl;
1637 catch(SickConfigException &sick_config_exception)
1639 std::cerr << sick_config_exception.
what() << std::endl;
1644 catch(SickTimeoutException &sick_timeout_exception)
1646 std::cerr << sick_timeout_exception.
what() << std::endl;
1651 catch(SickIOException &sick_io_exception)
1653 std::cerr << sick_io_exception.
what() << std::endl;
1658 catch(SickThreadException &sick_thread_exception)
1660 std::cerr << sick_thread_exception.
what() << std::endl;
1667 std::cerr <<
"SickPLS::_setSickOpModeMonitorStreamValues: Unknown exception!!!" << std::endl;
1674 std::cout <<
"\t\tData stream started!" << std::endl;
1693 uint16_t num_partial_scans = 0;
1696 payload_buffer[0] = 0x20;
1697 payload_buffer[1] = sick_mode;
1705 if(mode_params == NULL)
1707 throw SickConfigException(
"SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1710 memcpy(&payload_buffer[2],mode_params,8);
1745 if(mode_params == NULL)
1747 throw SickConfigException(
"SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1750 payload_buffer[2] = *mode_params;
1757 if(mode_params == NULL)
1759 throw SickConfigException(
"SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1762 memcpy(&payload_buffer[2],mode_params,2);
1763 memcpy(&payload_buffer[4],&mode_params[2],2);
1770 if(mode_params == NULL)
1772 throw SickConfigException(
"SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1775 payload_buffer[2] = mode_params[0];
1776 memcpy(&payload_buffer[3],&mode_params[1],2);
1777 memcpy(&payload_buffer[5],&mode_params[3],2);
1784 if(mode_params == NULL)
1786 throw SickConfigException(
"SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1789 memcpy(&payload_buffer[2],mode_params,2);
1790 memcpy(&payload_buffer[4],&mode_params[2],2);
1801 if(mode_params == NULL)
1803 throw SickConfigException(
"SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1807 memcpy(&num_partial_scans,mode_params,2);
1810 memcpy(&payload_buffer[2],mode_params,num_partial_scans*4+2);
1817 if(mode_params == NULL)
1819 throw SickConfigException(
"SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1823 memcpy(&num_partial_scans,mode_params,2);
1826 memcpy(&payload_buffer[2],mode_params,num_partial_scans*4+2);
1837 if(mode_params == NULL)
1839 throw SickConfigException(
"SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1842 memcpy(&payload_buffer[2],mode_params,2);
1843 memcpy(&payload_buffer[4],&mode_params[2],2);
1851 throw SickConfigException(
"SickPLS::_switchSickOperatingMode: Unrecognized operating mode!");
1870 std::cerr << sick_timeout_exception.
what() << std::endl;
1877 std::cerr << sick_io_exception.
what() << std::endl;
1884 std::cerr << sick_thread_exception.
what() << std::endl;
1891 std::cerr <<
"SickPLS::_switchSickOperatingMode: Unknown exception!!!" << std::endl;
1896 memset(payload_buffer,0,
sizeof(payload_buffer));
1902 if(payload_buffer[1] != 0x00)
1904 throw SickConfigException(
"SickPLS::_switchSickOperatingMode: configuration request failed!");
1947 const uint16_t num_measurements,
1948 uint16_t *
const measured_values)
const 1951 for(
unsigned int i = 0; i < num_measurements; i++)
1953 measured_values[i] = byte_sequence[i*2] + 256*(byte_sequence[i*2+1] & 0x1F);
2014 std::cerr <<
"Unexpected baud rate!" << std::endl;
Defines simple utility functions for working with the Sick LMS 2xx laser range finder units...
#define DEFAULT_SICK_PLS_SICK_SWITCH_MODE_TIMEOUT
Can take the Sick LD up to 3 seconds to reply (usecs)
Contains some simple exception classes.
#define DEFAULT_SICK_PLS_SICK_PASSWORD
Password for entering installation mode.
Definition of class SickPLSMessage.
#define DEFAULT_SICK_PLS_SICK_MESSAGE_TIMEOUT
The max time to wait for a message reply (usecs)
#define DEFAULT_SICK_PLS_BYTE_INTERVAL
Minimum time in microseconds between transmitted bytes.
#define DEFAULT_SICK_PLS_SICK_ADDRESS
Sick PLS default serial address.
#define DEFAULT_SICK_PLS_SICK_BAUD
Initial baud rate of the PLS (whatever is set in flash)
Defines a class for monitoring the receive buffer when interfacing w/ a Sick PLS laser range finder...
Definition of class SickPLS. Code by Jason C. Derenick and Thomas H. Miller. Contact derenick(at)lehi...
#define DEFAULT_SICK_PLS_NUM_TRIES
The max number of tries before giving up on a request.