PDA

View Full Version : Please Help me



hcsee
07-18-2006, 04:15 AM
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!.··

Kevin Wood
07-18-2006, 06:48 AM
What are you trying to do with the motor controller?

hcsee
07-18-2006, 01:55 PM
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.

hcsee
08-07-2006, 04:21 AM
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=[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 Wood
08-07-2006, 06:49 AM
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

hcsee
08-07-2006, 04:36 PM
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','no ne','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=[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=[cmd 1 13]
%fwrite(s_port,cmd,'async');
cmd=['!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 Savage
08-07-2006, 09:39 PM
This thread is being moved from the·Stamps In Class·Forum to the·Sandbox Forum.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)