Sign in to follow this  
Followers 0
Exi

COM port for servo position

12 posts in this topic

Hi, i need a little help here with sending to a COM port.

I use martins UDF for a servo controller and a servo, i have connected and received version from the controller by using _CommSetPort, _CommSendString, _CommGetString.

So there is no problem communicating with it, however i want to move the servo now but i have no idea what to send it.

I have tried this but it doesnt move at all.

$Starting = "!SC"
$Cpara = "15"           ;servo is on spot 15 on the controller
$Rpara = "7"             ;movement speed set to 7
$Lowbyte = "1011"
$Highbyte = "1011"

_CommSendString($Starting & $Cpara & $Rpara & $Lowbyte & $Highbyte & @CR, 1)
Sleep(500)
FileWriteLine($file, "" &_NowTime() &"Servo position moved to " & $Lowbyte)

Here is some info from the manual. Syntax: !SC C R pw.LOWBYTE, pw.HIGHBYTE, $0D

CODE
Syntax: !SC C R pw.LOWBYTE, pw.HIGHBYTE, $0D

Reply: none

To control a servo, you must write a position command to the PSC. Each position command is comprised

of a header, three parameters: C, R, and PW, and a command terminator.

The Header: !SC is the header. The header signifies to all devices on the same wire that this is a

command for a Servo Controller.

The C parameter is a binary number 0-31 corresponding to the servo channel number. The servo

channel number should be 0-15

The R parameter is a binary number 0 63 that controls the ramp function for each channel. If the ramp

parameter is set to 0, ramping is disabled and the pulse width will be set to the P parameter sent

immediately. Ramp values of 1-63 correspond to speeds from ¾ of a second up to 60 seconds for a full

500 μs to 2.50 ms excursion for standard servos. This correlation is rather linear though no equation

presently exists.

The P parameter is a 16-bit Word that corresponds to the desired servo position. The range, (250-1250),

corresponds to 0 to 180 degrees of servo rotation with each step equaling 2 μs.

The command terminator, $0D, (CR), must not be omitted.

Share this post


Link to post
Share on other sites



Hi, i need a little help here with sending to a COM port.

I use martins UDF for a servo controller and a servo, i have connected and received version from the controller by using _CommSetPort, _CommSendString, _CommGetString.

So there is no problem communicating with it, however i want to move the servo now but i have no idea what to send it.

I have tried this but it doesnt move at all.

$Starting = "!SC"
$Cpara = "15"           ;servo is on spot 15 on the controller
$Rpara = "7"             ;movement speed set to 7
$Lowbyte = "1011"
$Highbyte = "1011"

_CommSendString($Starting & $Cpara & $Rpara & $Lowbyte & $Highbyte & @CR, 1)
Sleep(500)
FileWriteLine($file, "" &_NowTime() &"Servo position moved to " & $Lowbyte)

Here is some info from the manual. Syntax: !SC C R pw.LOWBYTE, pw.HIGHBYTE, $0D

CODE
Syntax: !SC C R pw.LOWBYTE, pw.HIGHBYTE, $0D

Reply: none

To control a servo, you must write a position command to the PSC. Each position command is comprised

of a header, three parameters: C, R, and PW, and a command terminator.

The Header: !SC is the header. The header signifies to all devices on the same wire that this is a

command for a Servo Controller.

The C parameter is a binary number 0-31 corresponding to the servo channel number. The servo

channel number should be 0-15

The R parameter is a binary number 0 63 that controls the ramp function for each channel. If the ramp

parameter is set to 0, ramping is disabled and the pulse width will be set to the P parameter sent

immediately. Ramp values of 1-63 correspond to speeds from ¾ of a second up to 60 seconds for a full

500 μs to 2.50 ms excursion for standard servos. This correlation is rather linear though no equation

presently exists.

The P parameter is a 16-bit Word that corresponds to the desired servo position. The range, (250-1250),

corresponds to 0 to 180 degrees of servo rotation with each step equaling 2 μs.

The command terminator, $0D, (CR), must not be omitted.

I don't know so it will need a bit of experimenting. Try this

$Starting = '"!SC"';it looks like the quotation marks have to be included.
$Cpara = "1111"       ;servo is on spot 15 on the controller. They say it should be binary
$Rpara = "0111"         ;movement speed set to 7. Binary?
$Lowbyte = "1011"
$Highbyte = "1011"

