SickPLS.cc
Go to the documentation of this file.
1 
16 /* Auto-generated header */
17 //#include "SickConfig.hh"
18 
19 /* Implementation dependencies */
20 #include <sstream>
21 #include <iostream>
22 #include <termios.h>
23 #include <sys/ioctl.h>
24 #include <signal.h>
25 
26 #include "SickPLS.hh"
27 #include "SickPLSMessage.hh"
28 #include "SickPLSBufferMonitor.hh"
29 #include "SickPLSUtility.hh"
30 #include "SickException.hh"
31 
32 #ifdef HAVE_LINUX_SERIAL_H
33 #include <linux/serial.h>
34 #else
35 #define B500000 0010005
36 #endif
37 
38 /* Associate the namespace */
39 namespace SickToolbox
40 {
41 
46 SickPLS::SickPLS( const std::string sick_device_path ): SickLIDAR< SickPLSBufferMonitor, SickPLSMessage >( ),
47  _sick_device_path(sick_device_path),
48  _curr_session_baud(SICK_BAUD_UNKNOWN),
49  _desired_session_baud(SICK_BAUD_UNKNOWN)
50 {
51 
52  /* Initialize the protected/private structs */
54  memset(&_sick_baud_status,0,sizeof(sick_pls_baud_status_t));
55  memset(&_old_term,0,sizeof(struct termios));
56 
57  //start in an unknown mode
59 
60  //fixed parameters
64 }
65 
70 {
71 
72  try
73  {
74 
75  /* Attempt to uninitialize the device */
77 
78  }
79 
80  /* Catch an I/O exception */
81  catch(SickIOException &sick_io_exception)
82  {
83  std::cerr << sick_io_exception.what() << std::endl;
84  }
85 
86  /* Catch anything else */
87  catch(...)
88  {
89  std::cerr << "SickPLS::~SickPLS: Unknown exception!" << std::endl;
90  }
91 
92 }
93 
99 bool SickPLS::Initialize( const sick_pls_baud_t desired_baud_rate )
101 {
102 
103  /* Buffer the desired baud rate in case we have to reset */
104  _desired_session_baud = desired_baud_rate;
105 
106  try
107  {
108 
109  std::cout << std::endl << "\t*** Attempting to initialize the Sick PLS..." << std::endl << std::flush;
110 
111  /* Initialize the serial term for communication */
112  std::cout << "\tAttempting to open device @ " << _sick_device_path << std::endl << std::flush;
114  std::cout << "\t\tDevice opened!" << std::endl << std::flush;
115 
116  /* Start/reset the buffer monitor */
118  {
119  std::cout << "\tAttempting to start buffer monitor..." << std::endl;
120  _startListening();
121  std::cout << "\t\tBuffer monitor started!" << std::endl;
122  }
123  else
124  {
125  std::cout << "\tAttempting to reset buffer monitor..." << std::endl;
127  std::cout << "\t\tBuffer monitor reset!" << std::endl;
128  }
129 
130  try
131  {
132 
133  std::cout << "\tAttempting to set session baud rate to "
135  << " as requested..." << std::endl;
137 
138  }
139 
140  /* Assume a timeout is due to a misconfigured terminal baud */
141  catch(SickTimeoutException &sick_timeout)
142  {
143 
144  /* Check whether to do an autodetect */
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;
148  if((default_baud != SICK_BAUD_38400) && _testSickBaud(SICK_BAUD_38400))
149  {
150  std::cout << "\t\tDetected PLS baud @ " << SickBaudToString(SICK_BAUD_38400) << "!" << std::endl;
151  }
152  else if((default_baud) != SICK_BAUD_500K && _testSickBaud(SICK_BAUD_500K))
153  {
154  std::cout << "\t\tDetected PLS baud @ " << SickBaudToString(SICK_BAUD_500K) << "!" << std::endl;
155  }
156  else if((default_baud != SICK_BAUD_9600) && _testSickBaud(SICK_BAUD_9600))
157  {
158  std::cout << "\t\tDetected PLS baud @ " << SickBaudToString(SICK_BAUD_9600) << "!" << std::endl;
159  }
160  else if((default_baud != SICK_BAUD_19200) && _testSickBaud(SICK_BAUD_19200))
161  {
162  std::cout << "\t\tDetected PLS baud @ " << SickBaudToString(SICK_BAUD_19200) << "!" << std::endl;
163  }
164  else
165  {
166  _stopListening();
167  return false;
168  throw SickIOException("SickPLS::Initialize: failed to detect baud rate!");
169  }
170  std::cout << std::flush;
171 
172  /* Try again! */
174  {
175  std::cout << "\tAttempting to setup desired baud (again)..." << std::endl << std::flush;
177  }
178 
179  }
180 
181  /* Catch anything else */
182  catch(...)
183  {
184  return false;
185  std::cerr << "SickPLS::Initialize: Unknown exception!" << std::endl;
186  throw;
187  }
188 
189  std::cout << "\t\tOperating @ " << SickBaudToString(_curr_session_baud) << std::endl;
190 
191  /* Set the device to request range mode */
193 
194 
195  /* Set the flag */
196  _sick_initialized = true;
197 
198  }
199 
200  /* Handle a config exception */
201  catch(SickConfigException &sick_config_exception)
202  {
203  return false;
204  std::cerr << sick_config_exception.what() << std::endl;
205  throw;
206  }
207 
208  /* Handle a timeout exception */
209  catch(SickTimeoutException &sick_timeout_exception)
210  {
211  return false;
212  std::cerr << sick_timeout_exception.what() << std::endl;
213  throw;
214  }
215 
216  /* Handle any I/O exceptions */
217  catch(SickIOException &sick_io_exception)
218  {
219  return false;
220  std::cerr << sick_io_exception.what() << std::endl;
221  throw;
222  }
223 
224  /* Handle any thread exceptions */
225  catch(SickThreadException &sick_thread_exception)
226  {
227  return false;
228  std::cerr << sick_thread_exception.what() << std::endl;
229  throw;
230  }
231 
232  /* Handle anything else */
233  catch(...)
234  {
235  return false;
236  std::cerr << "SickPLS::Initialize: Unknown exception!" << std::endl;
237  throw;
238  }
239 
240  /* Initialization was successful! */
241  std::cout << "\t*** Init. complete: Sick PLS is online and ready!" << std::endl;
242  std::cout << "\tScan Angle: " << GetSickScanAngle() << " (deg)" << std::endl;
243  std::cout << "\tScan Resolution: " << GetSickScanResolution() << " (deg)" << std::endl;
244  std::cout << "\tMeasuring Units: " << SickMeasuringUnitsToString(GetSickMeasuringUnits()) << std::endl;
245  std::cout << std::endl << std::flush;
246  return true;
247 }
248 
254 {
255 
256  if (_sick_initialized)
257  {
258 
259  std::cout << std::endl << "\t*** Attempting to uninitialize the Sick PLS..." << std::endl;
260 
261  try
262  {
263 
264  /* Restore original operating mode */
266 
267  /* Restore original baud rate settings */
269 
270  /* Attempt to cancel the buffer monitor */
272  {
273  std::cout << "\tAttempting to stop buffer monitor..." << std::endl;
274  _stopListening();
275  std::cout << "\t\tBuffer monitor stopped!" << std::endl;
276  }
277 
278  std::cout << "\t*** Uninit. complete - Sick PLS is now offline!" << std::endl << std::flush;
279 
280  }
281 
282  /* Handle any config exceptions */
283  catch(SickConfigException &sick_config_exception)
284  {
285  std::cerr << sick_config_exception.what() << " (attempting to kill connection anyways)" << std::endl;
286  throw;
287  }
288 
289  /* Handle a timeout exception */
290  catch(SickTimeoutException &sick_timeout_exception)
291  {
292  std::cerr << sick_timeout_exception.what() << " (attempting to kill connection anyways)" << std::endl;
293  throw;
294  }
295 
296  /* Handle any I/O exceptions */
297  catch(SickIOException &sick_io_exception)
298  {
299  std::cerr << sick_io_exception.what() << " (attempting to kill connection anyways)" << std::endl;
300  throw;
301  }
302 
303  /* Handle any thread exceptions */
304  catch(SickThreadException &sick_thread_exception)
305  {
306  std::cerr << sick_thread_exception.what() << " (attempting to kill connection anyways)" << std::endl;
307  throw;
308  }
309 
310  /* Handle anything else */
311  catch(...)
312  {
313  std::cerr << "SickPLS::Unintialize: Unknown exception!!!" << std::endl;
314  throw;
315  }
316 
317  /* Reset the flag */
318  _sick_initialized = false;
319 
320  }
321 
322 }
323 
328 std::string SickPLS::GetSickDevicePath( ) const
329 {
330  return _sick_device_path;
331 }
332 
333 
339 {
340 
341  /* Ensure the device is initialized */
342  if (!_sick_initialized)
343  {
344  throw SickConfigException("SickPLS::GetSickScanAngle: Sick PLS is not initialized!");
345  }
346 
347  /* Return the Sick scan angle */
349 
350 }
351 
357 {
358 
359  /* Ensure the device is initialized */
360  if (!_sick_initialized)
361  {
362  throw SickConfigException("SickPLS::GetSickScanResolution: Sick PLS is not initialized!");
363  }
364 
365  /* Return the scan resolution */
367 
368 }
369 
370 
371 
377 {
378 
379  /* Ensure the device is initialized */
380  if (!_sick_initialized)
381  {
382  throw SickConfigException("SickPLS::GetSickMeasuringUnits: Sick PLS is not initialized!");
383  }
384 
386 }
387 
393 {
394 
395  /* Ensure the device is initialized */
396  if (!_sick_initialized)
397  {
398  throw SickConfigException("SickPLS::GetSickScanAngle: Sick PLS is not initialized!");
399  }
400 
401  /* Return the current operating mode of the device */
403 
404 }
405 
406 
407 
424 void SickPLS::GetSickScan( unsigned int * const measurement_values,
425  unsigned int & num_measurement_values) throw( SickConfigException, SickTimeoutException, SickIOException, SickThreadException)
426 {
427 
428  /* Ensure the device is initialized */
429  if (!_sick_initialized)
430  {
431  throw SickConfigException("SickPLS::GetSickScan: Sick PLS is not initialized!");
432  }
433 
434  /* Declare message objects */
435  SickPLSMessage response;
436 
437  /* Declare some useful variables and a buffer */
438  uint8_t payload_buffer[SickPLSMessage::MESSAGE_PAYLOAD_MAX_LENGTH] = {0};
439 
440  try
441  {
442 
443  /* Restore original operating mode */
445 
446  /* Receive a data frame from the stream. */
448 
449  /* Check that our payload has the proper command byte of 0xB0 */
450  if(response.GetCommandCode() != 0xB0)
451  {
452  throw SickIOException("SickPLS::GetSickScan: Unexpected message!");
453  }
454 
455  /* Acquire the payload buffer and length*/
456  response.GetPayload(payload_buffer);
457 
458  /* Define a local scan profile object */
459  sick_pls_scan_profile_b0_t sick_scan_profile;
460 
461  /* Initialize the profile */
462  memset(&sick_scan_profile,0,sizeof(sick_pls_scan_profile_b0_t));
463 
464  /* Parse the message payload */
465  _parseSickScanProfileB0(&payload_buffer[1],sick_scan_profile);
466 
467  /* Return the request values! */
468  num_measurement_values = sick_scan_profile.sick_num_measurements;
469 
470  for (unsigned int i = 0; i < num_measurement_values; i++)
471  {
472 
473  /* Copy the measurement value */
474  measurement_values[i] = sick_scan_profile.sick_measurements[i];
475 
476  }
477 
478  }
479 
480  /* Handle any config exceptions */
481  catch(SickConfigException &sick_config_exception)
482  {
483  std::cerr << sick_config_exception.what() << std::endl;
484  throw;
485  }
486 
487  /* Handle a timeout exception */
488  catch(SickTimeoutException &sick_timeout_exception)
489  {
490  std::cerr << sick_timeout_exception.what() << std::endl;
491  throw;
492  }
493 
494  /* Handle any I/O exceptions */
495  catch(SickIOException &sick_io_exception)
496  {
497  std::cerr << sick_io_exception.what() << std::endl;
498  throw;
499  }
500 
501  /* Handle any thread exceptions */
502  catch(SickThreadException &sick_thread_exception)
503  {
504  std::cerr << sick_thread_exception.what() << std::endl;
505  throw;
506  }
507 
508  /* Handle anything else */
509  catch(...)
510  {
511  std::cerr << "SickPLS::GetSickScan: Unknown exception!!!" << std::endl;
512  throw;
513  }
514 
515 }
516 
517 
518 
519 
520 
526 {
527 
528  /* Ensure the device is initialized */
529  if (!_sick_initialized)
530  {
531  throw SickConfigException("SickPLS::ResetSick: Sick PLS is not initialized!");
532  }
533 
534  SickPLSMessage message,response;
535  uint8_t payload[SickPLSMessage::MESSAGE_PAYLOAD_MAX_LENGTH] = {0};
536 
537  /* Construct the reset command */
538  payload[0] = 0x10; // Request field reset
539  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload,1);
540 
541  std::cout << "\tResetting the device..." << std::endl;
542  std::cout << "\tWaiting for Power on message..." << std::endl;
543 
544  try
545  {
546 
547  /* Send the reset command and wait for the reply */
548  _sendMessageAndGetReply(message,response,0x91,(unsigned int)60e6,DEFAULT_SICK_PLS_NUM_TRIES);
549 
550  std::cout << "\t\tPower on message received!" << std::endl;
551  std::cout << "\tWaiting for PLS Ready message..." << std::endl;
552 
553  /* Set terminal baud to the detected rate to get the PLS ready message */
555 
556  /* Receive the PLS ready message after power on */
557  _recvMessage(response,(unsigned int)30e6);
558 
559  /* Verify the response */
560  if(response.GetCommandCode() != 0x90)
561  {
562  std::cerr << "SickPLS::ResetSick: Unexpected reply! (assuming device has been reset!)" << std::endl;
563  }
564  else
565  {
566  std::cout << "\t\tPLS Ready message received!" << std::endl;
567  }
568  std::cout << std::endl;
569 
570  /* Reinitialize and sync the device */
572 
573  }
574 
575  /* Catch any timeout exceptions */
576  catch(SickTimeoutException &sick_timeout_exception)
577  {
578  std::cerr << sick_timeout_exception.what() << std::endl;
579  throw;
580  }
581 
582  /* Catch any I/O exceptions */
583  catch(SickIOException &sick_io_exception)
584  {
585  std::cerr << sick_io_exception.what() << std::endl;
586  throw;
587  }
588 
589  /* Catch any thread exceptions */
590  catch(SickThreadException &sick_thread_exception)
591  {
592  std::cerr << sick_thread_exception.what() << std::endl;
593  throw;
594  }
595 
596  /* Catch anything else */
597  catch(...)
598  {
599  std::cerr << "SickPLS::ResetSick: Unknown exception!!!" << std::endl;
600  throw;
601  }
602 
603  std::cout << "\tRe-initialization sucessful. PLS is ready to go!" << std::endl;
604 
605 }
606 
611 std::string SickPLS::GetSickStatusAsString( ) const
612 {
613 
614  std::stringstream str_stream;
615 
616  str_stream << "\t=============== Sick PLS Status ===============" << std::endl;
617 
618  /* If Sick is initialized then print the status! */
619  if (_sick_initialized)
620  {
621 
622  str_stream << "\tScan Angle: " << GetSickScanAngle() << " (deg)" << std::endl;
623  str_stream << "\tScan Resolution: " << GetSickScanResolution() << " (deg)" << std::endl;
624  str_stream << "\tOperating Mode: " << SickOperatingModeToString(GetSickOperatingMode()) << std::endl;
625  str_stream << "\tMeasuring Units: " << SickMeasuringUnitsToString(GetSickMeasuringUnits()) << std::endl;
626 
627  }
628  else
629  {
630 
631  str_stream << "\t Unknown (Device is not initialized)" << std::endl;
632 
633  }
634 
635  str_stream << "\t===============================================" << std::endl;
636 
637  return str_stream.str();
638 }
639 
640 
641 
642 
643 
649 {
650 
651  switch(scan_angle_int)
652  {
653  case 180:
654  return SICK_SCAN_ANGLE_180;
655  default:
657  }
658 
659 }
660 
666 {
667 
668  switch(scan_resolution_int)
669  {
670  case 50:
672  default:
674  }
675 
676 }
677 
683 {
684  return IntToSickScanResolution((const int)(scan_resolution_double*100));
685 }
686 
692 std::string SickPLS::SickBaudToString( const sick_pls_baud_t baud_rate )
693 {
694 
695  switch(baud_rate)
696  {
697  case SICK_BAUD_9600:
698  return "9600bps";
699  case SICK_BAUD_19200:
700  return "19200bps";
701  case SICK_BAUD_38400:
702  return "38400bps";
703  case SICK_BAUD_500K:
704  return "500Kbps";
705  default:
706  return "Unknown!";
707  }
708 
709 }
710 
716 {
717 
718  switch(baud_int)
719  {
720  case 9600:
721  return SICK_BAUD_9600;
722  case 19200:
723  return SICK_BAUD_19200;
724  case 38400:
725  return SICK_BAUD_38400;
726  case 500000:
727  return SICK_BAUD_500K;
728  default:
729  return SICK_BAUD_UNKNOWN;
730  }
731 
732 }
733 
738 sick_pls_baud_t SickPLS::StringToSickBaud( const std::string baud_str )
739 {
740 
741  int baud_int;
742  std::istringstream input_stream(baud_str);
743  input_stream >> baud_int;
744 
745  return IntToSickBaud(baud_int);
746 
747 }
748 
754 std::string SickPLS::SickStatusToString( const sick_pls_status_t sick_status )
755 {
756 
757  /* Return a string */
758  if(sick_status != SICK_STATUS_OK)
759  {
760  return "Error (possibly fatal)";
761  }
762  return "OK!";
763 
764 }
765 
766 
772 std::string SickPLS::SickOperatingModeToString( const sick_pls_operating_mode_t sick_operating_mode )
773 {
774 
775  switch(sick_operating_mode)
776  {
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";
811  default:
812  return "Unknown!";
813  };
814 
815 }
816 
817 
818 
825 {
826 
827  /* Return the proper string */
828  switch(sick_units)
829  {
831  return "Centimeters (cm)";
832  default:
833  return "Unknown!";
834  }
835 
836 }
837 
842 {
843 
844  try
845  {
846 
847  /* Open the device */
848  if((_sick_fd = open(_sick_device_path.c_str(), O_RDWR | O_NOCTTY | O_NDELAY)) < 0)
849  {
850  throw SickIOException("SickPLS::_setupConnection: - Unable to open serial port");
851  }
852 
853  /* Backup the original term settings */
854  if(tcgetattr(_sick_fd,&_old_term) < 0)
855  {
856  throw SickIOException("SickPLS::_setupConnection: tcgetattr() failed!");
857  }
858 
859  /* Set the host terminal baud rate to the new speed */
861 
862  }
863 
864  /* Handle any I/O exceptions */
865  catch(SickIOException &sick_io_exception)
866  {
867  std::cerr << sick_io_exception.what() << std::endl;
868  throw;
869  }
870 
871  /* Handle any thread exceptions */
872  catch(SickThreadException &sick_thread_exception)
873  {
874  std::cerr << sick_thread_exception.what() << std::endl;
875  throw;
876  }
877 
878  /* Handle unknown exceptions */
879  catch(...)
880  {
881  std::cerr << "SickPLS::_setupConnection: Unknown exception!" << std::endl;
882  throw;
883  }
884 
885 }
886 
891 {
892 
893  /* Check whether device was initialized */
894  if(!_sick_initialized)
895  {
896  return;
897  }
898 
899  /* Restore old terminal settings */
900  if (tcsetattr(_sick_fd,TCSANOW,&_old_term) < 0)
901  {
902  throw SickIOException("SickPLS::_teardownConnection: tcsetattr() failed!");
903  }
904 
905  /* Actually close the device */
906  if(close(_sick_fd) != 0)
907  {
908  throw SickIOException("SickPLS::_teardownConnection: close() failed!");
909  }
910 
911 }
912 
917 {
918 
919  try
920  {
921 
922  /* Acquire access to the data stream */
924 
925  /* Nobody is reading a message, so safely flush! */
926  if (tcflush(_sick_fd,TCIOFLUSH) != 0)
927  {
928  throw SickThreadException("SickPLS::_flushTerminalBuffer: tcflush() failed!");
929  }
930 
931  /* Attempt to release the data stream */
933 
934  }
935 
936  /* Handle thread exceptions */
937  catch(SickThreadException &sick_thread_exception)
938  {
939  std::cerr << sick_thread_exception.what() << std::endl;
940  throw;
941  }
942 
943  /* A sanity check */
944  catch(...)
945  {
946  std::cerr << "SickPLS::_flushTerminalBuffer: Unknown exception!" << std::endl;
947  throw;
948  }
949 
950 }
951 
963  SickPLSMessage &recv_message,
964  const unsigned int timeout_value,
965  const unsigned int num_tries ) throw( SickIOException, SickThreadException, SickTimeoutException )
966 {
967 
968  uint8_t sick_reply_code = send_message.GetCommandCode() + 0x80;
969 
970  // std::cout.setf(std::ios::hex,std::ios::basefield);
971  // std::cout << "Waiting for reply code: " << (unsigned int) sick_reply_code << std::endl;
972  // std::cout.setf(std::ios::dec,std::ios::basefield);
973 
974 
975  try
976  {
977 
978  /* Send a message and get reply using a reply code */
979  _sendMessageAndGetReply(send_message,recv_message,sick_reply_code,timeout_value,num_tries);
980 
981  }
982 
983  /* Handle a timeout! */
984  catch (SickTimeoutException &sick_timeout)
985  {
986  /* For now just rethrow it */
987  throw;
988  }
989 
990  /* Handle a thread exception */
991  catch (SickThreadException &sick_thread_exception)
992  {
993  std::cerr << sick_thread_exception.what() << std::endl;
994  throw;
995  }
996 
997  /* Handle write buffer exceptions */
998  catch (SickIOException &sick_io_error)
999  {
1000  std::cerr << sick_io_error.what() << std::endl;
1001  throw;
1002  }
1003 
1004  /* A safety net */
1005  catch (...)
1006  {
1007  std::cerr << "SickPLS::_sendMessageAndGetReply: Unknown exception!!!" << std::endl;
1008  throw;
1009  }
1010 
1011 }
1012 
1022  SickPLSMessage &recv_message,
1023  const uint8_t reply_code,
1024  const unsigned int timeout_value,
1025  const unsigned int num_tries ) throw( SickIOException, SickThreadException, SickTimeoutException )
1026 {
1027 
1028  try
1029  {
1030 
1031  /* Attempt to flush the terminal buffer */
1033 
1034  /* Send a message and get reply using parent's method */
1036  recv_message,
1037  &reply_code, 1,
1039  timeout_value, num_tries);
1040 
1041  }
1042 
1043  /* Handle a timeout! */
1044  catch (SickTimeoutException &sick_timeout)
1045  {
1046  throw;
1047  }
1048 
1049  /* Handle a thread exception */
1050  catch (SickThreadException &sick_thread_exception)
1051  {
1052  std::cerr << sick_thread_exception.what() << std::endl;
1053  throw;
1054  }
1055 
1056  /* Handle write buffer exceptions */
1057  catch (SickIOException &sick_io_error)
1058  {
1059  std::cerr << sick_io_error.what() << std::endl;
1060  throw;
1061  }
1062 
1063  /* A safety net */
1064  catch (...)
1065  {
1066  std::cerr << "SickPLS::_sendMessageAndGetReply: Unknown exception!!!" << std::endl;
1067  throw;
1068  }
1069 
1070 }
1071 
1077 {
1078 
1079  //PLS-specific before session baud can be set, we need to enter setup mode (setup in PLS software, called installation in SickToolbox)
1080 
1082 
1083  std::cout<< "Setting session baud from operating mode: "
1085  << std::endl;
1086 
1087  SickPLSMessage message, response;
1088 
1089  uint8_t payload[SickPLSMessage::MESSAGE_PAYLOAD_MAX_LENGTH] = {0};
1090 
1091  /* Another sanity check */
1092  if(baud_rate == SICK_BAUD_UNKNOWN)
1093  {
1094  throw SickIOException("SickPLS::_setSessionBaud: Undefined baud rate!");
1095  }
1096 
1097  /* Construct the command telegram */
1098  payload[0] = 0x20;
1099  payload[1] = baud_rate;
1100 
1101  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload,2);
1102 
1103  // message.Print();
1104 
1105  try
1106  {
1107 
1108  /* Send the status request and get a reply */
1110 
1111  /* Set the host terminal baud rate to the new speed */
1112  _setTerminalBaud(baud_rate);
1113 
1114  /* Sick likes a sleep here */
1115  usleep(2500);
1116 
1117  }
1118 
1119  /* Catch a timeout */
1120  catch(SickTimeoutException &sick_timeout_exception)
1121  {
1122  std::cerr << sick_timeout_exception.what() << std::endl;
1123  throw;
1124  }
1125 
1126  /* Catch any I/O exceptions */
1127  catch(SickIOException &sick_io_exception)
1128  {
1129  std::cerr << sick_io_exception.what() << std::endl;
1130  throw;
1131  }
1132 
1133  /* Catch any thread exceptions */
1134  catch(SickThreadException &sick_thread_exception)
1135  {
1136  std::cerr << sick_thread_exception.what() << std::endl;
1137  throw;
1138  }
1139 
1140  /* Catch anything else */
1141  catch(...)
1142  {
1143  std::cerr << "SickPLS::_getSickErrors: Unknown exception!!!" << std::endl;
1144  throw;
1145  }
1146 
1147 }
1148 
1154 {
1155 
1156  try
1157  {
1158 
1159  /* Another sanity check */
1160  if(baud_rate == SICK_BAUD_UNKNOWN)
1161  {
1162  throw SickIOException("SickPLS::_testBaudRate: Undefined baud rate!");
1163  }
1164 
1165  /* Attempt to get status information at the current baud */
1166  std::cout << "\t\tChecking " << SickBaudToString(baud_rate) << "..." << std::endl;
1167 
1168  /* Set the host terminal baud rate to the test speed */
1169  _setTerminalBaud(baud_rate);
1170 
1171  try
1172  {
1173 
1174  /* Check to see if the Sick replies! */
1175  _getSickErrors();
1176 
1177  }
1178 
1179  /* Catch a timeout exception */
1180  catch(SickTimeoutException &sick_timeout_exception)
1181  {
1182  /* This means that the current baud rate timed out! */
1183  return false;
1184  }
1185 
1186  /* Catch anything else and throw it away */
1187  catch(...)
1188  {
1189  std::cerr << "SickPLS::_testBaudRate: Unknown exception!" << std::endl;
1190  throw;
1191  }
1192 
1193  }
1194 
1195  /* Handle any IO exceptions */
1196  catch(SickIOException &sick_io_exception)
1197  {
1198  std::cerr << sick_io_exception.what() << std::endl;
1199  throw;
1200  }
1201 
1202  /* Handle thread exceptions */
1203  catch(SickThreadException &sick_thread_exception)
1204  {
1205  std::cerr << sick_thread_exception.what() << std::endl;
1206  throw;
1207  }
1208 
1209  /* A safety net */
1210  catch(...)
1211  {
1212  std::cerr << "SickPLS::_testBaudRate: Unknown exception!!!" << std::endl;
1213  throw;
1214  }
1215 
1216  /* Success! */
1217  return true;
1218 
1219 }
1220 
1226 {
1227 
1228  struct termios term;
1229 
1230  term.c_iflag |= INPCK;
1231  term.c_iflag &= ~IXOFF;
1232  term.c_cflag |= PARENB;
1233 
1234  try
1235  {
1236  /* Attempt to acquire device attributes */
1237  if(tcgetattr(_sick_fd,&term) < 0)
1238  {
1239  throw SickIOException("SickPLS::_setTerminalBaud: Unable to get device attributes!");
1240  }
1241 
1242  /* Switch on the baud rate */
1243  switch(baud_rate)
1244  {
1245  case SICK_BAUD_9600:
1246  {
1247  cfmakeraw(&term);
1248 
1249  term.c_iflag |= INPCK;
1250  term.c_iflag &= ~IXOFF;
1251  term.c_cflag |= PARENB;
1252 
1253  cfsetispeed(&term,B9600);
1254  cfsetospeed(&term,B9600);
1255  break;
1256  }
1257  case SICK_BAUD_19200:
1258  {
1259  cfmakeraw(&term);
1260 
1261  term.c_iflag |= INPCK;
1262  term.c_iflag &= ~IXOFF;
1263  term.c_cflag |= PARENB;
1264 
1265  cfsetispeed(&term,B19200);
1266  cfsetospeed(&term,B19200);
1267  break;
1268  }
1269  case SICK_BAUD_38400:
1270  {
1271  cfmakeraw(&term);
1272 
1273  term.c_iflag |= INPCK;
1274  term.c_iflag &= ~IXOFF;
1275  term.c_cflag |= PARENB;
1276 
1277  cfsetispeed(&term,B38400);
1278  cfsetospeed(&term,B38400);
1279  break;
1280  }
1281  case SICK_BAUD_500K:
1282  {
1283  cfmakeraw(&term);
1284 
1285  term.c_iflag |= INPCK;
1286  term.c_iflag &= ~IXOFF;
1287  term.c_cflag |= PARENB;
1288 
1289  cfsetispeed(&term,B500000);
1290  cfsetospeed(&term,B500000);
1291  break;
1292  }
1293  default:
1294  throw SickIOException("SickPLS::_setTerminalBaud: Unknown baud rate!");
1295  }
1296 
1297  /* Attempt to set the device attributes */
1298  if(tcsetattr(_sick_fd,TCSAFLUSH,&term) < 0 )
1299  {
1300  throw SickIOException("SickPLS::_setTerminalBaud: Unable to set device attributes!");
1301  }
1302 
1303  /* Buffer the rate locally */
1304  _curr_session_baud = baud_rate;
1305 
1306  /* Attempt to flush the I/O buffers */
1308 
1309  } // try
1310 
1311  /* Catch an IO exception */
1312  catch(SickIOException sick_io_exception)
1313  {
1314  std::cerr << sick_io_exception.what() << std::endl;
1315  throw;
1316  }
1317 
1318  /* Catch an IO exception */
1319  catch(SickThreadException sick_thread_exception)
1320  {
1321  std::cerr << sick_thread_exception.what() << std::endl;
1322  throw;
1323  }
1324 
1325  /* A sanity check */
1326  catch(...)
1327  {
1328  std::cerr << "SickPLS::_setTerminalBaud: Unknown exception!!!" << std::endl;
1329  throw;
1330  }
1331 
1332 }
1333 
1334 
1335 
1339 void SickPLS::_getSickErrors( unsigned int * const num_sick_errors, uint8_t * const error_type_buffer,
1340  uint8_t * const error_num_buffer ) throw( SickTimeoutException, SickIOException, SickThreadException )
1341 {
1342 
1343  SickPLSMessage message, response;
1344 
1345  int payload_length;
1346  uint8_t payload_buffer[SickPLSMessage::MESSAGE_PAYLOAD_MAX_LENGTH] = {0};
1347 
1348  /* The command to request PLS status */
1349  payload_buffer[0] = 0x32;
1350 
1351  /* Build the request message */
1352  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,1);
1353 
1354  try
1355  {
1356 
1357  /* Send the status request and get a reply */
1359 
1360  }
1361 
1362  /* Catch any timeout exceptions */
1363  catch(SickTimeoutException &sick_timeout_exception)
1364  {
1365  std::cerr << sick_timeout_exception.what() << std::endl;
1366  throw;
1367  }
1368 
1369  /* Catch any I/O exceptions */
1370  catch(SickIOException &sick_io_exception)
1371  {
1372  std::cerr << sick_io_exception.what() << std::endl;
1373  throw;
1374  }
1375 
1376  /* Catch any thread exceptions */
1377  catch(SickThreadException &sick_thread_exception)
1378  {
1379  std::cerr << sick_thread_exception.what() << std::endl;
1380  throw;
1381  }
1382 
1383  /* Catch anything else */
1384  catch(...)
1385  {
1386  std::cerr << "SickPLS::_getSickErrors: Unknown exception!!!" << std::endl;
1387  throw;
1388  }
1389 
1390  /* Extract the payload_length */
1391  payload_length = response.GetPayloadLength();
1392 
1393  /* Compute the number of errors */
1394  double num_errors = ((payload_length-2)/((double)2));
1395 
1396  /* Assign the number of errors if necessary */
1397  if (num_sick_errors)
1398  {
1399  *num_sick_errors = (unsigned int)num_errors;
1400  }
1401 
1402  /* Populate the return buffers with the error data */
1403  for (unsigned int i = 0, k = 1; i < (unsigned int)num_errors && (error_type_buffer || error_num_buffer); i++)
1404  {
1405 
1406  /* Check if the error type has been requested */
1407  if (error_type_buffer)
1408  {
1409  error_type_buffer[i] = payload_buffer[k];
1410  }
1411  k++;
1412 
1413  /* Check if the error number has been requested */
1414  if (error_num_buffer)
1415  {
1416  error_num_buffer[i] = payload_buffer[k];
1417  }
1418  k++;
1419 
1420  }
1421 
1422 }
1423 
1424 
1425 
1431 {
1432 
1433  /* Assign the password for entering installation mode */
1434  uint8_t sick_password[9] = DEFAULT_SICK_PLS_SICK_PASSWORD;
1435 
1436  /* Check if mode should be changed */
1438  {
1439 
1440  try
1441  {
1442 
1443  /* Attempt to switch modes! */
1445 
1446  }
1447 
1448  /* Catch any config exceptions */
1449  catch(SickConfigException &sick_config_exception)
1450  {
1451  std::cerr << sick_config_exception.what() << std::endl;
1452  throw;
1453  }
1454 
1455  /* Catch any timeout exceptions */
1456  catch(SickTimeoutException &sick_timeout_exception)
1457  {
1458  std::cerr << sick_timeout_exception.what() << std::endl;
1459  throw;
1460  }
1461 
1462  /* Catch any I/O exceptions */
1463  catch(SickIOException &sick_io_exception)
1464  {
1465  std::cerr << sick_io_exception.what() << std::endl;
1466  throw;
1467  }
1468 
1469  /* Catch any thread exceptions */
1470  catch(SickThreadException &sick_thread_exception)
1471  {
1472  std::cerr << sick_thread_exception.what() << std::endl;
1473  throw;
1474  }
1475 
1476  /* Catch anything else */
1477  catch(...)
1478  {
1479  std::cerr << "SickPLS::_setSickOpModeInstallation: Unknown exception!!!" << std::endl;
1480  throw;
1481  }
1482 
1483  /* Assign the new operating mode */
1485  }
1486 
1487 }
1488 
1494 {
1495 
1496  /* Check if mode should be changed */
1498  {
1499 
1500  std::cout << "\tAttempting to enter diagnostic mode..." << std::endl;
1501 
1502  try
1503  {
1504 
1505  /* Attempt to switch modes! */
1507 
1508  }
1509 
1510  /* Catch any config exceptions */
1511  catch(SickConfigException &sick_config_exception)
1512  {
1513  std::cerr << sick_config_exception.what() << std::endl;
1514  throw;
1515  }
1516 
1517  /* Catch any timeout exceptions */
1518  catch(SickTimeoutException &sick_timeout_exception)
1519  {
1520  std::cerr << sick_timeout_exception.what() << std::endl;
1521  throw;
1522  }
1523 
1524  /* Catch any I/O exceptions */
1525  catch(SickIOException &sick_io_exception)
1526  {
1527  std::cerr << sick_io_exception.what() << std::endl;
1528  throw;
1529  }
1530 
1531  /* Catch any thread exceptions */
1532  catch(SickThreadException &sick_thread_exception)
1533  {
1534  std::cerr << sick_thread_exception.what() << std::endl;
1535  throw;
1536  }
1537 
1538  /* Catch anything else */
1539  catch(...)
1540  {
1541  std::cerr << "SickPLS::_setSickOpModeInstallation: Unknown exception!!!" << std::endl;
1542  throw;
1543  }
1544 
1545  /* Assign the new operating mode */
1547 
1548  std::cout << "Success!" << std::endl;
1549 
1550  }
1551 
1552 }
1553 
1559 {
1560 
1561  /* Check if mode should be changed */
1563  {
1564 
1565  try
1566  {
1567 
1568  /* Attempt to switch operating mode */
1570 
1571  }
1572 
1573  /* Catch any config exceptions */
1574  catch(SickConfigException &sick_config_exception)
1575  {
1576  std::cerr << sick_config_exception.what() << std::endl;
1577  throw;
1578  }
1579 
1580  /* Catch any timeout exceptions */
1581  catch(SickTimeoutException &sick_timeout_exception)
1582  {
1583  std::cerr << sick_timeout_exception.what() << std::endl;
1584  throw;
1585  }
1586 
1587  /* Catch any I/O exceptions */
1588  catch(SickIOException &sick_io_exception)
1589  {
1590  std::cerr << sick_io_exception.what() << std::endl;
1591  throw;
1592  }
1593 
1594  /* Catch any thread exceptions */
1595  catch(SickThreadException &sick_thread_exception)
1596  {
1597  std::cerr << sick_thread_exception.what() << std::endl;
1598  throw;
1599  }
1600 
1601  /* Catch anything else */
1602  catch(...)
1603  {
1604  std::cerr << "SickPLS::_setSickOpModeMonitorRequestValues: Unknown exception!!!" << std::endl;
1605  throw;
1606  }
1607 
1608  /* Assign the new operating mode */
1610 
1611  }
1612 
1613 }
1614 
1620 {
1621 
1622  /* Check if mode should be changed */
1624  {
1625 
1626  std::cout << "\tRequesting measured value data stream..." << std::endl;
1627 
1628  try
1629  {
1630 
1631  /* Attempt to switch modes */
1633 
1634  }
1635 
1636  /* Catch any config exceptions */
1637  catch(SickConfigException &sick_config_exception)
1638  {
1639  std::cerr << sick_config_exception.what() << std::endl;
1640  throw;
1641  }
1642 
1643  /* Catch any timeout exceptions */
1644  catch(SickTimeoutException &sick_timeout_exception)
1645  {
1646  std::cerr << sick_timeout_exception.what() << std::endl;
1647  throw;
1648  }
1649 
1650  /* Catch any I/O exceptions */
1651  catch(SickIOException &sick_io_exception)
1652  {
1653  std::cerr << sick_io_exception.what() << std::endl;
1654  throw;
1655  }
1656 
1657  /* Catch any thread exceptions */
1658  catch(SickThreadException &sick_thread_exception)
1659  {
1660  std::cerr << sick_thread_exception.what() << std::endl;
1661  throw;
1662  }
1663 
1664  /* Catch anything else */
1665  catch(...)
1666  {
1667  std::cerr << "SickPLS::_setSickOpModeMonitorStreamValues: Unknown exception!!!" << std::endl;
1668  throw;
1669  }
1670 
1671  /* Assign the new operating mode */
1673 
1674  std::cout << "\t\tData stream started!" << std::endl;
1675 
1676  }
1677 
1678 }
1679 
1680 
1686 void SickPLS::_switchSickOperatingMode( const uint8_t sick_mode, const uint8_t * const mode_params )
1688 {
1689 
1690  SickPLSMessage message,response;
1691 
1692  uint8_t payload_buffer[SickPLSMessage::MESSAGE_PAYLOAD_MAX_LENGTH] = {0};
1693  uint16_t num_partial_scans = 0;
1694 
1695  /* Construct the correct switch mode packet */
1696  payload_buffer[0] = 0x20;
1697  payload_buffer[1] = sick_mode;
1698 
1699  switch(sick_mode)
1700  {
1701 
1703 
1704  /* Make sure the params are defined */
1705  if(mode_params == NULL)
1706  {
1707  throw SickConfigException("SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1708  }
1709 
1710  memcpy(&payload_buffer[2],mode_params,8); //Copy password
1711  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,10);
1712  break;
1713 
1715  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,2);
1716  break;
1717 
1719  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,2);
1720  break;
1721 
1723  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,2);
1724  break;
1725 
1727  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,2);
1728  break;
1729 
1731  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,2);
1732  break;
1733 
1735  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,2);
1736  break;
1737 
1739  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,2);
1740  break;
1741 
1743 
1744  /* Make sure the params are defined */
1745  if(mode_params == NULL)
1746  {
1747  throw SickConfigException("SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1748  }
1749 
1750  payload_buffer[2] = *mode_params;
1751  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,3);
1752  break;
1753 
1755 
1756  /* Make sure the params are defined */
1757  if(mode_params == NULL)
1758  {
1759  throw SickConfigException("SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1760  }
1761 
1762  memcpy(&payload_buffer[2],mode_params,2); //Begin range
1763  memcpy(&payload_buffer[4],&mode_params[2],2); //End range
1764  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,6);
1765  break;
1766 
1768 
1769  /* Make sure the params are defined */
1770  if(mode_params == NULL)
1771  {
1772  throw SickConfigException("SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1773  }
1774 
1775  payload_buffer[2] = mode_params[0]; //Sample size
1776  memcpy(&payload_buffer[3],&mode_params[1],2); //Begin mean range
1777  memcpy(&payload_buffer[5],&mode_params[3],2); //End mean range
1778  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,7);
1779  break;
1780 
1782 
1783  /* Make sure the params are defined */
1784  if(mode_params == NULL)
1785  {
1786  throw SickConfigException("SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1787  }
1788 
1789  memcpy(&payload_buffer[2],mode_params,2); //Start
1790  memcpy(&payload_buffer[4],&mode_params[2],2); //End
1791  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,6);
1792  break;
1793 
1795  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,2);
1796  break;
1797 
1799 
1800  /* Make sure the params are defined */
1801  if(mode_params == NULL)
1802  {
1803  throw SickConfigException("SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1804  }
1805 
1806  /* Get the number of partial scans (between 1 and 5) */
1807  memcpy(&num_partial_scans,mode_params,2);
1808 
1809  /* Setup the command packet */
1810  memcpy(&payload_buffer[2],mode_params,num_partial_scans*4+2);
1811  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,num_partial_scans*4+4);
1812  break;
1813 
1815 
1816  /* Make sure the params are defined */
1817  if(mode_params == NULL)
1818  {
1819  throw SickConfigException("SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1820  }
1821 
1822  /* Get the number of partial scans (between 1 and 5) */
1823  memcpy(&num_partial_scans,mode_params,2);
1824 
1825  /* Setup the command packet */
1826  memcpy(&payload_buffer[2],mode_params,num_partial_scans*4+2);
1827  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,num_partial_scans*4+4);
1828  break;
1829 
1831  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,2);
1832  break;
1833 
1835 
1836  /* Make sure the params are defined */
1837  if(mode_params == NULL)
1838  {
1839  throw SickConfigException("SickPLS::_switchSickOperatingMode - Requested mode requires parameters!");
1840  }
1841 
1842  memcpy(&payload_buffer[2],mode_params,2); //Start
1843  memcpy(&payload_buffer[4],&mode_params[2],2); //End
1844  message.BuildMessage(DEFAULT_SICK_PLS_SICK_ADDRESS,payload_buffer,6);
1845  break;
1846 
1847  case SICK_OP_MODE_UNKNOWN:
1848  //Let this case go straight to default
1849 
1850  default:
1851  throw SickConfigException("SickPLS::_switchSickOperatingMode: Unrecognized operating mode!");
1852  }
1853 
1854  // message.Print();
1855 
1856  try
1857  {
1858 
1859  /* Attempt to send the message and get the reply */
1860  _sendMessageAndGetReply(message,
1861  response,
1864 
1865  }
1866 
1867  /* Catch any timeout exceptions */
1868  catch(SickTimeoutException &sick_timeout_exception)
1869  {
1870  std::cerr << sick_timeout_exception.what() << std::endl;
1871  throw;
1872  }
1873 
1874  /* Catch any I/O exceptions */
1875  catch(SickIOException &sick_io_exception)
1876  {
1877  std::cerr << sick_io_exception.what() << std::endl;
1878  throw;
1879  }
1880 
1881  /* Catch any thread exceptions */
1882  catch(SickThreadException &sick_thread_exception)
1883  {
1884  std::cerr << sick_thread_exception.what() << std::endl;
1885  throw;
1886  }
1887 
1888  /* Catch anything else */
1889  catch(...)
1890  {
1891  std::cerr << "SickPLS::_switchSickOperatingMode: Unknown exception!!!" << std::endl;
1892  throw;
1893  }
1894 
1895  /* Reset the buffer */
1896  memset(payload_buffer,0,sizeof(payload_buffer));
1897 
1898  /* Obtain the response payload */
1899  response.GetPayload(payload_buffer);
1900 
1901  /* Make sure the reply was expected */
1902  if(payload_buffer[1] != 0x00)
1903  {
1904  throw SickConfigException("SickPLS::_switchSickOperatingMode: configuration request failed!");
1905  }
1906 
1907 }
1908 
1914 void SickPLS::_parseSickScanProfileB0( const uint8_t * const src_buffer, sick_pls_scan_profile_b0_t &sick_scan_profile ) const
1915 {
1916 
1917  /* Read block A, the number of measurments */
1918  sick_scan_profile.sick_num_measurements = src_buffer[0] + 256*(src_buffer[1] & 0x03);
1919 
1920  /* Check whether this is a partial scan */
1921  sick_scan_profile.sick_partial_scan_index = ((src_buffer[1] & 0x18) >> 3);
1922 
1923  /* Extract the measurements and Field values (if there are any) */
1924  _extractSickMeasurementValues(&src_buffer[2],
1925  sick_scan_profile.sick_num_measurements,
1926  sick_scan_profile.sick_measurements);
1927 
1928  /* If the Sick is pulling real-time indices then pull them too */
1929 
1930  // /* Buffer the Sick telegram index */
1931  // sick_scan_profile.sick_telegram_index = src_buffer[data_offset];
1932 
1933 }
1934 
1935 
1936 
1946 void SickPLS::_extractSickMeasurementValues( const uint8_t * const byte_sequence,
1947  const uint16_t num_measurements,
1948  uint16_t * const measured_values) const
1949 {
1950  /* Extract the range and Field values */
1951  for(unsigned int i = 0; i < num_measurements; i++)
1952  {
1953  measured_values[i] = byte_sequence[i*2] + 256*(byte_sequence[i*2+1] & 0x1F);
1954  }
1955 }
1956 
1961 bool SickPLS::_validSickScanAngle( const sick_pls_scan_angle_t sick_scan_angle ) const
1962 {
1963 
1964  /* Check the given Sick scan angle */
1965  if (sick_scan_angle != SICK_SCAN_ANGLE_180 )
1966  {
1967 
1968  return false;
1969  }
1970 
1971  /* Valid */
1972  return true;
1973 }
1974 
1979 bool SickPLS::_validSickScanResolution( const sick_pls_scan_resolution_t sick_scan_resolution ) const
1980 {
1981 
1982  /* Check the given Sick scan resolution value */
1983  if (sick_scan_resolution != SICK_SCAN_RESOLUTION_50)
1984  {
1985  return false;
1986  }
1987 
1988  /* Valid */
1989  return true;
1990 }
1991 
1992 
1993 
1994 
2000 sick_pls_baud_t SickPLS::_baudToSickBaud( const int baud_rate ) const
2001 {
2002 
2003  switch(baud_rate)
2004  {
2005  case B9600:
2006  return SICK_BAUD_9600;
2007  case B19200:
2008  return SICK_BAUD_19200;
2009  case B38400:
2010  return SICK_BAUD_38400;
2011  case B500000:
2012  return SICK_BAUD_500K;
2013  default:
2014  std::cerr << "Unexpected baud rate!" << std::endl;
2015  return SICK_BAUD_9600;
2016  }
2017 
2018 }
2019 
2020 
2021 
2022 } //namespace SickToolbox
sick_pls_baud_t _desired_session_baud
Definition: SickPLS.hh:285
void _recvMessage(SickPLSMessage &sick_message, const unsigned int timeout_value) const
0.50 degree angular resolution
Definition: SickPLS.hh:76
static sick_pls_scan_resolution_t IntToSickScanResolution(const int scan_resolution_int)
Converts integer to corresponding Sick PLS scan resolution.
Definition: SickPLS.cc:665
void ResetSick()
Reset the Sick PLS active field values NOTE: Considered successful if the PLS ready message is receiv...
Definition: SickPLS.cc:525
void AcquireDataStream()
Acquires a lock on the data stream.
Defines simple utility functions for working with the Sick LMS 2xx laser range finder units...
uint16_t sick_num_measurements
Number of measurements.
Definition: SickPLS.hh:191
void _setSickOpModeMonitorRequestValues()
Sets the device to monitor mode and tells it to send values only upon request.
Definition: SickPLS.cc:1557
unsigned int GetPayloadLength() const
Definition: SickMessage.hh:68
#define B500000
Definition: SickPLS.cc:35
Streams measured values with associated flags.
Definition: SickPLS.hh:121
sick_pls_baud_t
Defines available Sick PLS baud rates.
Definition: SickPLS.hh:134
uint16_t sick_scan_angle
Sick scanning angle (deg)
Definition: SickPLS.hh:154
SickPLS(const std::string sick_device_path)
Primary constructor.
Definition: SickPLS.cc:46
#define DEFAULT_SICK_PLS_SICK_SWITCH_MODE_TIMEOUT
Can take the Sick LD up to 3 seconds to reply (usecs)
Definition: SickPLS.hh:35
Streams mean values from a sample size of n consecutive scans.
Definition: SickPLS.hh:118
void _setTerminalBaud(const sick_pls_baud_t sick_baud)
Sets the local terminal baud rate.
Definition: SickPLS.cc:1225
Contains some simple exception classes.
SickPLS::sick_pls_measuring_units_t GetSickMeasuringUnits() const
Gets the current Sick PLS measuring units.
Definition: SickPLS.cc:376
void _setSickOpModeDiagnostic()
Sets the device to diagnostic mode.
Definition: SickPLS.cc:1492
Streams minimum measured values for each segment in a sub-range.
Definition: SickPLS.hh:124
void _parseSickScanProfileB0(const uint8_t *const src_buffer, sick_pls_scan_profile_b0_t &sick_scan_profile) const
Parses a byte sequence into a scan profile corresponding to message B0.
Definition: SickPLS.cc:1914
uint16_t sick_scan_resolution
Sick angular resolution (1/100 deg)
Definition: SickPLS.hh:155
uint8_t sick_operating_mode
Sick operating mode.
Definition: SickPLS.hh:157
void _switchSickOperatingMode(const uint8_t sick_mode, const uint8_t *const mode_params=NULL)
Attempts to switch the operating mode of the Sick PLS.
Definition: SickPLS.cc:1686
~SickPLS()
Destructor.
Definition: SickPLS.cc:69
sick_pls_status_t
Defines the status of the Sick PLS unit.
Definition: SickPLS.hh:95
static sick_pls_baud_t StringToSickBaud(const std::string baud_str)
Converts string to corresponding Sick PLS baud.
Definition: SickPLS.cc:738
void SetDataStream(const unsigned int sick_fd)
A method for setting/changing the current data stream.
static sick_pls_scan_resolution_t DoubleToSickScanResolution(const double scan_resolution_double)
Converts double to corresponding Sick PLS scan resolution.
Definition: SickPLS.cc:682
A class for monitoring the receive buffer when interfacing with a Sick PLS LIDAR. ...
void _flushTerminalBuffer()
Flushes terminal I/O buffers.
Definition: SickPLS.cc:916
void ReleaseDataStream()
Releases a lock on the data stream.
double GetSickScanResolution() const
Gets the current angular resolution.
Definition: SickPLS.cc:356
static std::string SickStatusToString(const sick_pls_status_t sick_status)
Converts the Sick PLS status code to a string.
Definition: SickPLS.cc:754
#define DEFAULT_SICK_PLS_SICK_PASSWORD
Password for entering installation mode.
Definition: SickPLS.hh:33
A structure for aggregating the data that collectively define the baud config.
Definition: SickPLS.hh:174
Streams measured range from a scan and sub-range of reflectivity values.
Definition: SickPLS.hh:126
Definition of class SickPLSMessage.
bool _validSickScanResolution(const sick_pls_scan_resolution_t sick_scan_resolution) const
Indicates whether the given scan resolution is defined.
Definition: SickPLS.cc:1979
virtual const char * what() const
From the standard exception library.
static std::string SickMeasuringUnitsToString(const sick_pls_measuring_units_t sick_units)
Converts the Sick PLS measurement units to a corresponding string.
Definition: SickPLS.cc:824
struct termios _old_term
Definition: SickPLS.hh:297
void _setSickOpModeMonitorStreamValues()
Sets the device to monitor mode and tells it to stream measured values.
Definition: SickPLS.cc:1618
std::string GetSickDevicePath() const
Gets the Sick PLS device path.
Definition: SickPLS.cc:328
A structure for aggregating the data that define a scan profile obtained from reply B0 (See page 49 T...
Definition: SickPLS.hh:190
static std::string SickOperatingModeToString(const sick_pls_operating_mode_t sick_operating_mode)
Converts the Sick operating mode to a corresponding string.
Definition: SickPLS.cc:772
#define DEFAULT_SICK_PLS_SICK_MESSAGE_TIMEOUT
The max time to wait for a message reply (usecs)
Definition: SickPLS.hh:34
uint16_t sick_measurements[SICK_MAX_NUM_MEASUREMENTS]
Range/reflectivity measurement buffer.
Definition: SickPLS.hh:192
uint8_t GetCommandCode() const
Sends min vertical distance to object when detected.
Definition: SickPLS.hh:115
#define DEFAULT_SICK_PLS_BYTE_INTERVAL
Minimum time in microseconds between transmitted bytes.
Definition: SickPLS.hh:37
#define DEFAULT_SICK_PLS_SICK_ADDRESS
Sick PLS default serial address.
Definition: SickPLS.hh:32
void _teardownConnection()
Closes the data connection associated with the device.
Definition: SickPLS.cc:890
static std::string SickBaudToString(const sick_pls_baud_t baud_rate)
Converts Sick PLS baud to a corresponding string.
Definition: SickPLS.cc:692
Sends the min measured values when object is detected.
Definition: SickPLS.hh:113
void GetPayload(uint8_t *const payload_buffer) const
Get the payload contents as a sequence of well-formed bytes.
Definition: SickMessage.hh:156
uint8_t sick_partial_scan_index
Indicates the start angle of the scan (This is useful for partial scans)
Definition: SickPLS.hh:195
Streams all measured values in a scan.
Definition: SickPLS.hh:116
Scanning angle of 180 degrees.
Definition: SickPLS.hh:66
void _extractSickMeasurementValues(const uint8_t *const byte_sequence, const uint16_t num_measurements, uint16_t *const measured_values) const
Extracts the measured values (w/ flags) that were returned by the device.
Definition: SickPLS.cc:1946
Sends measured range values on request (i.e. when polled)
Definition: SickPLS.hh:117
sick_pls_measuring_units_t
Defines the available Sick PLS measured value units.
Definition: SickPLS.hh:84
sick_pls_baud_t _curr_session_baud
Definition: SickPLS.hh:282
Provides an abstract parent for all Sick LIDAR devices.
Definition: SickLIDAR.hh:53
sick_pls_operating_mode_t GetSickOperatingMode() const
Gets the current Sick PLS operating mode.
Definition: SickPLS.cc:392
void _setSessionBaud(const sick_pls_baud_t baud_rate)
Sets the baud rate for the current communication session.
Definition: SickPLS.cc:1076
bool _testSickBaud(const sick_pls_baud_t baud_rate)
Attempts to detect whether the PLS is operating at the given baud rate.
Definition: SickPLS.cc:1153
Streams mean values over requested subrange.
Definition: SickPLS.hh:120
void _setSickOpModeInstallation()
Sets the device to installation mode.
Definition: SickPLS.cc:1429
bool _validSickScanAngle(const sick_pls_scan_angle_t sick_scan_angle) const
Indicates whether the given scan angle is defined.
Definition: SickPLS.cc:1961
double GetSickScanAngle() const
Gets the current scan angle of the device.
Definition: SickPLS.cc:338
#define DEFAULT_SICK_PLS_SICK_BAUD
Initial baud rate of the PLS (whatever is set in flash)
Definition: SickPLS.hh:30
void GetSickScan(unsigned int *const measurement_values, unsigned int &num_measurement_values)
Returns the most recent measured values obtained by the Sick PLS.
Definition: SickPLS.cc:424
Sick outputs navigation data records.
Definition: SickPLS.hh:125
sick_pls_operating_status_t _sick_operating_status
Definition: SickPLS.hh:289
sick_pls_scan_angle_t
Defines the scan angle for the Sick PLS.
Definition: SickPLS.hh:64
std::string _sick_device_path
Definition: SickPLS.hh:279
void _setupConnection()
Attempts to open a I/O stream using the device path given at object instantiation.
Definition: SickPLS.cc:841
Defines a class for monitoring the receive buffer when interfacing w/ a Sick PLS laser range finder...
Measured values are in centimeters.
Definition: SickPLS.hh:87
A class to represent all messages sent to and from the Sick PLS.
virtual void _sendMessageAndGetReply(const SICK_MSG_CLASS &send_message, SICK_MSG_CLASS &recv_message, const uint8_t *const byte_sequence, const unsigned int byte_sequence_length, const unsigned int byte_interval, const unsigned int timeout_value, const unsigned int num_tries)
Definition: SickLIDAR.hh:405
A structure for aggregating the data that collectively defines the operating status of the device...
Definition: SickPLS.hh:153
sick_pls_operating_mode_t
Defines the operating modes supported by Sick PLS. See page 41 of the PLS telegram manual for additio...
Definition: SickPLS.hh:106
Definition of class SickPLS. Code by Jason C. Derenick and Thomas H. Miller. Contact derenick(at)lehi...
Installation mode for writing EEPROM.
Definition: SickPLS.hh:110
void BuildMessage(uint8_t dest_address, const uint8_t *const payload_buffer, const unsigned int payload_length)
Consructs a message object from given parameter values.
std::string GetSickStatusAsString() const
Acquire the Sick PLS&#39;s status as a printable string.
Definition: SickPLS.cc:611
sick_pls_scan_resolution_t
Defines the available resolution settings for the Sick PLS.
Definition: SickPLS.hh:74
sick_pls_baud_t _baudToSickBaud(const int baud_rate) const
Converts a termios baud to an equivalent Sick baud.
Definition: SickPLS.cc:2000
static sick_pls_scan_angle_t IntToSickScanAngle(const int scan_angle_int)
Converts integer to corresponding Sick PLS scan angle.
Definition: SickPLS.cc:648
Thrown instance where the driver can&#39;t read,write,drain,flush,... the buffers.
void _sendMessageAndGetReply(const SickPLSMessage &sick_send_message, SickPLSMessage &sick_recv_message, const unsigned int timeout_value, const unsigned int num_tries)
Sends a message and searches for the corresponding reply.
Definition: SickPLS.cc:962
void Uninitialize()
Uninitializes the PLS by putting it in a mode where it stops streaming data, and returns it to the de...
Definition: SickPLS.cc:253
#define DEFAULT_SICK_PLS_NUM_TRIES
The max number of tries before giving up on a request.
Definition: SickPLS.hh:39
Streams measured values of partial scan directly after measurement.
Definition: SickPLS.hh:122
static sick_pls_baud_t IntToSickBaud(const int baud_int)
Converts integer to corresponding Sick PLS baud.
Definition: SickPLS.cc:715
Streams minimum measured values for each segement.
Definition: SickPLS.hh:112
Thrown when the driver detects (or the Sick reports) an invalid config.
bool Initialize(const sick_pls_baud_t desired_baud_rate)
Attempts to initialize the Sick PLS and then sets communication at at the given baud rate...
Definition: SickPLS.cc:99
uint8_t sick_measuring_units
Sick measuring units {cm,mm}.
Definition: SickPLS.hh:159
Diagnostic mode for testing purposes.
Definition: SickPLS.hh:111
Makes handling timeouts much easier.
sick_pls_baud_status_t _sick_baud_status
Definition: SickPLS.hh:293
Thrown when error occurs during thread initialization, and uninitialization.
void _getSickErrors(unsigned int *const num_sick_errors=NULL, uint8_t *const error_type_buffer=NULL, uint8_t *const error_num_buffer=NULL)
Obtains any error codes from the Sick PLS.
Definition: SickPLS.cc:1339


asr_mild_base_laserscanner
Author(s): Aumann Florian, Borella Jocelyn, Dehmani Souheil, Marek Felix, Reckling Reno
autogenerated on Mon Jun 10 2019 12:41:37