Shop OBEX P1 Docs P2 Docs Learn Events
Newbie needs COM port advice (and more...) — Parallax Forums

Newbie needs COM port advice (and more...)

animatoranimator Posts: 1
edited 2008-06-08 08:03 in Propeller 1
Hi there:

I'm working on an animatronics display that is controlled by 3rd party software that sends servo position information to the serial port in the form [noparse][[/noparse]SYNC], [noparse][[/noparse]SERVONUMBER], [noparse][[/noparse]POSITION]. The SYNC byte is 255 (0xFF) and position is a value between 1 and 254, with 127 indicating the center point (the software is written to control typical r/c servos. It is VSA from http://www.brookshiresoftware.com).

I'd like to use this same software to position stepper motors, so that I can drive an x-y slide to position the animatronic characters. My idea is to take the output from the com port, send it to the Prop (I have a demo board) and convert it to step and direction signals that can be sent to my stepper controller cards.

The stepper cards' step and direction signals are normally carried via parallel port on pins 2-9 like so: 2=XDIR, 3=XSTEP, 4=YDIR, 5=YSTEP, 6=ZDIR, 7=ZSTEP, 8=ADIR, 9=ASTEP (low to high transition for step; low for one direction, high for the other).

I figure to do the translation requires knowing the current position of the "servo" according to the software (e.g. 190). By comparing that to the desired position (e.g. 100), one can determine required distance and direction (via the simple equation Desired - Current), where negative numbers correspond to one direction, and positive numbers to the other direction. The result can then multiplied by some constant to convert servo position deltas to number of steps. This info is then sent via the appropriate pin to the stepper card to move the steppers. Easy enough -- in theory, anyway.

Unfortunately, I'm very new to the propeller and to microcontrollers in general, so this is posing quite a challenge to me. My inclination is to break the process down into three steps: 1) Ensure that I can reliably read the servo strings coming from the com port,· 2) ensure that I can send the appropriate signals from the prop to the right pins to move the motors, and 3) figure out how do the translation math.

My prop research has led me to some excellent tutorials and the object exchange. I'm using the Extended_FDSerial object as I tackle step 1) above, and I've hit my first stumbling block (already!). Here's the very simple code I've come up with:

CON
· _xinfreq = 5_000_000
· _clkmode = xtal1 + pll16x
OBJ
· text : "tv_text"
· serial : "Extended_FDSerial"
PUB start | serinp
· text.start(12)
· text.str(string(13,"·· Test of VSA COM port output ",13,$C,1))
·
· serial.start(31,30,0,115200)
· serial.SetDelimiter(",")
· repeat
··· serinp := serial.rx
'' This doesn't work: serinp := serial.rxHex
··· text.out(serinp)

The code works when I set the VSA software to output text strings in the form #[noparse][[/noparse]SERVONUMBER]P[noparse][[/noparse]POSITION][noparse][[/noparse]0x0D]. I see a nice scrolling stream of text. Joy!· However, when I set it to output hex values, the screen throws garbage *even when I try to convert these to strings* via the Extended_FDSerial object's rxHex method. I figure the math will be easier if I keep everything in hex (maybe I'm wrong?), so I'm interested to see hex values are really being sent out to the COM port. Any pointers from the pros on how to get these hex values displayed on my screen?

Any other tips as I tackle steps 2 & 3?

Thanks in advance for any help you are able to offer.

·

Comments

  • SpinHeadSpinHead Posts: 28
    edited 2008-06-08 05:05
    animator said...

    repeat
    serinp := serial.rx
    '' This doesn't work: serinp := serial.rxHex
    text.out(serinp)

    change text.out(serinp) to text.hex(serinp)
  • StefanL38StefanL38 Posts: 2,292
    edited 2008-06-08 08:03
    hello,

    your variable serinp is a long (an integer with 4 bytes).

    RxHex expects that you send characters like "F8C7" and the delimiter

    if there comes just ONE byte use the .Rx-method

    Rx expects a single byte. This byte can have values between 0 and 255

    if you want to see this value as a hexnumber you use

    text.hex(serinp,2)

    where the "2" is the number of digits of the hexadecimal value
    255 is hex "FF" = two digits

    best regards

    Stefan
Sign In or Register to comment.