BerryIMU and Matlab

Home Forums Forums Technical Support for BerryIMU BerryIMU and Matlab

Viewing 3 posts - 16 through 18 (of 18 total)
  • Author
    Posts
  • #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?

    #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!!

    #7224
    Sylvain
    Participant

    Hi nightpoison, do you have a clean code to share ?

    I am interested in using the i2c protocole with an Arduino and the BerryIMU (probably later using raspbery Pi. Though the main code should remain the same.

    thanks,

    Sylvain

Viewing 3 posts - 16 through 18 (of 18 total)
  • You must be logged in to reply to this topic.

Blip, blop, bloop…