Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00039 #include <string>
00040 #include <boost/format.hpp>
00041
00042 #include "ros/console.h"
00043 #include "microstrain_3dmgx2_imu/3dmgx2.h"
00044 #include "log4cxx/logger.h"
00045
00046 std::string getID(microstrain_3dmgx2_imu::IMU &imu)
00047 {
00048 char dev_name[17];
00049 char dev_model_num[17];
00050 char dev_serial_num[17];
00051 char dev_opt[17];
00052 imu.getDeviceIdentifierString(microstrain_3dmgx2_imu::IMU::ID_DEVICE_NAME, dev_name);
00053 imu.getDeviceIdentifierString(microstrain_3dmgx2_imu::IMU::ID_MODEL_NUMBER, dev_model_num);
00054 imu.getDeviceIdentifierString(microstrain_3dmgx2_imu::IMU::ID_SERIAL_NUMBER, dev_serial_num);
00055 imu.getDeviceIdentifierString(microstrain_3dmgx2_imu::IMU::ID_DEVICE_OPTIONS, dev_opt);
00056
00057 char *dev_name_ptr = dev_name;
00058 char *dev_model_num_ptr = dev_model_num;
00059 char *dev_serial_num_ptr = dev_serial_num;
00060
00061 while (*dev_name_ptr == ' ')
00062 dev_name_ptr++;
00063 while (*dev_model_num_ptr == ' ')
00064 dev_model_num_ptr++;
00065 while (*dev_serial_num_ptr == ' ')
00066 dev_serial_num_ptr++;
00067
00068 return (boost::format("%s_%s-%s")%dev_name_ptr%dev_model_num_ptr%dev_serial_num_ptr).str();
00069 }
00070
00071 int main(int argc, char **argv)
00072 {
00073 if (argc < 2 || argc > 3)
00074 {
00075 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");
00076 return 1;
00077 }
00078
00079 bool verbose = (argc == 2);
00080 if (!verbose)
00081 {
00082
00083 log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
00084 logger->setLevel(ros::console::g_level_lookup[ros::console::levels::Error]);
00085 ros::console::notifyLoggerLevelsChanged();
00086 }
00087
00088 microstrain_3dmgx2_imu::IMU imu;
00089
00090 try
00091 {
00092 imu.openPort(argv[1]);
00093 }
00094 catch (microstrain_3dmgx2_imu::Exception& e)
00095 {
00096 fprintf(stderr, "Unable to open IMU at port %s. IMU may be disconnected.\n%s", argv[1], e.what());
00097 return 1;
00098 }
00099
00100 imu.initTime(0.0);
00101
00102 std::string id = getID(imu);
00103
00104 if (verbose)
00105 fprintf(stdout, "IMU Device at port %s has ID: ", argv[1]);
00106 fprintf(stdout, "%s\n", id.c_str());
00107
00108 try
00109 {
00110 imu.closePort();
00111 }
00112 catch (microstrain_3dmgx2_imu::Exception& e)
00113 {
00114 fprintf(stderr, "Exception thrown while stopping IMU.\n%s", e.what());
00115 return 1;
00116 }
00117
00118 return 0;
00119 }