Connecting to MATLAB

I have an 18 mini Maestro Servo drive. I have control model in MATLAB for my robot. is There any any example to send position from MATLAB to controller? I need Example Code. here is my cod which is not worked.
obj=serial(‘COM3’);
set(obj,‘Terminator’,‘CR’);
set(obj,‘BaudRate’,115200,‘DataBits’,8,‘Parity’,‘none’,‘stopBits’,1);

obj.FlowControl=‘none’;

format short g

A=132;B=1900;C=1200;D=1200;E=1400;F=1400;G=1900;H=1000;I=1000;
A=1100;B=1100;C=1100;D=1900;E=1900;F=1900;G=1900;H=1900;I=1200;
fopen(obj);

str = sprintf(’#0 P%d #1 P%d #2 P%d #3 P%d #4 P%d #5 P%d #6 P%d #7 P%d #8 P%d\n’,A,B,C,D,E,F,G,H,I);
fprintf(obj,str);

fclose(obj);

i reach to this one but no luck.
obj=serial(‘COM3’);

set(obj, ‘InputBufferSize’, 2048);
set(obj, ‘BaudRate’, 9600);
set(obj, ‘DataBits’, 8);
set(obj, ‘Parity’, ‘none’);
set(obj, ‘StopBits’, 1);
obj.FlowControl=‘none’;

fopen(obj);

fwrite(obj, [255, 0, 0],‘uint8’)
fclose(obj);

Hello.

We do not have much experience with MATLAB, but I don’t see anything obviously wrong with the code in your latest post. Have you made sure the Maestro is configured correctly (including setting it to an appropriate serial mode, as described in the “Serial Settings” section of the user’s guide)?

You can try sending the same command with the Pololu Serial Transmitter to make sure there are no problems with the configuration and that you have the correct COM port.

Kevin

Hello
thanks.
I double check it. it seems matlab does not recognize the device.
i still work on it
any help would be great.
thanks

the code is found by help of my friend . the range was different. here is a cod:

fwrite(obj,[170,12,4,0,32,31])

31 is the minimum position.

It sounds like you have it working; is that correct? The command in your latest post uses a different protocol compared to the one in your original code (this one uses the Pololu protocol while the earlier one used the Mini SSC protocol), but the original command should have worked fine. If you want to continue trying to get your earlier code to work, or if you still have any questions, let me know.

By the way, you are observing that “31 is the minimum position” because that byte represents the higher 7 bits of a 14-bit target, representing a pulse length in units of quarter microseconds, and the default minimum allowed value for a servo channel’s position is 992 us (as configured in Channel Settings). This corresponds to a value of 3968 quarter-microseconds, which is 00111110000000 in binary, splitting into 0011111 = 31 (high 7 bits) and 0000000 = 0 (low 7 bits).

Kevin