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

Serial Servo

electric550electric550 Posts: 122
edited 2009-04-12 20:48 in Propeller 1
Could someone point me to a good example of some code that reads in serial and controls 8 servos. My plan is

1. One cog reading in servo values from serial port and writting them to global memory

2. another cod reading the global variables and controlling the servos.


I will be sending the servo values as two bytes each so bassically I will send an A to start the transfer then each servo value will be 2 bytes, then there will be a terminating Z.

So the packet looks like A1122334455667788Z So these values will be read by a program that controls the 8 servos.
This will be less than one long so I was hopping to just parse all the servo values into one long then have the servo program get the 2bytes for each value for control.

sorry about the mess but, does anyone have code that already does something like this, or can point me to something good for this.

Comments

  • simonlsimonl Posts: 866
    edited 2009-04-12 19:26
    Hmmm; I've not seen any code that'll do all you've asked, but there's no reason why you couldn't do this. Should just be a case of gluing the fullduplexserial and servo32 objects.

    I'm a little confused by your assertion "This will be less than one long..." though; a long is only four bytes, and you're showing 18 bytes...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,
    Simon

    www.norfolkhelicopterclub.com

    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again wink.gif
    BTW: I type as I'm thinking, so please don't take any offence at my writing style smile.gif
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-12 19:28
    There are several servo drivers in the Object Exchange. Servo32 can control up to 32 servos. There's a small demo program included with it.

    FullDuplexSerial is a serial I/O driver that comes with the Propeller Tool that includes a 16 byte buffer. I suggest you use one of the other serial I/O drivers from the Object Exchange that has a larger buffer, one larger than your packet size. Some of these come with sample code, but they're pretty straightforward.

    By using these two drivers, you don't have to deal with multiple cogs since each of the drivers takes care of that for you. Your program would simply call FullDuplexSerial for each of the characters of your packet and, as they're processed, would call the servo driver to set new servo positions. The cogs started by the FullDuplexSerial object and the Servo32 object would take care of receiving and buffering serial characters and issuing the servo control pulses as needed.
  • electric550electric550 Posts: 122
    edited 2009-04-12 19:39
    Sorry I meant that I wanted to put all of it into a single 32 bit storage space. Anyways I will look into using that fullduplexserial to write to main memory then read it into with the servo 32
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-12 19:51
    How are you going to put all of that into a single 32 bit word? That's 4 bits per servo which means a value from 0 to 15 for each servo. Is that what you want?

    FullDuplexSerial (or one of the alternative drivers) will provide you with the characters. You can easily write a loop to wait for the "A" and shift in 4 bits for each two characters from the packet, verify that this is followed by a "Z" and repeat after storing the 32 bit long word into a global variable.
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-04-12 19:52
    Hello electric550,

    32bits is EXACTLY the same as four bytes.

    Does this mean that all 8 values range between %0000 and %1111 (binary four bits) then 8 values fit into a 32bits = one long.
    four bits means values from 0 to 15 which are 16 steps from min to max

    If you need more than 16 steps from min to max it will NOT fit into 32bits.

    best regards

    Stefan
  • electric550electric550 Posts: 122
    edited 2009-04-12 19:52
    Ohh...the reason that I need to have one cog running the serial and reading from one main memory bank is that there is also going to be other cogs sending and receiving serial data as well so I do not want them to step on each other. So What I was planning on doing was having 2 cogs writing and reading to a main memory location and having one cog iterating through the memory and sending the data out. So basically there would be approximately 32 bytes in main memory that continuously gets update by the other cogs and there would be serial program that would simply continuously read through the memory area and send the data, regardless of whether the data was updated or not. So basically it would read 16 bytes then write 16 byes and so on. I was wondering if someone had already writing something like this or maybe somebody would be willing to. It seems like it would be relatively easy to do but I have to figure out this crazy language first!
  • electric550electric550 Posts: 122
    edited 2009-04-12 19:56
    oops yea I got my data types mixed up there what I meant to say was that each servo value would take two bytes so I guess that I would be needing more space. I will have to test and see how bad (nochy) servo response is with 256 steps(one byte). I guess that would be enough in that case I would only need one byte per servo. that way I could fit all 8 channels into one 32 bit number if someone has already done something like this let me know.
  • electric550electric550 Posts: 122
    edited 2009-04-12 19:57
    oops I mean 4 channels into one 32 bit number. I guess it will take two 32 bit numbers for 8 channels, well this should be interesting.
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-04-12 20:06
    Hello electric550,

    slow down. To me it is still NOT clear what you want to do.

    Could you please describe in DETAIL what you want to do in a general way.
    I mean something like. I need three serial connections to the propeller
    first connection is for doing .....
    second connection is for doing ....
    third connection is for doing ....

    first connection is just receiving data
    second connection ist sending and receiving data...

    describing WITHOUT using already words like "cog" or "FullDuplexSerial"

    and it will become MUCH clearer if you describe your WHOLE project

    best regards

    Stefan
  • electric550electric550 Posts: 122
    edited 2009-04-12 20:06
    Maybe somebody could create an object that when started writes a setable # of bytes of data to a settable main memory ram location, as well as reads from and sends out a setable number of bytes starting at a settable address, all at a settable baud rate....I am thinking

    MainRamSerial(NuminBytes,Inlocation,NumoutBytes,OutLocation,Buadrate)

    If I can figure out this language i will have to write that. Anyways if someone can do that I would really appreciate it.
  • electric550electric550 Posts: 122
    edited 2009-04-12 20:22
    OOPS I THINK the read would have to Look for a special character to start reading on.....)

    MainRamSerial(NuminBytes,Inlocation,NumoutBytes,OutLocation,Buadrate,StartChar)
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-12 20:45
    You're talking about something that's quite complex. Some of the pieces already exist like a multiple servo driver, buffered serial drivers, and even an object to receive RC control streams. You're not likely to get anyone to do what you want without paying them because you're talking about a lot of work.

    I'd suggest you start by learning Spin and learning how to use a set of objects that will help you with your tasks, like FullDuplexSerial, Servo32v3, and the Servo Pulse Input objects. There are some beginners' tutorials via the Getting Started thread index and the Propeller Education Kit tutorials are also good for getting started.
  • electric550electric550 Posts: 122
    edited 2009-04-12 20:48
    Thanks, yea the main thing that I was wondering was if anyone had done the central memory serial thing. I have seen all of the pieces, I will see if I can put some of them together. Thanks for the help!
Sign In or Register to comment.