Matlab question

Hello,
I am working on a project and i am using Matlab 7 to build a GUI that allows the user to specify the position and speed of the servos (the project is much more complex but i will not go into furhter details). I have managed to give simple instructions and move the servos, like :

S=serial(‘COM4’, ‘BaudRate’, 115200,‘Terminator’,‘CR/LF’);
fopen(S)
fprintf(S,’#0P1500S200’)
fclose(S)

but the thing is that i want the indication for the position to be a variable that actually the user can change any time from the GUI and in the backround that variable can be assigned to the correct place to give the controler the appropriate instruction.
So, my question is: if that can be expressed somehow and if it can, what is that expression?
I have tried several things but iam n00b in matlab so i need your help.

In summary what i ask is:

position = get(handles.pos,‘value’) % e.g. get user speed from slider
fprintf(S,’#0P’) %i want the position to change
according to the value from
user,what is the proper syntax to write it and the contoler to understand?

Thanks in advance,
Panos.

no one knows?

:frowning:

If you use the search function of the forum for matlab you should find 8 more threads. You may find an email of other matlab users in there, and they might be willing to help you. I’m sorry, but I don’t know how to help you.

Ok,
after i spent alot time on that issue i found out how to make it work
So, i am giving you the solution (although its not very professional) but it works.
**
S=serial(‘COM4’, ‘BaudRate’, 115200,‘Terminator’,‘CR/LF’);**
**fopen(S) ** %open port
**position = get(handles.pos,‘value’); ** %get value from slider of position
temporary = sprintf(’#0P%d’,position); %store using sprintf function the
whole sentence as a a single character in order the SSC32 controller to recognise.
**fprintf(S,temporary) ** % send the instruction to the SSC32
**fclose(S) ** %close the serial port

:smiley::smiley:

man !
thanks very very much :smiley:

i had the same problem and i was checking for a solution and your thread just answered my doubts…

thanks again and thank for the guys of lynxmotion for this forum :smiley:

I’m glad the forum was helpful! 8)

For those that use Matlab, the below link has some info on Matlab serial port operations that might be useful.

cnx.org/content/m12062/latest/

Made this a sticky.

I had a question around this topic so i thought I should drop it in here.
its regarding the SSC-32 Query command through matlab.

I am trying to read the status of servo i.e. either “.” or “+” through the query command as mentioned in SSC-32 manual.
here are the commands I am issuing through matlab:

S=serial(‘COM10’, ‘BaudRate’, 115200,‘Terminator’,‘CR/LF’);
fopen(S)
fprintf(S,‘Q’);
query=fscanf(S);

When fscanf(S) is executed,it results in a pause for about 4-5secs and then matlab command window prompts “warning:connection timeout while reaching the terminator” something like that…
and after that it displays the result ,either “.” or “+” depending upon the servo motion state.

My question is about the delay and the warning msg result while reading the port.Why is there such an extended delay while reading the port and why this warning message?The same is the case if fprintf(S,‘VER’); command is issued. i.e. matlab first prompts the connection timout warning and then the SSC-32 returns the value.
Any thoughts?
Thanks
cheers

just to confirm ;
is the following a complete write serial date command or should it include the terminator i.e. at the end as well?

fprintf(S,’#0P1500T2000’)

thanks

If you get the expected data back, then the command is probably correct. The below is from a quick google search that might be of help. My guess is that matlab doesn’t know how long to wait for more data comming into the serial port input buffer, or what to look for to know that it is time to display the collected buffer contents.

tinyurl.com/mhnkaz

So how to move the servo to two positions through matlab?

I mean first give the command for position1

fprintf(S,’#0P1500T2000’)

and then should there be a Query command to ensure “.” is recieved before sending

fprintf(S,’#0P2350T2000’) for position 2? or how should the two statements be placed in order to move the servo to position 2 after successfully reaching position1?

Any thoughts?

Thanks a lot.

If you need a delay between positioning the servos, then that will probably need to be handled by the matlab code. If you are sending timed movements to the servos, then you may can query the ssc-32 in a loop until the “.” is returned to verify the final position has been sent to the servo, then send the next command for the next servo. It might be more practical to just wait in matlab the same amount of time as the servo is commanded to take to move.

thanks zoomkat for your assisstance.
I’ll try both the ways to see which one suits my case the best. Since i am intending to trace a spline curve which is in x,y,z format so, i would have to check whether reading the SCC-32 Query return is quicker or just putting time delays after a motion command would be sufficient for perfect trajectory following.

thanks again
cheers

You can also query the last pulse width sent to the servo. It appears that timed moves are made using a string of increasing/decreasing position commands to the servo which can be monitored. You should be able to send commands to a second servo based on the position reported position of the first. Probably the best idea is to send small incremental position changes to all servos using a formula generated in software.

Query Pulse Width.

Example: "QP "

This will return a single byte (in binary format) indicating the pulse width of the selected servo with a resolution of 10uS. For example, if the pulse width is 1500uS, the returned byte would be 150 (binary).

Multiple servos may be queried in the same command. The return value will be one byte per servo. There will be a delay of at least 50uS to 5mS before the response is sent Typically the response will be started within 100uS.

I was using the Group servo move command and moving the following servos with 2 sec time command through matlab.

#20P1500#21P1500#22P1500#4P1500#5P1500#6P1500T2000

but the servos donot move in 2 secs. They move at a very high speed.Even changing the time does not reflect any change in the servo speed.

However if a single servo is moved through

#6P1500T2000

it moves in 2 secs.

what’s wrong with the group servo command?

not sure if this applies but remember that the 1st command you send to the controller after power up doesn’t allow for speed commands because it has no idea where the servos are. after the first move completes the timed and speed commands work properly.

what should come in the field? I tried putting servo channel number but it didnt work!

Thanks

The would be the servo number you are querying. Try querying the servo using lynxterm to see if that works. This can determine weither there is some hardware issue of a matlab issue.

I tried issuing commands like

QP#04, QP04, QP’#04

in the lynxterm, but none returned any output!

Any thoughts?