print_scans.cpp
Go to the documentation of this file.
1 // this program is just a little test to make sure the laser is working.
3 // it's mostly just to familiarize myself with the sicktoolbox library.
4 // it's heavily lifted from the sicktoolbox lms_simple_app program.
5 //
6 // Copyright (C) 2008, Morgan Quigley
7 //
8 // I am distributing this code under the BSD license:
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 // * Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // * Neither the name of Stanford University nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
32 
33 #include <csignal>
34 extern "C" {
35 // not everyone has <cstdint>
36 #include <stdint.h>
37 }
38 #include <cstdio>
40 using namespace SickToolbox;
41 using namespace std;
42 
43 bool got_ctrlc = false;
44 void ctrlc_handler(int)
45 {
46  got_ctrlc = true;
47 }
48 
49 int main(int argc, char **argv)
50 {
51  if (argc != 3)
52  {
53  printf("Usage: print_scans DEVICE BAUD_RATE\n");
54  return 1;
55  }
56  string lms_dev = argv[1];
58  if (desired_baud == SickLMS2xx::SICK_BAUD_UNKNOWN)
59  {
60  printf("bad baud rate. must be one of {9600, 19200, 38400, 500000}\n");
61  return 1;
62  }
63  signal(SIGINT, ctrlc_handler);
64  uint32_t values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0};
65  uint32_t num_values = 0;
66  SickLMS2xx sick_lms(lms_dev);
67  try
68  {
69  sick_lms.Initialize(desired_baud);
70  }
71  catch (...)
72  {
73  printf("initialize failed! are you using the correct device path?\n");
74  }
75  try
76  {
77  while (!got_ctrlc)
78  {
79  sick_lms.GetSickScan(values, num_values);
80  // print 12 ranges to the console
81  int inc = num_values / 11;
82  printf("%5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d\n",
83  values[0], values[inc],
84  values[2*inc], values[3*inc],
85  values[4*inc], values[5*inc],
86  values[6*inc], values[7*inc],
87  values[8*inc], values[9*inc],
88  values[10*inc], values[num_values-1]);
89  }
90  }
91  catch (...)
92  {
93  printf("woah! error!\n");
94  }
95  try
96  {
97  sick_lms.Uninitialize();
98  }
99  catch (...)
100  {
101  printf("error during uninitialize\n");
102  return 1;
103  }
104  printf("success.\n");
105  return 0;
106 }
107 
void GetSickScan(unsigned int *const measurement_values, unsigned int &num_measurement_values, unsigned int *const sick_field_a_values=NULL, unsigned int *const sick_field_b_values=NULL, unsigned int *const sick_field_c_values=NULL, unsigned int *const sick_telegram_index=NULL, unsigned int *const sick_real_time_scan_index=NULL)
void Initialize(const sick_lms_2xx_baud_t desired_baud_rate, const uint32_t delay=0)
static const uint16_t SICK_MAX_NUM_MEASUREMENTS
static sick_lms_2xx_baud_t StringToSickBaud(const std::string baud_str)


sicktoolbox_wrapper
Author(s): Morgan Quigley
autogenerated on Mon Jun 10 2019 15:03:33