これは MMA7361 3軸アナログ加速度センサ の Nucleo F401RE 用のライブラリです。詳しい説明はLibrary中のReadMe.hに記載しています。文字化けや開けない場合はダウンロードしてみてください。Google Chrome では見れるはずです。

Dependents:   Nucleo_L3GD20_MMA7361_Kalman

Committer:
hirokimineshita
Date:
Fri Sep 30 06:50:24 2016 +0000
Revision:
6:ca882e5e2686
Parent:
5:83a3021f51f8
+a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hirokimineshita 0:ad6f3a862ed5 1 #ifndef _MMA7361_H_20150129_1716_
hirokimineshita 0:ad6f3a862ed5 2 #define _MMA7361_H_20150129_1716_
hirokimineshita 0:ad6f3a862ed5 3
hirokimineshita 0:ad6f3a862ed5 4 #define def -1
hirokimineshita 0:ad6f3a862ed5 5 #define x_axis 0
hirokimineshita 0:ad6f3a862ed5 6 #define y_axis 1
hirokimineshita 0:ad6f3a862ed5 7 #define z_axis 2
hirokimineshita 0:ad6f3a862ed5 8 #define A00 31356
hirokimineshita 0:ad6f3a862ed5 9 #define A10 34040
hirokimineshita 0:ad6f3a862ed5 10 #define A20 28639
hirokimineshita 0:ad6f3a862ed5 11 #define A01 32717
hirokimineshita 0:ad6f3a862ed5 12 #define A11 33388
hirokimineshita 0:ad6f3a862ed5 13 #define A21 31475
hirokimineshita 0:ad6f3a862ed5 14 #define G00 15633
hirokimineshita 0:ad6f3a862ed5 15 #define G10 15797
hirokimineshita 0:ad6f3a862ed5 16 #define G20 15187
hirokimineshita 0:ad6f3a862ed5 17 #define G01 5416
hirokimineshita 0:ad6f3a862ed5 18 #define G11 3220
hirokimineshita 0:ad6f3a862ed5 19 #define G21 7131
hirokimineshita 0:ad6f3a862ed5 20 #define PI 3.1415926535
hirokimineshita 4:c3d863eb7f91 21 #define THHO 0.0000000001
hirokimineshita 0:ad6f3a862ed5 22
hirokimineshita 5:83a3021f51f8 23 /** This progrum is to be easy to control MMA7361 analog sensor\n
hirokimineshita 5:83a3021f51f8 24 * site http://akizukidenshi.com/catalog/g/gM-06725/
hirokimineshita 5:83a3021f51f8 25 */
hirokimineshita 0:ad6f3a862ed5 26 class mma7361{
hirokimineshita 0:ad6f3a862ed5 27 private:
hirokimineshita 0:ad6f3a862ed5 28 AnalogIn dx;
hirokimineshita 0:ad6f3a862ed5 29 AnalogIn dy;
hirokimineshita 0:ad6f3a862ed5 30 AnalogIn dz;
hirokimineshita 0:ad6f3a862ed5 31 DigitalOut ST;
hirokimineshita 0:ad6f3a862ed5 32 DigitalOut GS;
hirokimineshita 0:ad6f3a862ed5 33 Serial pcdev;
hirokimineshita 0:ad6f3a862ed5 34 int range; //0 : 1.5G 1 : 6.0G
hirokimineshita 0:ad6f3a862ed5 35 int mat[4][3];
hirokimineshita 0:ad6f3a862ed5 36 public:
hirokimineshita 5:83a3021f51f8 37
hirokimineshita 5:83a3021f51f8 38 /** constracta
hirokimineshita 5:83a3021f51f8 39 *
hirokimineshita 5:83a3021f51f8 40 * set all pin number
hirokimineshita 5:83a3021f51f8 41 * @param accelx analog pin which conect to x-axis (default = PA_0)
hirokimineshita 5:83a3021f51f8 42 * @param accely analog pin which conect to y-axis (default = PA_1)
hirokimineshita 5:83a3021f51f8 43 * @param accelz analog pin which conect to z-axis (default = PA_4)
hirokimineshita 5:83a3021f51f8 44 * @param set digital pin which conect to ST (default = PH_0)
hirokimineshita 5:83a3021f51f8 45 * @param set_range digital pin which conect to GS (default = PH_1)
hirokimineshita 5:83a3021f51f8 46 */
hirokimineshita 5:83a3021f51f8 47 mma7361(PinName accelx = PA_0,PinName accely = PA_1,PinName accelz = PA_4,PinName set = PH_0,PinName set_range = PH_1);
hirokimineshita 5:83a3021f51f8 48
hirokimineshita 5:83a3021f51f8 49 /** function
hirokimineshita 5:83a3021f51f8 50 *
hirokimineshita 5:83a3021f51f8 51 * do the calibration, you need to conect terminal (ex.TeraTerm) by USB\n
hirokimineshita 5:83a3021f51f8 52 * the serial port is set in this class, but it's private\n
hirokimineshita 5:83a3021f51f8 53 * please follow the sentence on the terminal\n
hirokimineshita 6:ca882e5e2686 54 * this function set the matrix which use to calculate the gravity\n
hirokimineshita 5:83a3021f51f8 55 * if you don't want to do this or know the data, you can use set_each_num() or set_num() to set matrix
hirokimineshita 5:83a3021f51f8 56 */
hirokimineshita 0:ad6f3a862ed5 57 void calibration();
hirokimineshita 5:83a3021f51f8 58
hirokimineshita 5:83a3021f51f8 59 /** function
hirokimineshita 5:83a3021f51f8 60 *
hirokimineshita 6:ca882e5e2686 61 * this function set the matrix which use to calculate the gravity and the range of sensitivity\n
hirokimineshita 6:ca882e5e2686 62 * the matrix's paramater is this\n
hirokimineshita 6:ca882e5e2686 63 * | A00 A10 A20 | : middle bits (=0G) of each axes when range is 1.5G\n
hirokimineshita 6:ca882e5e2686 64 * | A01 A11 A21 | : middle bits (=0G) of each axes when range is 6.0G\n
hirokimineshita 6:ca882e5e2686 65 * | G00 G10 G20 | : bits/G of each axes when range is 1.5G\n
hirokimineshita 6:ca882e5e2686 66 * | G01 G11 G21 | : bits/G of each axes when range is 6.0G
hirokimineshita 6:ca882e5e2686 67 * @param ax_0_0 A00 in the matrix (=-1:use default = 31356)
hirokimineshita 6:ca882e5e2686 68 * @param ay_0_0 A10 in the matrix (=-1:use default = 34040)
hirokimineshita 6:ca882e5e2686 69 * @param az_0_0 A20 in the matrix (=-1:use default = 28639)
hirokimineshita 6:ca882e5e2686 70 * @param ax_1_0 A01 in the matrix (=-1:use default = 32717)
hirokimineshita 6:ca882e5e2686 71 * @param ay_1_0 A11 in the matrix (=-1:use default = 33388)
hirokimineshita 6:ca882e5e2686 72 * @param az_1_0 A21 in the matrix (=-1:use default = 31475)
hirokimineshita 6:ca882e5e2686 73 * @param gx_0_0 G00 in the matrix (=-1:use default = 15633)
hirokimineshita 6:ca882e5e2686 74 * @param gy_0_0 G10 in the matrix (=-1:use default = 15797)
hirokimineshita 6:ca882e5e2686 75 * @param gz_0_0 G20 in the matrix (=-1:use default = 15187)
hirokimineshita 6:ca882e5e2686 76 * @param gx_1_0 G01 in the matrix (=-1:use default = 5416)
hirokimineshita 6:ca882e5e2686 77 * @param gy_1_0 G11 in the matrix (=-1:use default = 3220)
hirokimineshita 6:ca882e5e2686 78 * @param gz_1_0 G21 in the matrix (=-1:use default = 7131)
hirokimineshita 6:ca882e5e2686 79 * @param new_range range of sensitivity (0:1.5G 1:6.0G default = 0)
hirokimineshita 5:83a3021f51f8 80 */
hirokimineshita 6:ca882e5e2686 81 void set_each_num(int ax_0_0,int ay_0_0,int az_0_0,int ax_1_0,int ay_1_0,int az_1_0,int gx_0_0,int gy_0_0,int gz_0_0,int gx_1_0,int gy_1_0,int gz_1_0,int new_range = 0);
hirokimineshita 6:ca882e5e2686 82
hirokimineshita 6:ca882e5e2686 83 /** function
hirokimineshita 6:ca882e5e2686 84 *
hirokimineshita 6:ca882e5e2686 85 * this function set the matrix which use to calculate the gravity and the range of sensitivity\n
hirokimineshita 6:ca882e5e2686 86 * the matrix's paramater is this\n
hirokimineshita 6:ca882e5e2686 87 * | A00 A10 A20 | : middle bits (=0G) of each axes when range is 1.5G\n
hirokimineshita 6:ca882e5e2686 88 * | A01 A11 A21 | : middle bits (=0G) of each axes when range is 6.0G\n
hirokimineshita 6:ca882e5e2686 89 * | G00 G10 G20 | : bits/G of each axes when range is 1.5G\n
hirokimineshita 6:ca882e5e2686 90 * | G01 G11 G21 | : bits/G of each axes when range is 6.0G
hirokimineshita 6:ca882e5e2686 91 * @param new_mat this matrix means {{A00,A10,A20},{A01,A11,A21},{G00,G10,G20},{G01,G11,G21}}, if elements have the value of -1 then it's value is default
hirokimineshita 6:ca882e5e2686 92 * @param new_range range of sensitivity (0:1.5G 1:6.0G default = 0)
hirokimineshita 6:ca882e5e2686 93 */
hirokimineshita 6:ca882e5e2686 94 void set_num(int (*new_mat)[3],int new_range = 0);
hirokimineshita 6:ca882e5e2686 95
hirokimineshita 6:ca882e5e2686 96 /** function
hirokimineshita 6:ca882e5e2686 97 *
hirokimineshita 6:ca882e5e2686 98 * this function set the range of sensitivity
hirokimineshita 6:ca882e5e2686 99 * @param new_range range of sensitivity (0:1.5G 1:6.0G default = 0)
hirokimineshita 6:ca882e5e2686 100 */
hirokimineshita 6:ca882e5e2686 101 void set_range(int new_range = 0);
hirokimineshita 6:ca882e5e2686 102
hirokimineshita 6:ca882e5e2686 103 /** function
hirokimineshita 6:ca882e5e2686 104 *
hirokimineshita 6:ca882e5e2686 105 * this function set the matrix to default
hirokimineshita 6:ca882e5e2686 106 */
hirokimineshita 0:ad6f3a862ed5 107 void clear_mat();
hirokimineshita 6:ca882e5e2686 108
hirokimineshita 6:ca882e5e2686 109 /** function
hirokimineshita 6:ca882e5e2686 110 *
hirokimineshita 6:ca882e5e2686 111 * this function read the bit data (the result of ADC) of axis (x:x_axis y:y_axis z:z_axis)
hirokimineshita 6:ca882e5e2686 112 * @param axis select what you want to read (x:x_axis y:y_axis z:z_axis)
hirokimineshita 6:ca882e5e2686 113 * @return same as Analog class' read_u16()
hirokimineshita 6:ca882e5e2686 114 */
hirokimineshita 0:ad6f3a862ed5 115 int read_bit(int axis);
hirokimineshita 6:ca882e5e2686 116
hirokimineshita 6:ca882e5e2686 117 /** function
hirokimineshita 6:ca882e5e2686 118 *
hirokimineshita 6:ca882e5e2686 119 * this function read the bit data (the result of ADC) and remove the effect of the gravity of axis (x:x_axis y:y_axis z:z_axis)
hirokimineshita 6:ca882e5e2686 120 * @param axis select what you want to read (x:x_axis y:y_axis z:z_axis)
hirokimineshita 6:ca882e5e2686 121 * @return do Analog class' read_u16() and remove the effect of gravity, data is from matrix
hirokimineshita 6:ca882e5e2686 122 */
hirokimineshita 0:ad6f3a862ed5 123 int read_bit_0(int axis);
hirokimineshita 6:ca882e5e2686 124
hirokimineshita 6:ca882e5e2686 125 /** function
hirokimineshita 6:ca882e5e2686 126 *
hirokimineshita 6:ca882e5e2686 127 * this function read the acceleration by G
hirokimineshita 6:ca882e5e2686 128 * @param axis select what you want to read (x:x_axis y:y_axis z:z_axis)
hirokimineshita 6:ca882e5e2686 129 * @return the acceleration by G
hirokimineshita 6:ca882e5e2686 130 */
hirokimineshita 0:ad6f3a862ed5 131 float read_by_g(int axis);
hirokimineshita 6:ca882e5e2686 132
hirokimineshita 6:ca882e5e2686 133 /** function
hirokimineshita 6:ca882e5e2686 134 *
hirokimineshita 6:ca882e5e2686 135 * this function do the low pass filter by program\n
hirokimineshita 6:ca882e5e2686 136 * this filter use the last bit data and get new bit data when this function is done\n
hirokimineshita 6:ca882e5e2686 137 * so when you use this, do loop if you want to use data from LPF\n
hirokimineshita 6:ca882e5e2686 138 * before you use this function, you should use set_1st_bit() to be short the time which the data be convergence\n
hirokimineshita 6:ca882e5e2686 139 * if you don't use set_1st_bit(), you must through about 300 data
hirokimineshita 6:ca882e5e2686 140 * @param int_bit the pointer of the variable which has acceleration
hirokimineshita 6:ca882e5e2686 141 * @param axis select what you want to do (x:x_axis y:y_axis z:z_axis)
hirokimineshita 6:ca882e5e2686 142 */
hirokimineshita 0:ad6f3a862ed5 143 void low_pass_filter(int *int_bit,int axis);
hirokimineshita 6:ca882e5e2686 144
hirokimineshita 6:ca882e5e2686 145 /** function
hirokimineshita 6:ca882e5e2686 146 *
hirokimineshita 6:ca882e5e2686 147 * show the matrix on terminal
hirokimineshita 6:ca882e5e2686 148 */
hirokimineshita 0:ad6f3a862ed5 149 void show_mat();
hirokimineshita 6:ca882e5e2686 150
hirokimineshita 6:ca882e5e2686 151 /** function
hirokimineshita 6:ca882e5e2686 152 *
hirokimineshita 6:ca882e5e2686 153 * change the acceleration data from bit to G
hirokimineshita 6:ca882e5e2686 154 * @param bit original bit data
hirokimineshita 6:ca882e5e2686 155 * @param axis select what you want to change (x:x_axis y:y_axis z:z_axis)
hirokimineshita 6:ca882e5e2686 156 * @return the acceleration by G
hirokimineshita 6:ca882e5e2686 157 */
hirokimineshita 0:ad6f3a862ed5 158 float bit_to_g(int bit,int axis);
hirokimineshita 6:ca882e5e2686 159
hirokimineshita 6:ca882e5e2686 160 /** function
hirokimineshita 6:ca882e5e2686 161 *
hirokimineshita 6:ca882e5e2686 162 * use before low_pass_filter()\n
hirokimineshita 6:ca882e5e2686 163 * set direction_G to the unti direction of gravity from -1 to be short the time which the data be convergence\n
hirokimineshita 6:ca882e5e2686 164 * read the description of low_pass_filter()
hirokimineshita 6:ca882e5e2686 165 * @param variable the pointer of the variable which will have acceleration
hirokimineshita 6:ca882e5e2686 166 * @param axis select what you want to do (x:x_axis y:y_axis z:z_axis)
hirokimineshita 6:ca882e5e2686 167 * @param direction_G the unti direction of gravity from -1 to be short the time which the data be convergence (no need to be set completely)
hirokimineshita 6:ca882e5e2686 168 */
hirokimineshita 0:ad6f3a862ed5 169 void set_1st_bit(int *variable,int axis,float direction_G);
hirokimineshita 0:ad6f3a862ed5 170
hirokimineshita 6:ca882e5e2686 171 /** function
hirokimineshita 6:ca882e5e2686 172 *
hirokimineshita 6:ca882e5e2686 173 * calculate the rotation acceleration from a_axis to b_axis\n
hirokimineshita 6:ca882e5e2686 174 * if the acceleration is smoller than THHO (0.01G), then the acceleration is 0G
hirokimineshita 6:ca882e5e2686 175 * @param a_value the pointer of the variable which will have acceleration
hirokimineshita 6:ca882e5e2686 176 * @param a_axis select what you want to do (x:x_axis y:y_axis z:z_axis)
hirokimineshita 6:ca882e5e2686 177 * @param b_value the pointer of the variable which will have acceleration
hirokimineshita 6:ca882e5e2686 178 * @param b_axis select what you want to do (x:x_axis y:y_axis z:z_axis)
hirokimineshita 6:ca882e5e2686 179 * @return the rotation acceleration by radian
hirokimineshita 6:ca882e5e2686 180 */
hirokimineshita 0:ad6f3a862ed5 181 float rotate(int *a_value,int a_axis,int *b_value,int b_axis);
hirokimineshita 6:ca882e5e2686 182
hirokimineshita 6:ca882e5e2686 183 /** function
hirokimineshita 6:ca882e5e2686 184 *
hirokimineshita 6:ca882e5e2686 185 * change the radian to degree
hirokimineshita 6:ca882e5e2686 186 * @param rad radian which you want to change
hirokimineshita 6:ca882e5e2686 187 * @return return changed degree
hirokimineshita 6:ca882e5e2686 188 */
hirokimineshita 0:ad6f3a862ed5 189 float rad_to_deg(float rad);
hirokimineshita 0:ad6f3a862ed5 190 };
hirokimineshita 0:ad6f3a862ed5 191
hirokimineshita 0:ad6f3a862ed5 192 #endif