time_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 <cstdlib>
34 #include <csignal>
35 #include <stdint.h>
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 != 3)
51  {
52  printf("Usage: print_scans DEVICE BAUD_RATE\n");
53  return 1;
54  }
55  string lms_dev = argv[1];
57  if (desired_baud == SickLMS2xx::SICK_BAUD_UNKNOWN)
58  {
59  printf("bad baud rate. must be one of {9600, 19200, 38400, 500000}\n");
60  return 1;
61  }
62  signal(SIGINT, ctrlc_handler);
63  uint32_t values[SickLMS2xx::SICK_MAX_NUM_MEASUREMENTS] = {0};
64  uint32_t num_values = 0;
65  SickLMS2xx sick_lms(lms_dev);
66  try
67  {
68  sick_lms.Initialize(desired_baud);
69  }
70  catch (...)
71  {
72  printf("initialize failed! are you using the correct device path?\n");
73  }
74  try
75  {
76  ros::Time prev_scan_time = ros::Time::now();
77  while (!got_ctrlc)
78  {
79  sick_lms.GetSickScan(values, num_values);
81  double delta = t.toSec() - prev_scan_time.toSec();
82  printf("%f (%f)\n", delta, 1.0 / delta);
83  prev_scan_time = t;
84  }
85  }
86  catch (...)
87  {
88  printf("woah! error!\n");
89  }
90  try
91  {
92  sick_lms.Uninitialize();
93  }
94  catch (...)
95  {
96  printf("error during uninitialize\n");
97  return 1;
98  }
99  printf("success.\n");
100  return 0;
101 }
102 
int main(int argc, char **argv)
Definition: time_scans.cpp:48
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)
bool got_ctrlc
Definition: time_scans.cpp:42
static Time now()
void ctrlc_handler(int)
Definition: time_scans.cpp:43


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