Reply To: BerryIMU and Matlab

Home Forums Forums Technical Support for BerryIMU BerryIMU and Matlab Reply To: BerryIMU and Matlab

#6136
nightpoison
Participant

First, thank you for helping. I do really appreciate it.

I believe I am enabling correctly, here is the write function

function [] = writeGYR(IMU, reg, val)
%GRYO Summary of this function goes here

writeRegister(IMU, reg, val)

end

and here is the script that I'm using. I used the Python code you supplied via git, and made changes where appropriate for Matlab.

IMU = i2cdev(rpi, 'i2c-1', '0x6A');

G_GAIN = .07;

gyroXAngle = 0;
gyroYAngle = 0;
gyroZAngle = 0;

%initialize Gyroscope
writeGYR(IMU, hex2dec('20'), 00001111);
writeGYR(IMU, hex2dec('21'), 00110000);

%start timer
tic;

while true

%read gyroscope valuess
GYRx = readGYRx(IMU);
GYRy = readGYRy(IMU);
GYRz = readGYRz(IMU);

%calculate loop period(LP). time between reads
loopTime = toc;
tic;
LP = (loopTime/1000000)/(1000000*1);

%convert gyro raw to degrees per second
rate_gyr_x = GYRx * G_GAIN;
rate_gyr_y = GYRy * G_GAIN;
rate_gyr_z = GYRz * G_GAIN;

%Calculate angles from gyro
gyroXangle = gyroXAngle + (rate_gyr_x * LP);
gyroYangle = gyroYAngle + (rate_gyr_y * LP);
gyroZangle = gyroZAngle + (rate_gyr_z * LP);

% fprintf('Gyro X angle: %5.2f Gyro Y angle: %5.2f Gyro Z angle %5.2f\n', gyroXAngle, gyroYAngle, gyroZAngle);

pause(1);

end

Blip, blop, bloop...