Shop OBEX P1 Docs P2 Docs Learn Events
Help! Using “Servo controller” with a PC — Parallax Forums

Help! Using “Servo controller” with a PC

DumBDumB Posts: 8
edited 2006-07-26 15:41 in General Discussion
Hi
Can you guys offer some help on sending commands to the 'Parallax USB Servo Controller' from a PC, without using the PSCI Application? confused.gif
I'm Using C#.Net for developing the custom application for PC.
Thanks in Advance
Binesh

Comments

  • dandreaedandreae Posts: 1,375
    edited 2006-07-24 18:50
    You can use "Hyper-Terminal" with the documentation from the serial version of the PSC to
    send commands to the USB version of the PSC.· Here is a link for the serial documentation:· http://www.parallax.com/detail.asp?product_id=28023·.

    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Tech Support
    dandreae@parallax.com
    Http://www.parallax.com

    ·
  • DumBDumB Posts: 8
    edited 2006-07-25 02:24
    Hi Dave,

    Thanks for the link.
    Now, I'm able to get the PSC Version and the Servo Position thru Hyper Terminal. But unable to set the position.

    Still i need help on the syntax to use the following at hyper terminal:

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

    Kindly suggest a example for the above command. Do i need to send as HEX / DEC ? Is the Comma (,) separater required?

    Thanks,
    Binesh
  • DumBDumB Posts: 8
    edited 2006-07-26 04:06
    Hi Dave,

    I'm using HyperTerminal and the following two commands gives me response.

    !SCVER?
    1.4
    !SCRSP0
    0
  • CJCJ Posts: 470
    edited 2006-07-26 11:04
    it may be quicker / easier to make a very basic app that takes input for channel and position, chops the position variable into bytes, then sends it out the serial port. you may be able to get hyperterm to work, but why not build the snippets of code you are going to need anyway for the end project, the protocol is well defined and you have a good communications path

    the hex values you are using look good for the position and byte order, but they have to be single bytes, to get hyperterminal to work, you would have to figure out a way to enter characters with the proper ascii(byte) values

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who says you have to have knowledge to use it?

    I've killed a fly with my bare mind.

    Post Edited (CJ) : 7/26/2006 11:12:57 AM GMT
  • Will__SWill__S Posts: 19
    edited 2006-07-26 15:41
    I've been working on controlling my psc through my computers usb port. I've created a little python program that will do this. I've been using it to control the legs on my robot until I perfect the walking gait. To use this you'll need to have python installed, and you'll also need pyserial. You should easily be able to google for both of those. I also believe a requirement to installing pyserial is that you get ez_setup and maybe pywin if you're on windows(I'm windows. Note: this wasn't tested on any other platform).

    All are small files, and if there's any interest in this I may look into creating an executable file that will just take in a file that pushes out the commands. This python program is still in development, and will be improved upon(there's not a whole lot of error catching).

    So if you're familiar with C# you shouldn't have much of a problem with this. So here's my attempt at explaining how all of this works:

    The psc.py file has a class called Psc. Psc has 3 methods and a constructor. 1 method gets the version from the psc 'getVer()', 1 method will send commands to the psc 'moveServo()', and 1 closes the connection 'cleanup()'(just started learning python, so I haven't looked into a destructor yet). When you create an instance of the psc class you supply the com number only. Make sure that before your program exits it calls cleanup() to close the com port(though I haven't seen any il-effects of not doing so). When calling moveServo() you supply in this order: the channel, the ramp rate, and the desired position. You will cause an error if you pass in values that are out of spec(too high, or too low) according to the psc(serial) documentation on parallax's site. If you pass in erroneous values the program will not send the data, only cause the error. If you read through the method you'll find what the values are if you don't feel like reading through the psc(serial version) manual.

    So without further delay here is a quick example!

    #################
    #file name is test.py ||| must be in same directory as the psc.py file
    import psc
    import time #used for pausing between sending commands

    myPsc = psc.Psc(3) #creates a new instance of the Psc class on com 3
    print myPsc.getVer() #prints out the version of the psc

    myPsc.moveServo(3, 10, 1325) #moves the servo on channel 3 with a ramp rate of 10 to position 1325
    time.sleep(1) #pause execution for 1 second allowing servo to move to desired position before sending it another command
    myPsc.moveServo(3, 0, 750) #moves the servo on channel with with no ramp rate to position 750 (center)
    myPsc.cleanup()
    ###################

    Note: no hex needed!

    So there's a very basic example. I've also attached the project I've been working on. The leg.py file contains a class that represents a leg of my robot, and the movement.py creates 4 legs and issues commands to make it walk.

    The other option instead of creating a sperate file, you can just edit everything under the "if __name__"... statement, and run the actual psc.py file. Follow the example included under that statement as it is a working example if you run the file by itself.

    I hope I haven't just confused you, and I hope that you will find this useful(and maybe some other members here). Let me know what you think.

    Will
Sign In or Register to comment.