00001 /* 00002 * Copyright (c) 2010, Bosch LLC 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of Bosch LLC nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 //\Author Lukas Marti, Bosch LLC 00031 #ifndef __SMI540__ 00032 #define __SMI540__ 00033 00034 #include <libsub.h> // sub20 device 00035 00036 //Define SMI540 specifics 00037 namespace cmd540 { 00038 //Define MM5 commands 00039 static char chRD_ACT_DATA_64[4] = {0x41, 0x99, 0x00, 0x5C}; 00040 static char chTRIGGER_RESET[4] = {0x61, 0x03, 0x00, 0xE9}; 00041 //Sepecify MM5 Scale Factor - note: Pos is slightly differen from negative 00042 const double fSFACC_inv = 6667; 00043 const double fSFGYRO_inv = 175; 00044 //Define enumerated sensor type 00045 enum eSensorType {eACCEL, eGYRO}; 00046 //Define default sampling rate 00047 const double dDEFAULT_RATE_Hz = 20; 00048 } 00049 00050 //Define measurement output 00051 struct ONESMI540MEAS { 00052 bool bMeasAvailable; //indicates true if a valid measurement is available 00053 double dRateZ; 00054 double dAccX; 00055 double dAccY; 00056 ros::Time dtomeas; //time tag measurement immediately in case of other delays 00057 }; 00058 00059 00061 00065 class Smi540 { 00066 public: 00067 00069 00073 Smi540(); 00075 00078 ~Smi540(); 00079 00081 00085 ONESMI540MEAS GetOneMeas(void); 00086 00087 private: 00088 //subdevice handle 00089 sub_handle fd; 00090 //status flag indicating if subdevice has been opened 00091 bool bSubDeviceOpen; 00092 //status flag indicating if SPI configuration for SMI530/540 has been stored 00093 bool bSubDeviceConfigured; 00094 //Serial number of subdevice 00095 std::string strSerial; 00097 double mm5data_to_int(char, char, cmd540::eSensorType); 00098 }; // class 00099 00100 #endif