Introduce
ESPrtk also supports IMU peripheral sensor. (Accelerometer / Gyroscope / Magnetometer).
High-precision IMU / INS data is processed in real time with low delay, sensor read-up frequency can up to 200Hz.
When enabled, ESPrtk will communicate with MPU9250 and send raw data, calibration data and filter data to Bluetooth device (client).
This function can run as a parallel task with the main action on both Rover and Base.
Note ! this feature only support on ESPrtk Ver 3.9.8 or higher.
Rover :
Base :
Wiring MPU9250 to use with ESPrtk
ESPrtk | IMU-MPU9250 |
---|---|
3.3V out | 3.3V |
GND | GND |
SDA_I2C | SDA |
SCL_I2C | SCL |
Configure enable Flag function
Detail configure
- Update frequency (Hz) : “2”,”10″,”15″,”20″,”25″,”35″,”50″,”100″,
“150”,”200″. - Gyroscope Scale range : ‘250’, ‘500’, ‘1000’,’2000′.
- Accelerometer Scale range : ‘2’, ‘4’, ‘8’,’16’.
- Low pass Filter (Hz): ‘Not use’,’5′,’10’,’20’,’41’,’92’,’184′.
- Shock tolerance Kalman Filter (input range): 1.000 ~ 20.000.
Format output data:
Please read ESPrtk datasheet to get detail $ESPIM1 and $ESPIM2 message : Download ESPrtk datasheet .
$ESPIM1, GX,GY,GZ, MX,MY,MZ, AX,AY,AZ, T, MXc,MYc,MZc,* <CS><CR><LF>
- GX,GY,GZ : Raw Gyroscope 3 Axis (Degree/second)
- MX,MY,MZ : Raw Magnetometer 3 Axis (uT) (micro-Tesla)
- AX,AY,AZ : Raw Accelerometer 3 Axis ( scale 0.1 m/s^2)
- T : Temperature sensor (°C) (degrees Celsius)
- MXc,MYc,MZc : Magnetometer 3 Axis + Calibrated.
$ESPIM2, QW,QX,QY,QZ, Yaw,Pitch,Roll, H, FQW,FQX,FQY,FQZ, FYaw,FPitch,FRoll, FH,* <CS><CR><LF>
- QW,QX,QY,QZ : DMP-Quaternion.
- Yaw,Pitch,Roll: DMP-Euler 3 Axis. (Degree)
- H :Compass Heading (using magnetometer calibrated) + Tilt compensation. (Degree)
- FQW,FQX,FQY,FQZ : DMP-Quaternion + Extended Kalman Filter.
- FYaw,FPitch,FRoll : DMP-Euler 3 Axis + Extended Kalman Filter. (Degree)
- FH :Compass Heading (using magnetometer calibrated) + Tilt compensation +Extended Kalman Filter (Degree)
<CS><CR><LF> :
- <CS> : a checksum represented as a two-digit hexadecimal number. The checksum is the bitwise exclusive OR of ASCII codes of all characters between the ($ )and (*). (does not include $ and * ).
- <CR> : “Carriage return” or ‘\r’ or ‘0x0D in hex’ (13 in decimal)
- <LF> : “Line Feed” or ‘\n’ or ‘0x0A in hex ‘ (10 in decimal) .
Calculate checksum – algorithm :
#include <stdio.h> const char MSG[]= "$ESPIM2|81|0.16|-0.09|-0.98|0.04|168.72|-172.96|-18.37|39.75|||||166.81|-163.44|19.96|53.70|*????\r\n"; // Calculate CRC uint8_t FIRST_CRC = 0 ; uint8_t SECOND_CRC = 0 ; uint16_t i = 0 ; while ( MSG [i] != '*' ){ // CRC_Range calculate from after '$' to begin '*' ( not contain '$' and '*') if ( MSG [i] != '$' ){ FIRST_CRC ^= ( uint8_t ) MSG [i]; SECOND_CRC ^= ( uint8_t ) FIRST_CRC; } i++; } //Format CRC to [HEX_Up] string and store to buffer char CRC16_OUT [4+1] ; sprintf ( CRC16_OUT , "%02X%02X" , FIRST_CRC , SECOND_CRC ); //Print out result printf ( "\n Your CRC16 is %s \n", CRC16_OUT); //Result should be [ Your CRC16 is 5172 ]
Example data receive on Bluetooth client:
$ESPIM2|81|0.16|-0.09|-0.98|0.04|168.72|-172.96|-18.37|39.75|||||166.81|-163.44|19.96|53.70|*5172 $ESPIM1|81|82.32|199.63|172.13|-2.40|-7.20|-50.41|0.54|-0.52|-0.57|29.17|-2.40|-7.20|-50.41|*186D $ESPIM2|82|0.35|-0.25|-0.88|0.20|136.90|-141.23|-31.31|21.44|||||139.56|-141.49|-30.51|22.45|*750C $ESPIM1|84|178.90|116.04|202.62|17.55|-21.91|-30.16|0.57|-0.76|-0.12|29.16|17.55|-21.91|-30.16|*2071 $ESPIM2|82|0.57|-0.51|-0.57|0.30|79.64|-100.98|-20.24|334.15|||||83.66|-106.79|-20.59|315.65|*7D05 $ESPIM1|82|117.38|127.38|185.91|37.51|-10.50|-8.85|-0.09|-0.79|0.14|29.16|37.51|-10.50|-8.85|*2211 $ESPIM2|77|0.66|-0.60|-0.20|0.40|51.81|-78.48|12.85|316.72|||||52.77|-79.97|6.36|316.71|*4774 $ESPIM1|76|-12.68|51.89|19.82|39.61|10.80|2.55|-0.66|-0.60|0.13|29.16|39.61|10.80|2.55|*3F7F $ESPIM2|77|0.63|-0.64|0.03|0.45|41.11|-76.36|38.07|295.72|||||41.76|-76.70|35.26|303.99|*5E7E $ESPIM1|79|-170.67|-256.16|-166.71|41.41|8.25|0.60|-0.30|-0.80|0.21|29.16|41.41|8.25|0.60|*004B $ESPIM2|78|0.59|-0.60|-0.19|0.50|62.77|-77.32|21.63|314.30|||||54.44|-77.11|23.91|309.77|*7C09 $ESPIM1|86|-160.12|-91.22|-182.01|30.01|-17.70|-25.81|0.61|-0.86|-0.59|29.17|30.01|-17.70|-25.81|*3C50 $ESPIM2|81|0.45|-0.47|-0.71|0.25|99.49|-120.54|-23.98|344.87|||||93.43|-97.15|-19.13|336.54|*433B
Calibration for magnetomter data
Compensating hard-iron-and-soft-iron-effects on compass sensor using trasnsformation matrix.
Go to this post to learn more : IMU MPU9250 ; Calibrate magnetometer on ESPrtk using Magneto1.2.
Calibration Helper.
Display and collect XYZ 3-axis magnetometer data to make calibration magnetometer more simple and professional with wireless connection (WIFI).
See detail here: IMU MPU9250 ; Calibration Helper .