Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __MICC_H__
00013 #define __MICC_H__
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #pragma systemFile
00036
00037 #ifndef __COMMON_H__
00038 #include "common.h"
00039 #endif
00040
00041 #define MICC_I2C_ADDR 0x02
00042
00043 #define MICC_ACC_ANG 0x42
00044
00045 #define MICC_TURN_RATE 0x44
00046
00047 #define MICC_X_ACCEL 0x46
00048 #define MICC_Y_ACCEL 0x48
00049 #define MICC_Z_ACCEL 0x4A
00050
00051 #define MICC_CMD_RESET 0x60
00052 #define MICC_CMD_RANGE_2G 0x61
00053 #define MICC_CMD_RANGE_4G 0x62
00054 #define MICC_CMD_RANGE_8G 0x63
00055
00056 int MICCreadRelativeHeading(tSensors link);
00057 int MICCreadTurnRate(tSensors link);
00058 bool MICCreadAccel(tSensors link, int &x_accel, int &y_accel, int &z_accel);
00059 bool MICCsendCmd(tSensors link, ubyte command);
00060
00061 #define MICCsetRange2G(x) MICCsendCmd(x, MICC_CMD_RANGE_2G)
00062 #define MICCsetRange4G(x) MICCsendCmd(x, MICC_CMD_RANGE_4G)
00063 #define MICCsetRange8G(x) MICCsendCmd(x, MICC_CMD_RANGE_8G)
00064 #define MICCreset(x) MICCsendCmd(x, MICC_CMD_RESET)
00065
00066 tByteArray MICC_I2CRequest;
00067 tByteArray MICC_I2CReply;
00068
00069
00070
00071
00072
00073
00074
00075 int MICCreadRelativeHeading(tSensors link) {
00076 memset(MICC_I2CRequest, 0, sizeof(tByteArray));
00077
00078 MICC_I2CRequest[0] = 2;
00079 MICC_I2CRequest[1] = MICC_I2C_ADDR;
00080 MICC_I2CRequest[2] = MICC_ACC_ANG;
00081
00082 if (!writeI2C(link, MICC_I2CRequest, 2))
00083 return 0;
00084
00085 if (!readI2C(link, MICC_I2CReply, 2))
00086 return 0;
00087
00088
00089 return (MICC_I2CReply[1] << 8) + MICC_I2CReply[0];
00090 }
00091
00092
00093
00094
00095
00096
00097 int MICCreadTurnRate(tSensors link) {
00098 memset(MICC_I2CRequest, 0, sizeof(tByteArray));
00099
00100 MICC_I2CRequest[0] = 2;
00101 MICC_I2CRequest[1] = MICC_I2C_ADDR;
00102 MICC_I2CRequest[2] = MICC_TURN_RATE;
00103
00104 if (!writeI2C(link, MICC_I2CRequest, 2))
00105 return 0;
00106
00107 if (!readI2C(link, MICC_I2CReply, 2))
00108 return 0;
00109
00110
00111 return (MICC_I2CReply[1] << 8) + MICC_I2CReply[0];
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 bool MICCreadAccel(tSensors link, int &x_accel, int &y_accel, int &z_accel) {
00123 memset(MICC_I2CRequest, 0, sizeof(tByteArray));
00124
00125 MICC_I2CRequest[0] = 2;
00126 MICC_I2CRequest[1] = MICC_I2C_ADDR;
00127 MICC_I2CRequest[2] = MICC_X_ACCEL;
00128
00129 if (!writeI2C(link, MICC_I2CRequest, 6))
00130 return false;
00131
00132 if (!readI2C(link, MICC_I2CReply, 6))
00133 return false;
00134
00135
00136 x_accel = (MICC_I2CReply[1] << 8) + MICC_I2CReply[0];
00137 y_accel = (MICC_I2CReply[3] << 8) + MICC_I2CReply[2];
00138 z_accel = (MICC_I2CReply[5] << 8) + MICC_I2CReply[4];
00139 return true;
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149 bool MICCsendCmd(tSensors link, ubyte command) {
00150 memset(MICC_I2CRequest, 0, sizeof(tByteArray));
00151
00152 MICC_I2CRequest[0] = 2;
00153 MICC_I2CRequest[1] = MICC_I2C_ADDR;
00154 MICC_I2CRequest[2] = command;
00155
00156 return writeI2C(link, MICC_I2CRequest, 0);
00157 }
00158
00159 #endif //__MICC_H__
00160
00161
00162
00163
00164
00165