;you need to add the spaces and commas as the example. I have done that here
_CommSendString($Starting & ' ' &  $Cpara & ' ' & $Rpara & ' ' &$Lowbyte & ',' & $Highbyte & @CR, 1)
Sleep(500)
FileWriteLine($file, "" &_NowTime() &"Servo position moved to " & $Lowbyte)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

I don't know so it will need a bit of experimenting. Try this

$Starting = '"!SC"';it looks like the quotation marks have to be included.
$Cpara = "1111"      ;servo is on spot 15 on the controller. They say it should be binary
$Rpara = "0111"     ;movement speed set to 7. Binary?
$Lowbyte = "1011"
$Highbyte = "1011"

;you need to add the spaces and commas as the example. I have done that here
_CommSendString($Starting & ' ' &  $Cpara & ' ' & $Rpara & ' ' &$Lowbyte & ',' & $Highbyte & @CR, 1)
Sleep(500)
FileWriteLine($file, "" &_NowTime() &"Servo position moved to " & $Lowbyte)
Thanks for your reply martin.

I tried everything you changed and it didnt work either and im pretty sure it have to be "!SC" and not '"!SC"', i tried both tho.

I decided to download Portmon and see what the program from the official site do. the above numbers is my program with these settings

CODE
$Starting = "!SC"

$Cpara = "1111"

$Rpara = "0111"

$Lowbyte = "1250"

$Highbyte = "1250"

_CommSendString($Starting & ' ' & $Cpara & ' ' & $Rpara & ' ' &$Lowbyte & ',' & $Highbyte & @CR, 1)

and below numbers is the program made by parallax which works to move it. As you can see the numbers is not even close to be the same 21 53 43 = !SC

Posted Image

Here is an example from manual too, not autoit tho :)....

CODE
'{$PBASIC 2.5}

ch VAR Byte

pw VAR Word

ra VAR Byte

Sdat CON 15

baud CON 396

ra = 7

ch = 15

DO

pw = 1250

SEROUT Sdat, Baud+$8000,["!SC", ch, ra, pw.LOWBYTE, pw.HIGHBYTE, CR]

PAUSE 1000

pw = 250

SEROUT Sdat, Baud+$8000,["!SC", ch, ra, pw.LOWBYTE, pw.HIGHBYTE, CR]

PAUSE 1000

LOOP

Share this post


Link to post
Share on other sites

Try

$Starting = "!SC"
$Ch = 15
$Ra = 7
$Pw = 1250
_CommSendString($Starting & Chr($Ch) & Chr($Ra) & Chr(BitAND($Pw, 0x00FF)) & Chr(BitAND(BitShift($Pw, 8), 0x00FF)) & @CR, 1)

Share this post


Link to post
Share on other sites

Battery just died, will report back after recharge :)

Share this post


Link to post
Share on other sites

Well that sure made it move, a lil to far tho hehe.

It tried to move more than it could and keept trying, had to shut the power of eventually.

Share this post


Link to post
Share on other sites

Well that sure made it move, a lil to far tho hehe.

It tried to move more than it could and keept trying, had to shut the power of eventually.

Have you tried other values for $Pw, your documentation shows 1250 as the max value.

Share this post


Link to post
Share on other sites

Have you tried other values for $Pw, your documentation shows 1250 as the max value.

<3 Finally working, thanks alot for the help picaxe and martin.

Share this post


Link to post
Share on other sites

Good to hear its working, you might find this interesting.

Share this post


Link to post
Share on other sites

Good to hear its working, you might find this interesting.

Yes that looks interesting. UK as well!. The link to the "Basic command data sheet(pdf)" is broken.

@ Exi. Glad you got it working. I am interested to know what servo controller you are using and the application. Can you tell us?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Yes that looks interesting. UK as well!. The link to the "Basic command data sheet(pdf)" is broken.

I just checked and is OK for me. Another site with good faqs.

Share this post


Link to post
Share on other sites

Yes that looks interesting. UK as well!. The link to the "Basic command data sheet(pdf)" is broken.

@ Exi. Glad you got it working. I am interested to know what servo controller you are using and the application. Can you tell us?

Im using Parallax USB servo controller.

I was wondering if you guys know any distance sensor that would work together with the servo controller. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0