Help with Matlab and Maestro Servo Controller

Hello All,

I am using 6-channel Maestro servo controller with Matlab to control my servos. I am using the compact protocol to send serial commands. But I would like to get errors from the servo controller when an error occurs. But I am getting the following error when I try to get the error code. Please let me know how I can get the error details from the controller. Thank you!!!

Here is my script:

controller = serial(com);
tx_string = 162;
fwrite(controller, tx_string, ‘uint8’);
count = 2; % # of bytes (high and low)
error = fread(controller, count, ‘uint8’);

Warning: Unsuccessful read: The specified amount of data was not returned within the Timeout period.
error = Empty matrix: 2-by-0

I can send signals to the servos the following way, and it works.

controller = serial(com);
set_position(controller, 2, 1500);

************************* set_position function*****************
function set_position(controller, servo, setpoint)
setpoint = 4*setpoint;
low = mod(setpoint,128);
high = floor(setpoint/128);
tx_string = [132 servo low high];
fwrite(controller, tx_string, ‘uint8’);


I am not familiar with Matlab, but the error message you are getting indicates that Matlab is not receiving the response bytes from the Maestro in a reasonable time. Could you describe how the Maestro is connected to the computer? Is it just plugged into USB? Does your set_position method actually succeed in moving servos? Could you post your Maestro settings file here? (You can save one from the File menu of the Maestro Control Center.) This will be useful because we should look carefully at all of your serial settings. It would also be good to figure out what timeout period Matlab is using; the default might be too low but you should be able to raise it.


Thanks David for your response. please see the details below.

Could you describe how the Maestro is connected to the computer? Is it just plugged into USB?

  • Yes, I am communicating to Maestro via USB. I open a serial COM port in Matlab.

Does your set_position method actually succeed in moving servos?
-Yes, I am moving 5 servos using the set_position method. It works fine majority of the time, but once in a while I get an error. That is the reason I am looking into Get Error command.

About Matlab time out period, I noticed that once fread command is called, matlab hangs for about 3-4 seconds. Then the timeout error occurs. I am trying to see if I can increase the timeout period, but I thought about 3 seconds was sufficient to get a response. This is what I read in the user guide "The error register is sent as a two-byte response immediately after the command is received, then all the error bits are cleared. "

Any help is appreciated.

Yes, three seconds is definitely long enough. I just noticed you are sending the wrong command to get the errors; it should be 161. If that does not help, could you try sending the Get Errors command using the Pololu Serial Transmitter and see if it shows the response bytes? Also, if you are just trying to troubleshoot your system then an easier way to see the errors would be to run the Maestro Control Center and look in the Errors tab.


Thank you very much!!
I was not aware of the Pololu Serial Transmitter, looks like a great tool for trouble shooting! Also, it should be 161 as you said (hex to decimal conversion gone wrong!).

Thank you once again for all your help.