Matlab Communication

Home Forums UM7 Product Support Matlab Communication

This topic contains 8 replies, has 2 voices, and was last updated by  Daniel Piedrahita 1 year, 7 months ago.

  • Author
    Posts
  • #758

    Thomas

    Hi,

    I want to read data from the UM7 from Matlab. I used the example code and just tried to run the init.m, this is what i get in Matlab2014:

    Undefined function or variable “got_temperature_data”.

    Error in DUT_callback (line 73)
    if got_temperature_data && got_gyro_data

    Error in instrcb (line 36)
    feval(val{1}, obj, eventStruct, val{2:end});

    Warning: The BytesAvailableFcn is being disabled. To enable the callback property
    either connect to the hardware with FOPEN or set the BytesAvailableFcn property.

    What can I do to make it work? Unfortunately I don’t have any experience in serial communication with Matlab yet. Thanks in advance!

  • #838

    Manish Mittal

    I also have exactly the same query. Please reply as it is very necessary for my thesis work that I am doing.

  • #842

    Caleb
    Moderator

    The Matlab script that can be downloaded from the site is a snippet designed to illustrate how to use serial port callbacks to read and parse data for the UM7, from within Matlab. You can delete the references to got_temperature_data and got_gyro_data.

    Basically, the serial callback function reads bytes in from the serial port and parses them. When a packet is received, you can check the packet type and address bytes to see if it is the data that you are interested in. If it is, you can log it, or set a flag (like got_temperature_data), or whatever you want to do with it.

  • #862

    Manish Mittal

    Can you please write an example code to get the euler angel from the orientation sensor? It would be really helpful.

  • #863

    Manish Mittal

    I got to communicate with UM6 using MATLAB. Can you please tell me the address for the Euler angle data packet?

  • #864

    Caleb
    Moderator

    Sure, the Euler Angle data begins in register 112 (0x70). You can find that information in the datasheet, here: http://www.chrobotics.com/docs/UM7_Datasheet.pdf

  • #983

    Manish Mittal

    Hi Caleb,

    I was able to get the Euler Angle Data from the sensor using the MATLAB example code written by you. Now I want to store it in a variable matrix so that I can use it for further calculations. I used the Userdata attribute of the callback. function object to store the data. I did something like:

    gyro_x = typecast( flipud(uint8(packet.data(1:2))), ‘int16’ )/100;
    gyro_y = typecast( flipud(uint8(packet.data(3:4))), ‘int16’ )/100;
    gyro_z = typecast( flipud(uint8(packet.data(5:6))), ‘int16’ )/100;

    h1 = [gyro_x, gyro_y, gyro_z];
    h = [h; h1; h1]
    obj.Userdata = h;

    I thought that it would return an ever-increasing (number of rows will continuously increase storing the real time data) matrix with the gyro_x, gyro_y, gyro_z values. But the Userdata matrix has just one row which contains the latest values of the three variables. Its like its just updating the last row after each loop run. I am not sure if I am doing anything wrong. Can you please tell me know if there is anything wrong or if there is any other way to store the real time data from the callback function in the base workspace for later usage.

  • #984

    Manish Mittal

    Actually it is just

    h = [h; h1]; (and not h = [h; h1; h1];)

    Please suggest.

    • #1722

      Daniel Piedrahita

      Hi Manish,

      You mentioned that you were able to get the Euler Angle Data from the sensor into Matlab. Would you mind sharing your code? I am working on a similar problem now. Any help would be much appreciated.

      Thanks,
      Daniel

You must be logged in to reply to this topic.