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

Parallax Servo Controller

Delus123Delus123 Posts: 9
edited 2006-12-20 19:23 in Propeller 1
I'm trying to connect my servo controller http://www.parallax.com/detail.asp?product_id=28023, to my prop using full duplex serial object but can't seem to get it to work. the code i'm using is:

pub Set(servo,pos,ra)
· 'servo-servo to be set(0-31), pos-servo position(280-1220), ra-ramp rate(1-64)
· ser.str(string("!SC"))
· ser.dec(servo)
· ser.dec(ra)
· ser.dec(pos)
· ser.hex($0D,2)

and the example in the manuel is(for the BS2):

baud CON 396
pw = 1250
SEROUT 15, baud+$8000,[noparse][[/noparse]"!SC", ch, ra, pw.LOWBYTE, pw.HIGHBYTE, CR]

i've called the start function of "ser", which is fullduplexserial.spin, setting the baud rate to 2400 and my tx pin to the pin that the controller is connected to.

if anyone has done anything like this help would be greatly apreciated.confused.gif·· i've tryed using the BS2 object but am not sure about all the variables it calls for such as "bits" int the serout_string.
the servo 32 function works great but i ran out of pinscry.gif .

Post Edited (Delus123) : 12/19/2006 11:26:17 PM GMT

Comments

  • Harrison.Harrison. Posts: 484
    edited 2006-12-19 06:28
    You need to use the tx() method to send raw bytes. I also put in the lowbyte / highbyte stuff. I haven't tested this, but it should work

    pub Set(servo,pos,ra)
      'servo-servo to be set(0-31), pos-servo position(0-1000), ra-ramp rate(1-64)
      ser.str(string("!SC"))
      ser.tx(servo)
      ser.tx(ra)
      ser.tx((pos & $FF00) >> 8)
      ser.tx(pos & $FF)
      ser.tx($0D)
    
    



    Harrison
  • Delus123Delus123 Posts: 9
    edited 2006-12-19 19:10
    I've tried your code as well as every possible variation i could come up with, including sending each charicter in the first part individualy, with no successconfused.gif .· although in reading the manual further the "pos" should be 250-1250 but this does not change my results.· what mode should full duplex be set to i'm currently using mode 2, or open drain/source tx.
  • Harrison.Harrison. Posts: 484
    edited 2006-12-19 21:48
    Post your entire source. If you can't then at least include how you start the fullduplex object.

    Harrison
  • Delus123Delus123 Posts: 9
    edited 2006-12-19 22:44
    {Servo_Controller.spin}
    CON
    ·· _clkmode = xtal1 + pll16x
    ·· _xinfreq = 5_000_000

    OBJ
    ·· ser : "FullDuplexSerial"

    PUB Main
    ·· dira[noparse][[/noparse]16] := 1
    ·· Start(7,21)· 'Im just using the set function which dosnt return anything so 21 is an unused pin.··
    ·· set(0, 1240, 7)
    ·· repeat
    ····· waitcnt(50_000_000+cnt)
    ····· !outa[noparse][[/noparse]16]·············· 'pin 16 is conected to an led to show me that it's at least doing some thing
    ····· set(1, 260, 7)

    PUB Start(rxpin, txpin)
    ·· ser.start(rxpin, txpin, 2, 2400)

    PUB Set(servo, pos, ra)
    ·· ser.str(string("!SC"))
    ·· {ser.tx($21)
    ·· ser.tx($53)
    ·· ser.tx($43)}
    ·· ser.tx(servo)
    ·· ser.tx(ra)
    ·· ser.tx((pos & $FF00) >> 8)
    ·· ser.tx(pos & $FF)
    ·· ser.tx($0D)

    PUB stop
    ·· ser.stop


    I've been looking at the simple serial object and if i can get it to work whold probably be perfect.· The controller manual, http://www.parallax.com/dl/docs/prod/motors/ServoControllerManualRevBv2_4.pdf, specifies the default baud rate as "2400 N 8 2, (no parity, eight data·bits, two stop bits)true data, open-drain (driven low, pulled high)."
  • Harrison.Harrison. Posts: 484
    edited 2006-12-19 23:04
    Your problem is probably the ser.start() mode parameters.

    Your mode was set to decimal 2, which is %0010 in binary. This evaluates to invert tx, which is definately not what you want since you want to send non-inverted 'true' serial data. So what you need to do is change mode to %0100 or decimal 4 to use open drain true mode.

    So change your start to:

    ser.start(rxpin, txpin, %0100, 2400)
    



    Harrison
  • Delus123Delus123 Posts: 9
    edited 2006-12-19 23:08
    It lives!!!tongue.gif· Thank you!
  • Delus123Delus123 Posts: 9
    edited 2006-12-19 23:11
    actualy it' is working but i had both servos 2 and 3· mimic 0 and 1 before returning to their original position
  • Delus123Delus123 Posts: 9
    edited 2006-12-19 23:21
    ok its working now but i had to flip the high and low pos bits
  • Harrison.Harrison. Posts: 484
    edited 2006-12-19 23:22
    Woops... Thats totally my fault, I read the basic stamp example backwards.

    Good to hear it works.

    Harrison
  • mike101videomike101video Posts: 43
    edited 2006-12-20 14:32
    If you want to read BACK the response information from the Servo Controller ( eg version,etc ), make sure you make the rxpin and the txpin the SAME. This works jsut fine in the serial object. ( I've been using a propeller pass thru to allow the PSCI program to control a servo from a PC, with a serial Servo Controller.)

    Mike
  • Delus123Delus123 Posts: 9
    edited 2006-12-20 19:23
    Oh ok i'll try that, i don't expect to be using any functions that have a responce but it might come in handy.
Sign In or Register to comment.