get_id.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
39 #include <string>
40 #include <boost/format.hpp>
41 
42 #include "ros/console.h"
44 #include "log4cxx/logger.h"
45 
47 {
48  char dev_name[17];
49  char dev_model_num[17];
50  char dev_serial_num[17];
51  char dev_opt[17];
56 
57  char *dev_name_ptr = dev_name;
58  char *dev_model_num_ptr = dev_model_num;
59  char *dev_serial_num_ptr = dev_serial_num;
60 
61  while (*dev_name_ptr == ' ')
62  dev_name_ptr++;
63  while (*dev_model_num_ptr == ' ')
64  dev_model_num_ptr++;
65  while (*dev_serial_num_ptr == ' ')
66  dev_serial_num_ptr++;
67 
68  return (boost::format("%s_%s-%s")%dev_name_ptr%dev_model_num_ptr%dev_serial_num_ptr).str();
69 }
70 
71 int main(int argc, char **argv)
72 {
73  if (argc < 2 || argc > 3)
74  {
75  fprintf(stderr, "usage: get_id /dev/ttyUSB? [quiet]\nOutputs the device ID of an IMU at that port. Add a second argument for script friendly output.\n");
76  return 1;
77  }
78 
79  bool verbose = (argc == 2);
80  if (!verbose)
81  {
82  // In quiet mode we want to turn off logging levels that go to stdout.
83  log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
84  logger->setLevel(ros::console::g_level_lookup[ros::console::levels::Error]);
86  }
87 
89 
90  try
91  {
92  imu.openPort(argv[1]);
93  }
94  catch (microstrain_3dmgx2_imu::Exception& e)
95  {
96  fprintf(stderr, "Unable to open IMU at port %s. IMU may be disconnected.\n%s", argv[1], e.what());
97  return 1;
98  }
99 
100  imu.initTime(0.0);
101 
102  std::string id = getID(imu);
103 
104  if (verbose)
105  fprintf(stdout, "IMU Device at port %s has ID: ", argv[1]);
106  fprintf(stdout, "%s\n", id.c_str());
107 
108  try
109  {
110  imu.closePort();
111  }
112  catch (microstrain_3dmgx2_imu::Exception& e)
113  {
114  fprintf(stderr, "Exception thrown while stopping IMU.\n%s", e.what());
115  return 1;
116  }
117 
118  return 0;
119 }
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
void openPort(const char *port_name)
Open the port.
Definition: 3dmgx2.cc:113
void closePort()
Close the port.
Definition: 3dmgx2.cc:170
void initTime(double fix_off)
Initialize timing variables.
Definition: 3dmgx2.cc:196
A class for interfacing to the microstrain 3dmgx2 and inertialink IMUs.
Definition: 3dmgx2.h:91
std::string getID(microstrain_3dmgx2_imu::IMU &imu)
Recovers hardware ID from IMU device.
Definition: get_id.cpp:46
int main(int argc, char **argv)
Definition: get_id.cpp:71
bool getDeviceIdentifierString(id_string type, char id[17])
Read one of the device identifier strings.
Definition: 3dmgx2.cc:476
#define ROSCONSOLE_DEFAULT_NAME


microstrain_3dmgx2_imu
Author(s): Jeremy Leibs, Blaise Gassend
autogenerated on Tue Jul 2 2019 19:40:35