nightpoison

Forum Replies Created

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #6172
    nightpoison
    Participant

    Mark,

    Thanks for the spread sheet, so based on the spread sheet I am not getting all the correct data results for each of the processes.

    here is the solution I’m using.

    function [ acc_combined ] = readACCx(a)

    acc_low = readRegister(a, hex2dec(’28’));
    acc_high = readRegister(a, hex2dec(’29’));

    acc_low = int16(acc_low);
    acc_high = int16(acc_high);

    acc_combined = bitor(acc_low, bitshift(acc_high, 8));

    fprintf(‘ACCx low: %8.2f high: %8.2f pre-combined: %8.2f post-combined: ‘, acc_low, acc_high, acc_combined);

    if acc_combined >= 32768
    acc_combined = acc_combined – 65536;
    end

    fprintf(‘%8.2f\n’,acc_combined);

    end

    once again thank you for your help. I’m now going to run the entire script and verify that I’m getting the correct pitch and roll. As that’s ultimately the data I need for my project. Thank you again!!

    #6171
    nightpoison
    Participant

    so that section of my code has changed. as you mentioned before I would be getting 1 byte of information from the high low, then when combined its a 2 byte signed. so what I ended up doing is first the OR operation, then converted into a signed 16 bit , then did the shifting.

    acc_combined = bitor(acc_low, acc_high);
    acc_combined = int16(acc_combined);
    acc_combined = bitshift(acc_combined, 8);

    what your saying is I need to do this in one line? I’m not sure if I can do that. I wasn’t able to shift by 8 bits before as matlab defaults to unsigned 8 bit precision. When I shifted by 8 it would just zero out the value. I can’t find any information on casting to signed 16. Ill need to look into that.

    It looks like, from this:

    gyr_combined = bitor(gyr_low, bitshift(gyr_high, 8));

    I’m only shifting the high value by 8 bits, is that correct?

    #6160
    nightpoison
    Participant

    ACC X——- ACC Y—— ACC Z—— Gyro X—– Gyro Y——- Gyro Z
    low high— low high— low high— low high— Low High—– Low High
    240 255—- 240 255—- 32 4—— 5 0——— 158 255—— 67 254
    238 255—- 246 255—- 16 5—— 113 0——— 1 255—— 97 254
    244 255—- 249 0———–1 4—— 148 0——— 204 255—— 92 254
    2 255———252 0——— 43 5—— 84 0——— 154 255—— 85 254
    240 255—- 3 255——- 254 4—— 116 0——— 200 255—— 127 254
    252 255—- 241 255—- 27 5—— 179 0——— 10 255—— 67 254
    253 255—- 236 255—- 247 4—— 156 0——— 203 255—— 29 254
    231 255—- 250 255—- 21 5—— 100 0——— 207 255—— 37 254
    250 255—- 255 255—- 5 5—— 83 0——— 189 255—— 87 254
    245 255—- 252 255—- 5 5—— 243 0——— 174 255—— 63 254

    #6156
    nightpoison
    Participant

    mark,

    here is the output I’m getting directly from the high lows.

    ACC X——-ACC Y ACC Z Gyro X Gyro Y Gyro Z
    low high—low high low high low high Low High Low High
    240 255—-240 255 32 4 5 0 158 255 67 254
    238 255—-246 255 16 5 113 0 1 255 97 254
    244 255—-249 0 1 4 148 0 204 255 92 254
    2 255—-252 0 43 5 84 0 154 255 85 254
    240 255—-3 255 254 4 116 0 200 255 127 254
    252 255—-241 255 27 5 179 0 10 255 67 254
    253 255—-236 255 247 4 156 0 203 255 29 254
    231 255—-250 255 21 5 100 0 207 255 37 254
    250 255—-255 255 5 5 83 0 189 255 87 254
    245 255—-252 255 5 5 243 0 174 255 63 254

    #6151
    nightpoison
    Participant

    Mark,

    so I believe I have gotten the read functions to perform correctly. can you confirm the data I’m receiving makes sense?

    after combining the low with the high, performing the bitwise or, shifting left 8 bits, and then finally adjusting by -655536, if the value is greater than 32768 here is the return values I’m receiving.

    -30976
    25856
    29952
    -28160
    28672
    -28928
    26880
    -32000
    32000
    21504
    -30208
    -26880
    -24576
    etc

    is this the results I should be expecting?

    #6145
    nightpoison
    Participant

    Mark,

    Thank you for clarifying. That helped me resolve and I am now getting what looks to be appropriate results for the individual register output. I found some errors, misleading information, in the Matlab documentation that was the source of my errors. Thank you. I will problem have more questions as I’m going. I’m running in to other issues. but I’m going to trouble shoot it for a bit first. Thank you again.

    Michael

    #6140
    nightpoison
    Participant

    bin2dec() doesn’t work. I get an error “Input must be a character vector”. I have a resource for matlab support.

    I just want to clarify, in the Python code (im using that for reference) you supply a GNU binary literal for the value to enable correct? Looking through the data sheet it seems that that is what is needed.

    Also, what is the type for the return value when I’m reading from the gyro for the high low registers? should they be decimal as I’m getting now?

    I haven’t used Matlab before, so I am taking a guess here.
    Maybe you need to convert the binary to decimal

    writeGYR(IMU, hex2dec(’20’),bin2dec(‘00001111`));
    writeGYR(IMU, hex2dec(’21’), bin2dec(‘00110000`));

    #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

    #6133
    nightpoison
    Participant

    Its taken some time, but I’ve figured out how to read and write to the device. However, I would very much like some feedback as I’m getting static output values from my device. There isn’t any drift at all.

    for the Gyroscope, could you supply a sample output for register’s 0x28, 0x29, 0x2A, 0x2B, 0x2C, & 0x2D. Before combining the values. I’m just looking for what the Gyro reads when you ready from those specific registers. For instance here is a method I’m currently using to read for the X value of the Gyro.

    function [ gyr_combined ] = readGYRx(IMU)
    % Reads data from IMU for x axis
    gyr_low = readRegister(IMU, hex2dec(’28’));
    gyr_high = readRegister(IMU, hex2dec(’29’));

    gyr_combined = bitor(gyr_low, gyr_high);
    gyr_combined = bitshift(gyr_combined, 8);

    if gyr_combined >= 32768
    gyr_combined = gyr_combined -65536;
    end

    return
    end

    no matter the angle of the sensor it always returns the same thing:
    gyr_low = 92.00
    gyr_high = 5.00

    first I’m sure these numbers should be moving, as even when a gyro is fixed, there should still be drift.

    #6124
    nightpoison
    Participant

    Hi,

    So im still having issues regarding matlab and the BerryIMU. But I’ve done some more research and narrowed it down to what I am specifically needing help with.

    Matlab has the ability to directly connect to I2C devices by creating an object using the devices address. here is two functions that I can use to read data from the device read() & readRegister()

    read(device, count, precision) –
    device = object connection with the IMU
    count = the number of elements I can expect
    precision = specified as a string. Match the data precision to the size of the register on the device. Optional.

    readRegister(device, register, precision) –
    device = object connection with the IMU
    register = register #
    Precision = specified as a string. Match the data precision to the size of the register on the device. Optional.

    can I use the LSM9DS0 to identify the registers on the IMU and then use readRegister to bring in the data? If that’s the case, which registers do I need to read in order to get the data I need.

    for instance in regards to the write function to enable the gyro. I know I need to send 0b00001111 to CTRL_REG1_G. But the register access is a scaler, so I can’t use the register name such as in python. how are the registers numbered?

Viewing 10 posts - 1 through 10 (of 10 total)

Blip, blop, bloop…