Matlab Communication for UM6


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

Undefined function or variable “got_temperature_data”.

[i]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.[/i]

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

I imagine that you are referring to the example code here:

The code is poorly written and far more complicated than it needs to be. This section of the code fails because, indeed, the variable “got_temperature_data” is not defined before it is referenced. It is not hard to fix, but it may not be worth the effort.

if packet.Address == 118
temperature = typecast( flipud(uint8(, ‘single’ );
got_temperature_data = 1;
% fprintf(’%3.2f\n’,temperature);

	% If we received gyro and temperature data, log it to
	% the workspace if logging is enabled.
	if got_temperature_data && got_gyro_data
		got_temperature_data = 0;
		got_gyro_data = 0;



I am sorry your UM6 is not working for you. If you are using CH Robotics example code Jim mentioned, you might try posting about this issue on CH Robotics’ forum, which is the best place to get support for their products.



I was able to run the code after removing the got_temperature_data term as Jim said. It prints the required data perfectly fine (in my case I want to read the Euler angle from the sensor whose packet.address is 98). But I am unable to record the data in a matrix variable so that I can access it in my further calculations. The logging snippet given in the code does not work an I don;t know why. Below is the snippet in the code:

if got_temperature_data && got_gyro_data
got_temperature_data = 0;
got_gyro_data = 0;

		if GDATA.logging_data == 1 && GDATA.selected_DUT > 0
			if GDATA.DUT_samples_collected < GDATA.MAX_SAMPLES
				GDATA.DUT_samples_collected = GDATA.DUT_samples_collected + 1;
				GDATA.DUT_data(GDATA.DUT_samples_collected,:) = [single([GDATA.selected_DUT,gyro_x,gyro_y,gyro_z]),temperature];
				fprintf('Maximum datapoints were collected.  Logging disabled.\n');
				GDATA.logging_data = 0;

It gives error as G.Data is not defined. I removed this part of the program and did something like this to make it work and record the data:

gyro_x = typecast( flipud(uint8(, ‘int16’ )/100;
gyro_y = typecast( flipud(uint8(, ‘int16’ )/100;
gyro_z = typecast( flipud(uint8(, ‘int16’ )/100;

h1 = [gyro_x, gyro_y, gyro_z];
h = [h; 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.

Also Jim, you said the code is not well written. Is there a different way that we can code it to access and store the required data in real time. I would really appreciate the help. I have posted the same query in CHR’s forum but have not heard from them yet.

[quote]Is there a different way that we can code it to access and store the required data in real time.[/quote]There are many ways, but it isn’t clear to me what you want to do. If you are just storing a big block of data for later processing, that isn’t “real time”.

Please describe the “big picture view” of this project. There are probably much more efficient approaches to obtain the final result.

What I am trying to do is I have a drilling prototype (for oil and gas drilling) that I built for down-hole drilling automation algorithm. The algorithm would be used to control the path of the drill-pipe (as shown in the picture). In my case the orientation sensor would be used to calculate the inclination and azimuth angle of the drill pipe from the Roll, Pitch and Yaw values (the Euler angles). There would be a set of inclination and azimuth angles through out the designed drill path that the drill bit needs to follow and if there is any deviation in their values, the two actuators will come into action to bring the drill pipe to its original path. As you can see (in the prototype picture) in my case the drill pipe is not moving rather I give a fake movement to it through the program.

Basically, in my case the sensor (at the bottom of the drill pipe) should have specific values of Euler angles at specific times and if there is any deviation in it the two actuators would push the drill pipe to bring it to the desired orientation. Now, for this I need to be able to access the Euler angles during the course of the program. And hence, I need a code that would do the same. (Please disregard the first paragraph if it sounds confusing).

Thanks for the overview! How would MATLAB fit into this scheme?

MATLAB is certainly not required to get the Euler angles from the UM6, any micro with a serial port can do that. There is also the possibility of SPI port communications.

In any case, this is a commercial venture and I can imagine all sorts of issues with electronic equipment in a hostile environment. You would get much more reliable advice if you talk with the UM6 designer (Caleb Christianson, I believe). Also note that the UM6 has been discontinued.

Thanks for the quick response.

Matlab comes into the scene becuase I am doing all the calculations using matlab and also I am controlling my actuators via Arduino using Matlab. Basically I am using Matlab for the overall coding for my project wich includes getting the input from the sensor, performing calculations with respect to the algorithm and then giving instructions to the actuators to do what they have to do.

Our posts (my edit) crossed.

I would just start over, and use the serial input routines of MATLAB to read the Euler angle data.