PDA

View Full Version : Propeller and SSC-32 servo controller



moomoo
09-03-2007, 07:43 AM
I'm loving the Propeller Chip so far!
I just got the propeller to communicate to an SSC-32 servo controller, finally, using the full delux object, like this...

ssc.str(string("#0 P1500 S1000",13))ии 'servo #0, 1500uS(center), speed 1000

Now my problem is, if I have an accelerometer input and want the servo to change according to the input(what ever that might be), how do I change that "P1500" to something that's changing all the time.
I'm have a hard time figuring out how to do this. I know there is another way to go about this.
Any help would be greatly appreciate!

Tony

Paul Baker
09-03-2007, 08:17 AM
Hi Tony, glad you are enjoying the Propeller. What you want to do to get the variability you desire is to decompose the string into constant parts and variable parts. So to give you the most general example lets create two arrays of variables which each correspond to the position and speed. Since the controller can handle 16 servos, that will be the size of the arrays



VAR
LONG pos[16], speed[16]

Now create a method which will take the servo number as an argument and send the string message to the controller:



PUB Update_Servo(num)
ssc.tx("#")
ssc.dec(num)
ssc.str(string(" P"))
ssc.dec(pos[num])
ssc.str(string(" S"))
ssc.dec(speed[num])
ssc.tx(13)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker (mailto:pbaker@parallax.com)
Propeller Applications Engineer
[/url][url=http://www.parallax.com] (http://www.parallax.com)
Parallax, Inc. (http://www.parallax.com)

moomoo
09-03-2007, 08:33 AM
Thank you very much Paul!

I'm going to try this right now, this really helps alot!

After scatching my head for too long, it starts to hurt.

Thanks Paul.

moomoo
09-03-2007, 11:17 PM
Well, Paul

I tried some things and I can't seem to get it to work. I attached my code so you or somebody can see what I'm doing wrong. I'm missing something somewhere?
I'm trying to center all 32 servos at 1500uS and speed of 1000ms. Is "num" the array for the pin number on the servo controller? And for now, I just set pos at 1500 and speed at 1000.

Paul Baker
09-04-2007, 01:08 AM
NUM and POS are arrays, you shouldn't be doing a direct assignment to the name. Keep Update Servo the way I wrote it and put the iteration in the Start Method:



CON
_clkmode = xtal1 + pll16x '80MHz operating frequency.
_xinfreq = 5_000_000

VAR

LONG POS [32]
LONG SPEED [32]

OBJ

SSC : "FullDuplexSerial"

Pub Start | NUM
SSC.start(7,7,0,115200) 'USING FULL DUPLEX ON PIN 7 @ 115200 BAUD RATE
REPEAT NUM FROM 0 TO 31 'CENTER ALL THE SERVOS
POS[NUM] := 1500 'SERVO CENTER 1500uS
SPEED[NUM} := 1000 'MEDIUM SPEED FOR CENTERING
UPDATE_SERVO(NUM)



PUB UPDATE_SERVO(NUM)
SSC.TX("#")
SSC.DEC(NUM)
SSC.STR(STRING(" P"))
SSC.DEC(POS[NUM])
SSC.STR(STRING(" S"))
SSC.DEC(SPEED[NUM])
SSC.TX(13)



NUM is not an array, it's the index value into the arrays.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker (mailto:pbaker@parallax.com)
Propeller Applications Engineer
[/url][url=http://www.parallax.com] (http://www.parallax.com)
Parallax, Inc. (http://www.parallax.com)

Mike Cato
09-23-2007, 09:20 AM
I've been trying to implement the above code to control my SSC-32 tonight, but I havn't had much luck.

I am a bit new to propeller, so I apologize in advance if I'm doing something trivially wrong. I've looked at the FullSerialDuplex code and I noticed that it's an object of the above code, but I'm not quite sure how it's being included.

Basically all I'm trying to do at the moment is to get a serial tx output going any ideas?

_Mark
09-24-2007, 08:11 PM
Hi Mike, I don't know if I really understand your post, or your question. But if the code above does not work for you, are you sure the pin number(s) used in the code for the serial connection matches the actual pin to which you connected the servo controller?


Btw. I'm puzzled by the above code using the same pin for transmit and receive, unless the mode parameter would be 2 (iirc), but that would not be full duplex and I'm guessing the SSC-32 does not work this way. I think you can only transmit with that code, i.e. you'd have to connect the receiving end (SSC-32 RX pin) to propeller pin 7. To receive anything, you'd need a second pin (unless you like to receive only the same bits that you transmit).

Post Edited (_Mark) : 9/24/2007 12:45:21 PM GMT

Mike Cato
09-24-2007, 11:22 PM
Well the SSC-32 controller has a TX and a RX pin for serial communication. At the moment, I really don't need TX from the SSC-32, I just need to send serial data to it's RX pin from the propeller pin 7. I just haven't had much luck with the above code. I've even specified the correct baud rates for the propeller and SSC. The SSC does have a LED which flashes when it's receiving serial data, and it has yet to flash, which means I'm not sending data from the propeller.

That's my problem. Oh and I'm sure that I'm using pin 7.



SSC.start(7,7,0,115200) 'USING FULL DUPLEX ON PIN 7 @ 115200 BAUD RATE



Also in the code above, what do the first three numbers in the parentheses specify (7,7,0)

_Mark
09-25-2007, 02:34 AM
If you open the FullDuplexSerial.spin file, you'll be able to check its Start method and see what it does (although it might not be obvious how it works at a glance). In case you don't know, the file is easy to find if you select "Propeller Library" from the top drop-down box on the left pane of the proptool IDE. This will show you the files located in the folder where you installed the proptool, which is also where the library object files reside. You may want to set the filter in the bottom drop-down box (all the way down, below the file view) to "Propeller Source (*.spin)".

The first two parameters (rxpin and txpin) are used to tell the object which pins to use for receiving and transmitting, resp. In the code above, it apparently uses pin 7 for both, which is what puzzles me. But since you're only trying to transmit for now, it should be fine. Just don't connect the SSC-32 TX pin to it (if I understand things right, this could cause a short-circuit and result in permanent damage). So, make sure only the SSC-32's RX pin is connected to the propeller, for now.

The third parameter (mode) is documented to mean the following:
mode bit 0 = invert rx
mode bit 1 = invert tx
mode bit 2 = open-drain/source tx
mode bit 3 = ignore tx echo on rx

I.e. the first 4 bits each toggle a specific feature of the object. Paul Baker apparently indicates with the code above that all bits should be zero. I can't test this because I don't have an SSC-32, but it makes sense, and it works for my ASC16 which (I think) is one of its predecessors.

The bit I'm not sure about is bit 2 (open-drain/source the tx output). If my interpretation of the assembly code in FullDuplexSerial is correct, then a 0 for this bit means source TX, and a 1 means open drain. This is opposite from what the documentation would suggest, however it makes sense to have sourcing as default behaviour (i.e. when mode is zero). I'm guessing that's what it is, because, as far as I can tell, the serial comms tests I have done with the propeller so far do not involve open drains nor the pull-up/down resistors that go with it, and I have used mode 0 in each case.

If my ranting about that mode parameter makes no sense to you, don't worry about it. In short, using 0 should work. One thing left to check, is whether or not pin 7 on your propeller is already connected to anything else. This may be the case depending on the circuit board your propeller is on (if any). I'm not intimately familiar with all available ones, so I couldn't tell you without looking it up. Let me know what you find out.

Post Edited (_Mark) : 9/24/2007 6:48:22 PM GMT