Shop OBEX P1 Docs P2 Docs Learn Events
Servo Controller and Matlab — Parallax Forums

Servo Controller and Matlab

ConfusedConfused Posts: 5
edited 2006-04-26 20:21 in General Discussion
I've been trying to figure out how to controll the servos using matlab and its COM interface.
What I whant to do is basically set the positions of the servos.

I get the basic ideas of the COM "language" like:

s = serial('COM3');
set(s,'BaudRate',2400);
fopen(s);
fprintf(s,'!SCVER?')
out = fscanf(s);
fclose(s)
delete(s)
clear s
But even the above doesn't seem to work properly.

If anyone has a good link, a good explanation·or some example code that would be much appreciated.
Thanks!

Comments

  • ConfusedConfused Posts: 5
    edited 2006-04-26 18:17
    Btw.. I've tried to search in the forum for answers but I haven't found any.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-04-26 18:27
    The thing that stands out to me is you didn't include the carriage return ($0D) which is required after all commands. For C syntax (which the matlab code you use seems to emulate), /r after the command should produce the character.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1+1=10
  • ConfusedConfused Posts: 5
    edited 2006-04-26 19:26
    Thanks for the reply!

    I have changed the Terminator for the COM object to CR because the default is LF. However:

    fprintf(s,'!SCVER?')
    fprintf(s,'/r')

    out = fscanf(s)
    out = !SCVER?

    -> So after I scan the buffer it contains "!SCVER?"

    out = fscanf(s)
    out = 1.4/r

    -> If I scan it again I get the above
    This doesn't seem right
  • ConfusedConfused Posts: 5
    edited 2006-04-26 19:29
    Btw I think it's '\r' that's the Carrige Return not '/r'. This gives the same result as above with the change of the "\"
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-04-26 19:42
    oh yes your correct, its a backslash. I think you are getting a loopback of what you are sending out, I think the 1.4 is the answer you are looking for. I suggest reading the helpfiles for Matlab's com library, there may be a means for switching the loopback off. I can't be much assistance beyond this since I haven't worked with Matlab in nearly 5 years.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1+1=10
  • ConfusedConfused Posts: 5
    edited 2006-04-26 20:21
    Anyone that has some examples of code that can be used in Matlab for the actual positioning of the servos or other information to help me?
Sign In or Register to comment.