Serial Servo
electric550
Posts: 122
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.
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
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
BTW: I type as I'm thinking, so please don't take any offence at my writing style
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.
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.
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
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
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.
MainRamSerial(NuminBytes,Inlocation,NumoutBytes,OutLocation,Buadrate,StartChar)
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.