MPU 6050 pada AVR
MPU 6050 merupakan combo sesnsor antara accelero dan gyroscope meskipun pada dasarnya ada sensor temperaturnya juga sih lihat disini. Akses sensor ini menggunakan fitur I2c microcontroller.
Untuk register mapnya bisa liat disini . Adapun fitur-fitur yang ditawarkan antara lain:
- - Sensitifitas Accelerometer yang dapat dipilih mulai 2/4/8 samapai 16 g
- - Sensitifitas Gyrocope yang dapat dipilih mulai 250/500/1000 sampai 2000 degrees/s
- - Range 16 bit untuk kedua sensor
- - Sensitivitas percepatan linier dari Gyroscope 0,1 derajat/s
- -
Data rate output
hingga 1000Hz, dilengkapi digital low
pass filter dan memiliki frekuensi sudut maksimum 256Hz.
Untuk mengakses sensor ini bisa diliat di contoh program dibawah;
Register yang didaftarkan:
#define MPU6050_ADDRESS 0xD0 // Address with end write bit
#define MPU6050_RA_XG_OFFS_TC 0x00 //[7] PWR_MODE, [6:1] XG_OFFS_TC, [0] OTP_BNK_VLD
#define MPU6050_RA_YG_OFFS_TC 0x01 //[7] PWR_MODE, [6:1] YG_OFFS_TC, [0] OTP_BNK_VLD
#define MPU6050_RA_ZG_OFFS_TC 0x02 //[7] PWR_MODE, [6:1] ZG_OFFS_TC, [0] OTP_BNK_VLD
#define MPU6050_RA_X_FINE_GAIN 0x03 //[7:0] X_FINE_GAIN
#define MPU6050_RA_Y_FINE_GAIN 0x04 //[7:0] Y_FINE_GAIN
#define MPU6050_RA_Z_FINE_GAIN 0x05 //[7:0] Z_FINE_GAIN
#define MPU6050_RA_XA_OFFS_H 0x06 //[15:0] XA_OFFS
#define MPU6050_RA_XA_OFFS_L_TC 0x07
#define MPU6050_RA_YA_OFFS_H 0x08 //[15:0] YA_OFFS
#define MPU6050_RA_YA_OFFS_L_TC 0x09
#define MPU6050_RA_ZA_OFFS_H 0x0A //[15:0] ZA_OFFS
#define MPU6050_RA_ZA_OFFS_L_TC 0x0B
#define MPU6050_RA_XG_OFFS_USRH 0x13 //[15:0] XG_OFFS_USR
#define MPU6050_RA_XG_OFFS_USRL 0x14
#define MPU6050_RA_YG_OFFS_USRH 0x15 //[15:0] YG_OFFS_USR
#define MPU6050_RA_YG_OFFS_USRL 0x16
#define MPU6050_RA_ZG_OFFS_USRH 0x17 //[15:0] ZG_OFFS_USR
#define MPU6050_RA_ZG_OFFS_USRL 0x18
#define MPU6050_RA_SMPLRT_DIV 0x19
#define MPU6050_RA_CONFIG 0x1A
#define MPU6050_RA_GYRO_CONFIG 0x1B
#define MPU6050_RA_ACCEL_CONFIG 0x1C
#define MPU6050_RA_FF_THR 0x1D
#define MPU6050_RA_FF_DUR 0x1E
#define MPU6050_RA_MOT_THR 0x1F
#define MPU6050_RA_MOT_DUR 0x20
#define MPU6050_RA_ZRMOT_THR 0x21
#define MPU6050_RA_ZRMOT_DUR 0x22
#define MPU6050_RA_FIFO_EN 0x23
#define MPU6050_RA_I2C_MST_CTRL 0x24
#define MPU6050_RA_I2C_SLV0_ADDR 0x25
#define MPU6050_RA_I2C_SLV0_REG 0x26
#define MPU6050_RA_I2C_SLV0_CTRL 0x27
#define MPU6050_RA_I2C_SLV1_ADDR 0x28
#define MPU6050_RA_I2C_SLV1_REG 0x29
#define MPU6050_RA_I2C_SLV1_CTRL 0x2A
#define MPU6050_RA_I2C_SLV2_ADDR 0x2B
#define MPU6050_RA_I2C_SLV2_REG 0x2C
#define MPU6050_RA_I2C_SLV2_CTRL 0x2D
#define MPU6050_RA_I2C_SLV3_ADDR 0x2E
#define MPU6050_RA_I2C_SLV3_REG 0x2F
#define MPU6050_RA_I2C_SLV3_CTRL 0x30
#define MPU6050_RA_I2C_SLV4_ADDR 0x31
#define MPU6050_RA_I2C_SLV4_REG 0x32
#define MPU6050_RA_I2C_SLV4_DO 0x33
#define MPU6050_RA_I2C_SLV4_CTRL 0x34
#define MPU6050_RA_I2C_SLV4_DI 0x35
#define MPU6050_RA_I2C_MST_STATUS 0x36
#define MPU6050_RA_INT_PIN_CFG 0x37
#define MPU6050_RA_INT_ENABLE 0x38
#define MPU6050_RA_DMP_INT_STATUS 0x39
#define MPU6050_RA_INT_STATUS 0x3A
#define MPU6050_RA_ACCEL_XOUT_H 0x3B
#define MPU6050_RA_ACCEL_XOUT_L 0x3C
#define MPU6050_RA_ACCEL_YOUT_H 0x3D
#define MPU6050_RA_ACCEL_YOUT_L 0x3E
#define MPU6050_RA_ACCEL_ZOUT_H 0x3F
#define MPU6050_RA_ACCEL_ZOUT_L 0x40
#define MPU6050_RA_TEMP_OUT_H 0x41
#define MPU6050_RA_TEMP_OUT_L 0x42
#define MPU6050_RA_GYRO_XOUT_H 0x43
#define MPU6050_RA_GYRO_XOUT_L 0x44
#define MPU6050_RA_GYRO_YOUT_H 0x45
#define MPU6050_RA_GYRO_YOUT_L 0x46
#define MPU6050_RA_GYRO_ZOUT_H 0x47
#define MPU6050_RA_GYRO_ZOUT_L 0x48
#define MPU6050_RA_EXT_SENS_DATA_00 0x49
#define MPU6050_RA_EXT_SENS_DATA_01 0x4A
#define MPU6050_RA_EXT_SENS_DATA_02 0x4B
#define MPU6050_RA_EXT_SENS_DATA_03 0x4C
#define MPU6050_RA_EXT_SENS_DATA_04 0x4D
#define MPU6050_RA_EXT_SENS_DATA_05 0x4E
#define MPU6050_RA_EXT_SENS_DATA_06 0x4F
#define MPU6050_RA_EXT_SENS_DATA_07 0x50
#define MPU6050_RA_EXT_SENS_DATA_08 0x51
#define MPU6050_RA_EXT_SENS_DATA_09 0x52
#define MPU6050_RA_EXT_SENS_DATA_10 0x53
#define MPU6050_RA_EXT_SENS_DATA_11 0x54
#define MPU6050_RA_EXT_SENS_DATA_12 0x55
#define MPU6050_RA_EXT_SENS_DATA_13 0x56
#define MPU6050_RA_EXT_SENS_DATA_14 0x57
#define MPU6050_RA_EXT_SENS_DATA_15 0x58
#define MPU6050_RA_EXT_SENS_DATA_16 0x59
#define MPU6050_RA_EXT_SENS_DATA_17 0x5A
#define MPU6050_RA_EXT_SENS_DATA_18 0x5B
#define MPU6050_RA_EXT_SENS_DATA_19 0x5C
#define MPU6050_RA_EXT_SENS_DATA_20 0x5D
#define MPU6050_RA_EXT_SENS_DATA_21 0x5E
#define MPU6050_RA_EXT_SENS_DATA_22 0x5F
#define MPU6050_RA_EXT_SENS_DATA_23 0x60
#define MPU6050_RA_MOT_DETECT_STATUS 0x61
#define MPU6050_RA_I2C_SLV0_DO 0x63
#define MPU6050_RA_I2C_SLV1_DO 0x64
#define MPU6050_RA_I2C_SLV2_DO 0x65
#define MPU6050_RA_I2C_SLV3_DO 0x66
#define MPU6050_RA_I2C_MST_DELAY_CTRL 0x67
#define MPU6050_RA_SIGNAL_PATH_RESET 0x68
#define MPU6050_RA_MOT_DETECT_CTRL 0x69
#define MPU6050_RA_USER_CTRL 0x6A
#define MPU6050_RA_PWR_MGMT_1 0x6B
#define MPU6050_RA_PWR_MGMT_2 0x6C
#define MPU6050_RA_BANK_SEL 0x6D
#define MPU6050_RA_MEM_START_ADDR 0x6E
#define MPU6050_RA_MEM_R_W 0x6F
#define MPU6050_RA_DMP_CFG_1 0x70
#define MPU6050_RA_DMP_CFG_2 0x71
#define MPU6050_RA_FIFO_COUNTH 0x72
#define MPU6050_RA_FIFO_COUNTL 0x73
#define MPU6050_RA_FIFO_R_W 0x74
#define MPU6050_RA_WHO_AM_I 0x75
sebelum memulai penulisan atau pembacaan dengan i2c maka kita cek terlebih dahulu register pada MPU 6050 apakah sudah ter conect dengan benar :
void tes_i2c()
{
unsigned char Datax = 0x00;
do{Datax=baca_i2c(MPU6050_ADDRESS, MPU6050_RA_WHO_AM_I);
lcd_clear();
if(Datax == 0x68)
{
lcd_putsf("cek berhasil");
}
else
{
lcd_putsf("cek gagal");
}
delay_ms(1000); }
while(Datax!=0x68);
}
setelah sesuai dengan register who am i kita lanjut ke setting register :
{
unsigned char Datax = 0x00;
do{Datax=baca_i2c(MPU6050_ADDRESS, MPU6050_RA_WHO_AM_I);
lcd_clear();
if(Datax == 0x68)
{
lcd_putsf("cek berhasil");
}
else
{
lcd_putsf("cek gagal");
}
delay_ms(1000); }
while(Datax!=0x68);
}
setelah sesuai dengan register who am i kita lanjut ke setting register :
void setup_mpu6050()
{ lcd_clear();
//f sample ratenya 1k karena DPLF aktif 1000/1+1 = 500Hz
nulis_i2c(MPU6050_ADDRESS,MPU6050_RA_SMPLRT_DIV,0x01);
//Disable FSync, 48Hz DLPF acceleronya bandwith 44 HZ delay 4.9 gyronya bandwith 42Hz delay 4.8Fs 1k
nulis_i2c(MPU6050_ADDRESS,MPU6050_RA_CONFIG,0x03);
//Disable gyro self tests, scale of 250 degrees/s
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_GYRO_CONFIG, 0x00);
//Disable accel self tests, scale of +-2g, no DHPF
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_ACCEL_CONFIG, 0b00000000);
//Freefall threshold of |0mg|
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_FF_THR, 0x00);
//Freefall duration limit of 0
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_FF_DUR, 0x00);
//Motion threshold of 0mg
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_MOT_THR, 0x00);
//Motion duration of 0s
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_MOT_DUR, 0x00);
//Zero motion threshold
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_ZRMOT_THR, 0x00);
//Zero motion duration threshold
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_ZRMOT_DUR, 0x00);
//Disable sensor output to FIFO buffer
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_FIFO_EN, 0x00);
//i2c MST CLOCK 348 kHz divider 23 dari 8Mhz mpu6050 internal clk
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_MST_CTRL, 0x00);
//Setup AUX I2C slaves
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV0_ADDR, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV0_REG, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV0_CTRL, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV1_ADDR, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV1_REG, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV1_CTRL, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV2_ADDR, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV2_REG, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV2_CTRL, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV3_ADDR, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV3_REG, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV3_CTRL, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV4_ADDR, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV4_REG, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV4_DO, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV4_CTRL, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV4_DI, 0x00);
//MPU6050_RA_I2C_MST_STATUS //Read-only
//Setup INT pin and AUX I2C pass through
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_INT_PIN_CFG, 0x00);
//Enable data ready interrupt
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_INT_ENABLE, 0x00);
//Slave out, dont care
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV0_DO, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV1_DO, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV2_DO, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV3_DO, 0x00);
//More slave config
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_MST_DELAY_CTRL, 0x00);
//Reset sensor signal paths
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_SIGNAL_PATH_RESET, 0x00);
//Motion detection control
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_MOT_DETECT_CTRL, 0x00);
//Disables FIFO, AUX I2C, FIFO and I2C reset bits to 0
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_USER_CTRL, 0x00);
//Sets clock source to gyro reference w/ PLL
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_PWR_MGMT_1, 0b00000010);
//Controls frequency of wakeups in accel low power mode plus the sensor standby modes
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_PWR_MGMT_2, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_FIFO_R_W, 0x00);
lcd_putsf("setup done");
delay_ms(1000);
}
//f sample ratenya 1k karena DPLF aktif 1000/1+1 = 500Hz
nulis_i2c(MPU6050_ADDRESS,MPU6050_RA_SMPLRT_DIV,0x01);
//Disable FSync, 48Hz DLPF acceleronya bandwith 44 HZ delay 4.9 gyronya bandwith 42Hz delay 4.8Fs 1k
nulis_i2c(MPU6050_ADDRESS,MPU6050_RA_CONFIG,0x03);
//Disable gyro self tests, scale of 250 degrees/s
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_GYRO_CONFIG, 0x00);
//Disable accel self tests, scale of +-2g, no DHPF
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_ACCEL_CONFIG, 0b00000000);
//Freefall threshold of |0mg|
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_FF_THR, 0x00);
//Freefall duration limit of 0
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_FF_DUR, 0x00);
//Motion threshold of 0mg
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_MOT_THR, 0x00);
//Motion duration of 0s
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_MOT_DUR, 0x00);
//Zero motion threshold
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_ZRMOT_THR, 0x00);
//Zero motion duration threshold
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_ZRMOT_DUR, 0x00);
//Disable sensor output to FIFO buffer
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_FIFO_EN, 0x00);
//i2c MST CLOCK 348 kHz divider 23 dari 8Mhz mpu6050 internal clk
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_MST_CTRL, 0x00);
//Setup AUX I2C slaves
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV0_ADDR, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV0_REG, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV0_CTRL, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV1_ADDR, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV1_REG, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV1_CTRL, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV2_ADDR, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV2_REG, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV2_CTRL, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV3_ADDR, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV3_REG, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV3_CTRL, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV4_ADDR, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV4_REG, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV4_DO, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV4_CTRL, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV4_DI, 0x00);
//MPU6050_RA_I2C_MST_STATUS //Read-only
//Setup INT pin and AUX I2C pass through
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_INT_PIN_CFG, 0x00);
//Enable data ready interrupt
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_INT_ENABLE, 0x00);
//Slave out, dont care
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV0_DO, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV1_DO, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV2_DO, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV3_DO, 0x00);
//More slave config
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_I2C_MST_DELAY_CTRL, 0x00);
//Reset sensor signal paths
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_SIGNAL_PATH_RESET, 0x00);
//Motion detection control
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_MOT_DETECT_CTRL, 0x00);
//Disables FIFO, AUX I2C, FIFO and I2C reset bits to 0
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_USER_CTRL, 0x00);
//Sets clock source to gyro reference w/ PLL
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_PWR_MGMT_1, 0b00000010);
//Controls frequency of wakeups in accel low power mode plus the sensor standby modes
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_PWR_MGMT_2, 0x00);
nulis_i2c(MPU6050_ADDRESS, MPU6050_RA_FIFO_R_W, 0x00);
lcd_putsf("setup done");
delay_ms(1000);
}
setelah menulis register-register ini sensor data sensor siap di akuisisi. pertama akusisi data accelero
contoh programnya seperti dibawah:
{
axx_xh = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_ACCEL_XOUT_H);
axx_xl = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_ACCEL_XOUT_L);
axx_yh = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_ACCEL_YOUT_H);
axx_yl = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_ACCEL_YOUT_L);
axx_zh = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_ACCEL_ZOUT_H);
axx_zl = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_ACCEL_ZOUT_L);
axx_x = ((axx_xh<<8)|axx_xl);
axx_y = ((axx_yh<<8)|axx_yl);
axx_z = ((axx_zh<<8)|axx_zl);
axx_sudut_x =(float) 57.295*atan((float)axx_y/ sqrt(pow((float)axx_z,2)+pow((float)axx_x,2)));
axx_sudut_y =(float) 57.295*atan((float)-axx_x/ sqrt(pow((float)axx_z,2)+pow((float)axx_y,2)));
axx_sudut_z =(float) 57.295*atan(sqrt(pow((float)axx_x,2)+pow((float)axx_y,2))/(float)axx_z);
}
untuk mengambil data accelero tinggal menggunakan fungsi tersebut namun sebelumnya daftarkan variable-variable terkait. Setelah sukses dengan accelero lanjut dengan akuisisi data gyro. pada dasarnya gyro membutuhkan nilai zero rate atau nilai rate ketika sensor benar-benar da;am keadaan diam jadi perlu adanya kalibrasi gyro ketika hendak memulai akuisisi data gyro. selaion itu setiap tempat atau berbeda posisi maka nilai zero ratenya juga akan berubah maka kalibrasi dilakukan setiap program dimuali. fungsinya seperti contoh program dibawah:
{
lcd_clear();
lcd_putsf("calibrating Gyro");
for(s = 0;s<100;s++)
{
giro_xh = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_GYRO_XOUT_H);
giro_xl = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_GYRO_XOUT_L);
giro_yh = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_GYRO_YOUT_H);
giro_yl = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_GYRO_YOUT_L);
giro_zh = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_GYRO_ZOUT_H);
giro_zl = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_GYRO_ZOUT_L);
giro_xh = giro_xh + giro_xh;
giro_yh = giro_yh + giro_yh;
giro_zh = giro_zh + giro_zh;
giro_xl = giro_xl + giro_xl;
giro_yl = giro_yl + giro_yl;
giro_zl = giro_zl + giro_zl;
delay_ms(1);
}
giro_xh100=giro_xh/100;
giro_yh100=giro_yh/100;
giro_zh100=giro_zh/100;
giro_xl100=giro_xl/100;
giro_yl100=giro_yl/100;
giro_zl100=giro_zl/100;
giro_x_ofset =(giro_xh100<<8)|giro_xl100;
giro_y_ofset =(giro_yh100<<8)|giro_yl100;
giro_z_ofset =(giro_zh100<<8)|giro_zl100;
}
setelah suskses dengan kalibrasi data diatas lanjut ke akuisisi sudut yang dihasilkan gyro
void akusisi_gyro()
{
giro_xh = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_GYRO_XOUT_H);
giro_xl = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_GYRO_XOUT_L);
giro_yh = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_GYRO_YOUT_H);
giro_yl = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_GYRO_YOUT_L);
giro_zh = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_GYRO_ZOUT_H);
giro_zl = baca_i2c(MPU6050_ADDRESS,MPU6050_RA_GYRO_ZOUT_L);
giro_x = ((giro_xh<<8)|giro_xl) - giro_x_ofset;
giro_y = ((giro_yh<<8)|giro_yl) - giro_y_ofset;
giro_z = ((giro_zh<<8)|giro_zl) - giro_z_ofset;
rate_giro_x = giro_x/giro_x_sens;
rate_giro_y = giro_y/giro_y_sens;
rate_giro_z = giro_z/giro_z_sens;
sudut_giro_x +=rate_giro_x*dt;
sudut_giro_y +=rate_giro_y*dt;
sudut_giro_z +=rate_giro_z*dt;
}
settin i2c dengan fungsi berikut:
void nulis_i2c(unsigned char alamatt,unsigned char regg, unsigned char dataa)
{
i2c_start();
i2c_write(alamatt | 0);
i2c_write(regg);
i2c_write(dataa);
i2c_stop();
delay_ms(10);
}
char baca_i2c(unsigned char alamat,unsigned char reg)
{
unsigned char baca;
i2c_start();
i2c_write(alamat |0);
i2c_write(reg);
i2c_start();
i2c_write(alamat |1);
baca=i2c_read(0);
i2c_stop();
return baca;
}
bagi kalian yang seneng quad copter bisa nyari infoneya disini atau disini dengan sensor MPU 6050. pada tugas akhir saya Omni directional wheels chair juga menggunakan sensor ini berikut demonya:
Comments
Trsu kalo nilai dari kecepatan sudut dapat dari mana ya??
Tks..
thx before
Brarti nilai kecepatan sudutnya formulanya gini ya gan??
rate_giro_x = giro_x/giro_x_sens;
rate_giro_y = giro_y/giro_y_sens;
rate_giro_z = giro_z/giro_z_sens;
Tks..
Nanti nih saya implementasikan buat mengatur kestabilan quadcopter pada saat hover dengan metode pengontrolan fuzzy logic yang mana nanti set point saya sudutnya sebesar 0 derajat thdp sumbu x,y, dan z menggunakan hasil complementary filter. .
Nah yg jadi masalah sudut thdp sumbu z knapa hasilnya gk sesuai ya?
Saya putar sensornya thdp sumbu x dan y malah sudut z juga ikut berubah. Seharusnyakan sumbu z tidak berubah nilainya kan gan??
Padahalkan sumbu z, nilainya berubah saat diputar terhadap yaw.
Mohon pencerahannya gan..
Tks banyak..
jadi ada baronya juga cocok buat quadcopter gan kalo MPU sebenernya gyronya kurang bagus gan mending cari accelero yang gyronya pisah gan
Mohon gan bantuannya..
Skaligus sourcode VB-nya gan..
Sebagai referensi saya.
Soalnya saya dah cari2 referensinya buat di matlab, susah gan.
Soalnya ntar mau nampilkan nilai dan grafik thdap waktu dari :
axx_sudut_x
axx_sudut_y
axx_sudut_z
melalui serial komunikasi gan..
Tks bnyak gan
Kalo boleh tau agan yogi deva pake metode apa?
{
COMPLEMENTARY_XANGLE = (COMPLEMENTARY_XANGLE + GYRO_XRATE*dt)*a + ACCEL_XANGLE*(1-a);
COMPLEMENTARY_YANGLE = (COMPLEMENTARY_YANGLE + GYRO_YRATE*dt)*a + ACCEL_YANGLE*(1-a);
COMPLEMENTARY_ZANGLE = (COMPLEMENTARY_ZANGLE + GYRO_ZRATE*dt)*a + ACCEL_ZANGLE*(1-a);
}
void second_order_complementary_filter() {
filter_xterm[0] = (ACCEL_XANGLE - COMPLEMENTARY_XANGLE) * timeConstant * timeConstant;
filter_yterm[0] = (ACCEL_YANGLE - COMPLEMENTARY_YANGLE) * timeConstant * timeConstant;
filter_zterm[0] = (ACCEL_ZANGLE - COMPLEMENTARY_ZANGLE) * timeConstant * timeConstant;
filter_xterm[2] = (dt * filter_xterm[0]) + filter_xterm[2];
filter_yterm[2] = (dt * filter_yterm[0]) + filter_yterm[2];
filter_zterm[2] = (dt * filter_zterm[0]) + filter_zterm[2];
filter_xterm[1] = filter_xterm[2] + (ACCEL_XANGLE - COMPLEMENTARY_XANGLE) * 2 * timeConstant + GYRO_XRATE;
filter_yterm[1] = filter_yterm[2] + (ACCEL_YANGLE - COMPLEMENTARY_YANGLE) * 2 * timeConstant + GYRO_YRATE;
filter_zterm[1] = filter_zterm[2] + (ACCEL_ZANGLE - COMPLEMENTARY_ZANGLE) * 2 * timeConstant + GYRO_ZRATE;
COMPLEMENTARY_XANGLE = ((dt * filter_xterm[1]) + COMPLEMENTARY_XANGLE)+1;
COMPLEMENTARY_YANGLE = (dt * filter_yterm[1]) + COMPLEMENTARY_YANGLE;
COMPLEMENTARY_ZANGLE = (dt * filter_zterm[1]) + COMPLEMENTARY_ZANGLE;
}
Mau nanya lagi Gan, nilai dari a dan dt nya berapa ya??
rate_giro_x = giro_x/giro_x_sens;
rate_giro_y = giro_y/giro_y_sens;
rate_giro_z = giro_z/giro_z_sens;
sudut_giro_x +=rate_giro_x*dt;
sudut_giro_y +=rate_giro_y*dt;
sudut_giro_z +=rate_giro_z*dt;
nilai dari
1. gyro_x_sens
2. gyro_y_sens
3. gyro_z_sens
4. dt
berapa ya gan saya mau coba menggunakan sensor ini untuk membuat robot keseimbangan 2 roda
saya mau tanya..klo mau nyeting acceleronya biar bisa 16g gmn ya?
trims
saya coba bagi hasilnya sama saja mas
maaf banyak tanya
terima kasih
Vin yg dipakai untuk sensor brp gan? 3v atau 5v?
Vin yg dipakai untuk sensor brp gan? 3v atau 5v?