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


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