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
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 my_logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
00084 my_logger->setLevel(ros::console::g_level_lookup[ros::console::levels::Error]);
00085 }
00086
00087 microstrain_3dmgx2_imu::IMU imu;
00088
00089 try
00090 {
00091 imu.openPort(argv[1]);
00092 }
00093 catch (microstrain_3dmgx2_imu::Exception& e)
00094 {
00095 fprintf(stderr, "Unable to open IMU at port %s. IMU may be disconnected.\n%s", argv[1], e.what());
00096 return 1;
00097 }
00098
00099 imu.initTime(0.0);
00100
00101 std::string id = getID(imu);
00102
00103 if (verbose)
00104 fprintf(stdout, "IMU Device at port %s has ID: ", argv[1]);
00105 fprintf(stdout, "%s\n", id.c_str());
00106
00107 try
00108 {
00109 imu.closePort();
00110 }
00111 catch (microstrain_3dmgx2_imu::Exception& e)
00112 {
00113 fprintf(stderr, "Exception thrown while stopping IMU.\n%s", e.what());
00114 return 1;
00115 }
00116
00117 return 0;
00118 }