I was going to put this question in general programming but felt it needs to go under SSC-32 since it is dealing with SSC-32 commands.
Hello guys. I have been trying to figure out an easy way to set all 32 servo banks to 1500 without a lot of code. My problem is how to make the “#P0-31” to be a variable. See code example:
FOR PINs = 0 TO 31
SEROUT SSC32,Baud,"#" DEC PINs, "P", DEC 1500, "T" , DEC 500, 13]
NEXT
The above code doesn’t work. I’m trying to add a variable “PINs” but it’s not working.
It looks like it should work assuming things like baud are setup…
Not sure of which processor you are using, but it should probably look something like:
iPin var byte
for iPin = 0 to 31
serout P11,i38400,"#",dec iPin, "P1500", 13]
next
This will do one pin at a time. You could do it where they all do it at once, by removing the , 13 from the serout in the for loop and have a subsequent serout that output the ,13 once. Something like:
iPin var byte
for iPin = 0 to 31
serout P11,i38400,"#",dec iPin, "P1500"]
next
serout P11,i38400,[13]
Obviously this assumes that you have the serial line on IOpin 11 and the ssc-32 configured for 38400…
I will give those examples a try tonight. The reason I was looking into setting all the servos to 1500 was to set the bot to a starting position at the beginning of the program. When the power is off and I handle my brat, the arms, legs, and head, all move a little, and I like to set them centered on power-up. Sometimes I turn on the bot just to center the servos before turning it back off when putting my Brat away, usually standing leaning against a wall.
Also, I’m using a BS2px MCU. The only difference is the baud config which is not a problem. I set it to use 38.4k and the jumpers on the SSC-32 are configured to 38.4k as well. I was getting an error “” required for the DEC modifier. Let me try your examples and see what happens.
One thing to note: there are no offsets so the bot will go into an uncalibrated center postion meaning there will be joints out of alignment. Anyway, its a quick way to center all 32 servos with just a few lines of code. One could take this base code and add offset values I guess.
[code]’ {$STAMP BS2px}
’ {$PBASIC 2.5}
T38K4 CON 84 ’ Define baud rate to 38.4k
PINs VAR Byte ’ Set variable to 8 bit
SSC32 CON 8 ’ Set I/O Pin to #8
Baud VAR Word ’ Set variable to 16 bit
Baud = T38K4 ’ Set Baud Rate
FOR PINs = 0 TO 31 ’ SSC-32 Pins (32)
SEROUT SSC32,Baud,"#", DEC PINs, “P”, DEC 1500, “T” , DEC 500, 13] ’ Send command(s) to SSC-32
DEBUG “#” ,DEC PINs, “P”, CR
NEXT[/code]
To keep the bot from jumping to fast, you can chage the 500 (.5 sec)value to 2000 (2 sec.) Or 1000 (1 sec.)
are you using a Basic Stamp? I used a BSII to control my board and it worked perfectly. I would think the code would look something like this:
FOR PINs = 0 TO 31
SEROUT SSC32, Baud, “#” DEC PINs, “P”, DEC 1500]
NEXT
SEROUT SSC32, Baud, “T 500”, 13]
If you used your original code:
FOR PINs = 0 TO 31
SEROUT SSC32,Baud,"#" DEC PINs, “P”, DEC 1500, “T” , DEC 500, 13]
NEXT
then the SSC32 would read that as "#1 P1500 T500, CR #2 P1500 T500, … CR #31 P1500 T500, CR.
you need to put your “T”, DEC 500, 13 outside of the loop so that it only sends your time and CR commands at the end, after the servo numbers and positions. otherwise each command will cancel the previous one it it will only move #31 to the center.
The code I posted works fine. It moves all servos to center. I don’t have the issue you are describing. The PINs varaible sends the move command to each servo connected to the SSC32, so each servo gets all the instructions needed to move to center. One thing to note: all servos move to center, however, servos vary slightly so true center is going to be different with each servo unless you use offsets.