Shop OBEX P1 Docs P2 Docs Learn Events
Please Help me — Parallax Forums

Please Help me

hcseehcsee Posts: 8
edited 2006-08-07 14:39 in General Discussion
I currently bought a parallax servo motor controller board (part number #28823).·It is·said that the board·can be·controlled by a VB program. I have no idea·of how to program. Is there anyone having such·programming experience?·Could anyone provide me some reference or sample codes ? Thank you for your attention!.··

Comments

  • Kevin WoodKevin Wood Posts: 1,266
    edited 2006-07-17 23:48
    What are you trying to do with the motor controller?
  • hcseehcsee Posts: 8
    edited 2006-07-18 06:55
    The task of the program is to control two servo motors simultaneously by giving the input parameters such as angle and speed. The program should be written in Matlab code (preferred) or VB code. Thank you for reply.
  • hcseehcsee Posts: 8
    edited 2006-08-06 21:21
    I have written a program in MATLAB to control a servo motor via servo motro controller board (#28823).
    As of the command for reading the position of servo motor, I wrote my codes as followed.
    According to the documentation, the device will automatically reply the servo motor position to the input buffer after the command for reading motor position is sent. However, when I trace the variables, I find the BytesAvailable for input buffer is always 0 which means there is no reply from device.
    Is there anyone who also encounted such problem? Thank you for your attention.

    %~~~~~~~~~~~~~~ SMC CMD4 Read the Position of Motor ~~~~~~~~~~~~~~
    % In:"!SCRSP"x (x is the channel number) => Out: x y z (where x is
    %% ~~~~~~~~~ 1.Input Command ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cmd=uint8('!SCRSP');
    cmd=[noparse][[/noparse]cmd 1 13]
    fwrite(s_port,cmd,'async');
    %% ~~~~~~~~ 2. Input Buffer ready to read ~~~~~~~~~~~~~~~~~~~~
    while s_port.BytesAvailable~=3 % (3 stands for the bytes of reply)
    end
    stopasync(s_port);
    %% ~~~~~~~~~ 3. Read Data from Input Buffer ~~~~~~~~~~~~~~~~~~~~~~~~~
    M_pos=fread(s_port,s_port.BytesAvailable)
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2006-08-06 23:49
    Are you initializing and opening your serial port? It doesn't look like you are from your code, but I understand that this might not be your complete program.

    See if this post helps any: http://forums.parallax.com/showthread.php?p=598635
  • hcseehcsee Posts: 8
    edited 2006-08-07 09:36
    Following is my code in completed version. I wrote "get version" command and "setting servo motor position"
    command at first and both of them work well; then it is the command for reading the servo motor position and there is no reply from the device.· Thank you for your reply.

    %~~~~~~~~~~~~~~ SMC CMD4 Read the Position of Motor ~~~~~~~~~~~~~~
    % In:"!SCRSP"x (x is the channel number) => Out: x y z (where x is
    % channer_no, z:y represents the position in binary number
    s_port=serial('COM18','BaudRate',2400,'Parity','none','DataBits',8,'StopBits',1);
    s_port.timeout=0.001;
    fopen(s_port);
    %~~~~~~~~~~ Command 1 ping the device ~~~~~~~~~~~~~~~~~~~~~~~~
    fprintf(s_port,'%s\r','!SCVER?','async');
    while (s_port.ValuesSent~=8)
    end
    echoedInput=s_port.ValuesSent;
    while s_port.BytesAvailable~=11
    end
    stopasync(s_port);
    fread(s_port,s_port.BytesAvailable);
    % ~~~~~~~~ Command 3 set/write the SMotor position~~~~~~~~~~~~~~~~
    %% ~~~~~~~~1. Input Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
    cmd=uint8('!SC');
    ch=1;
    ra=0; %fastest rate
    pwl=50;
    pwh=0;
    cr=13;
    cmd=[noparse][[/noparse]cmd ch ra pwl pwh cr];
    fwrite(s_port,cmd,'async');
    %% ~~~~~~~~~ 2. Output buffer finish transmission ~~~~~~~~~~~~~~~~~
    while (s_port.ValuesSent~=echoedInput+8)
    end
    echoedInput=s_port.ValuesSent; % The device can automatically echo input to output
    stopasync(s_port);
    %~~~~~~~~~ Command 4 Read the position of Motor ~~~~~~~~~`~
    %% ~~~~~~~~~ 0.Input Command ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    %cmd=uint8('!SCRSP');
    %cmd=[noparse][[/noparse]cmd 1 13]
    %fwrite(s_port,cmd,'async');
    cmd=[noparse][[/noparse]'!SCRSP' 1];
    fprintf(s_port,'%s\r',cmd,'async');
    %% ~~~~~~~~~ 1. Output buffer finish transmission ~~~~~~~~~~~~~~~~~
    while (s_port.ValuesSent~=echoedInput+8)
    end
    echoedInput=s_port.ValuesSent; % The device can automatically echo input to output
    %% ~~~~~~~~· 2. Input Buffer ready to read ~~~~~~~~~~~~~~~~~~~~
    while s_port.BytesAvailable~=0 % (8 bytes in +3 bytes out)
    end
    stopasync(s_port);
    %% ~~~~~~~~~ 3. Read Data from Input Buffer ~~~~~~~~~~~~~~~~~~~~~~~~~
    c_pos=fread(s_port,s_port.BytesAvailable) % quite same as fscanf
    % ~~~~~~~~~~~ Program End ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    stopasync(s_port);
    echoedInput=0;
    fclose(s_port);
    delete(s_port);
    clear s_port;
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-08-07 14:39
    This thread is being moved from the·Stamps In Class·Forum to the·Sandbox Forum.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.