Problem with Servo Control (PSC)
My PSC (serial) just came in the mail and I managed to get to the stage where the LED is actually lit (which is a tremendous feat for me), so I tried the source code from the Parallax PDF page.
I copied and pasted it exactly as is, and it goes to the same positon each time, no matter what numbers I put in for pw or ra. Can someone explain to me in simpler terms exactly what variable does to control a servo.
Thanks
' {$STAMP BS2} '{$PBASIC 2.5} ch VAR Byte pw VAR Word ra VAR Byte Sdat CON 15 baud CON 396 ra = 7 ch = 11 DO pw = 1250 SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch, ra, pw.LOWBYTE, pw.HIGHBYTE, CR] PAUSE 1000 pw = 250 SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch, ra, pw.LOWBYTE, pw.HIGHBYTE, CR] PAUSE
I copied and pasted it exactly as is, and it goes to the same positon each time, no matter what numbers I put in for pw or ra. Can someone explain to me in simpler terms exactly what variable does to control a servo.

Thanks

Comments
pw is a Word -- two bytes (the two halves of the world are sent as pw.LOWBYTE and pw.HIGHBYTE). The PSC uses 2us units, so pw=750 = 1500us or centered.
If your servo always goes to the "same position" what position is that? Centered? If so, is the servo plugged into servo port 11?
Do you have adequate power to both the PSC servo V+ terminal block and separate power for the Stamp? Do you have the PSC plugged in to PIN 15 of the Stamp? When your program runs you should see the green activity light on the PSC flicker rapidly? (It does this when receiving serial data.)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
I double checked that servos were connected to the right port, as well as the PSC. I am using 4 AA batteries to power the PSC separately and a 9V battery for the stamp. I also see green activity light when the program is running.
I tied a rubber band to the left-most horn when I turned it as left as I could, and each time it moves to the position that is 90 degrees right of it. (The next horn over's position). No matter what numbers I put in or wherever I start it from, the horn will always go in that position.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
also, I forgot to say but there's a green light (flickers a couple times for about 1 sec)
Post Edited (skatj) : 1/19/2008 3:46:34 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
http://i137.photobucket.com/albums/q224/skatj/servosetup.jpg
(ignore the stuff on the breadboard)
a) it sure looks like you have your servos plugged in to channels 14 and 15; the code sends changes to channel 11
b) code only does one servo (11)
In the PSC command, the ch var is the "channel" servo number 0 - 15 ON THE PSC.
So... if the photo is accurate, try this. I'm getting rid of most variables, so you can hopefully see some results.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
1. Would you post the *exact* code and a picture of *exactly* the setup you have when you run that same code? That way we can at least baseline it.
2. How are you getting power to the servos -- it looks like you connect the power leads from the AA battery holder into one of the servo cables?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
I hooked up a battery holder with 4 AA batteries (1.5V each), to the positive and negative terminals of the PSC.
edit: I tried the last code you posted, with the exact same setup. Both servos moved this time (expectedly), but to the same position as I described before. It seems like the connections and everything are in working order but I dunno..
also, I don't know if this is significant, but the servos are locked in place while the PSC is on, I can't move the horn with my mind or anything, but then again that might be normal.
Post Edited (skatj) : 1/19/2008 5:44:47 AM GMT
Yes -- that's normal -- these are motors with circuitry to move them to the position set by the pulsewidth they receive, and they are always trying to maintain their position -- the PSC will always keep sending whatever pulsewidth (position) it was last told to send on that channel. On reset it sends 1.5ms (centered) position to all servos.
Unclear from your last post if it's working or not? My code should send each servo to 1ms then 2ms, in turn. Then back again, over and over. On most servos 1ms to 2ms would be about 45 degrees from center in one direction, then 45 degrees past center in the other direction.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Did you check your communication set up with the version instruction, the code is in the PSC document.
Did you remove the jumper that sets the channels from 0-15 to 16-31.
If the above is OK try a fresh set of AA's for the servos remove one of the servos and just try and get one to work. Although you are providing power to the servos through one of the channel pins, which is fine, the PSC is designed to have the servo power connected via the small blue screw connector, but you may have a reason why you would rather use a channel connector.
If you get past the above checklist Zoot's code should work
Jeff T.
2. I ran the code from the PSC document, if that's what you're talking about, my firmware version is 1.4
3. Which jumper is this? I have the red/black/white cable plugged into the left port, not the right one, but I dunno if that's what you're talking about.
4. I have the battery pack soldered onto the pins under the blue screw connectors. The batteries are fresh out of the box.
Okay, this time I tried using just one servo on channel 15. I used Zoot's code, changing 14 to 15.
What happened was, for some reason this time I could move the servo easily with my hand (although there was some resistance). When I started the program, the servo moved to the same position as before (the only one that it would move to), and every time I moved the horn away from that position, it would go back to where it was. Any reason why it's behaving differently today? I didn't change anything.
Speaking as someone who has no idea how servo pulse control works, it seems like the signals are reaching the servo controller, but something's causing it to interpret every signal as the same position each time.
Post Edited (skatj) : 1/19/2008 7:57:44 PM GMT
Jeff T.
EDIT: I know you have this covered but I have to say make sure SW1 of the PSC is in the on position
Post Edited (Unsoundcode) : 1/19/2008 10:01:14 PM GMT
The jumper unsoundcode is referring to will make the PSC answer to channels 16-31 instead of 0-15. If it's not installed, fine. But I do suggest you read the PSC documentation which discusses the jumper and so forth.
You soldered leads to the terminal for power? Any reason not to just use the terminal block?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
I dunno if this is worth mentioning but when I move the servo horn out of its place and it goes back to its original position, the green LED doesn't flicker. It only flickers when it actually sends the pulse (I removed the do/loop from the above program to verify), but I don't know if that's normal behavior.
Thanks for the help though guys, maybe I got a defective one or something =/
To be honest, I wouldn't know how else to connect the battery pack wires. What plugs into that square opening in the blue terminal?
Post Edited (skatj) : 1/19/2008 11:31:44 PM GMT
The blue terminal block lets you insert wires and tighten them down with the screws on top.
Now, I think there *is* something funky going on here, because your setup basically looks OK, BUT I STRONGLY advise you to read through the PSC manual *carefully*. It has wiring diagram for terminal block, explains the jumper, etc.
Additionally, you might want to download and check out "Robotics with the Boe-bot" and read the chapter on servo control -- it's a great a explanation of what servos are, how they work, and how to control them with microcontrollers.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
I didn't see anything about the wiring other than the picture with two wires going into terminals (which didn't really show whether it went under or in it), same with the jumper.
Anyway I'll keep trying.. and I'll definitely read through the servo control chapter. Thanks guys.
Strip back about 1/4 inch of the insulation of the servo battery leads, push them firmly in the blue connectors then tighten with a small screwdriver. As you look down from the top the red positive wire should be in the right hand terminal and the black negative lead in the left.
The servo channel numbers·are printed on the PSC board against their respective pins, they might be difficult to line up at first so just double check you have the motor connector in the channel that matches your code.
Jeff T.
Jeff T.
This code will cycle through all 15 channels. It will take ~32 seconds to go through the whole thing.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Post Edited (Zoot) : 1/20/2008 2:38:06 AM GMT
And it worked! Then, after running it again three times, it stopped working. So um.. Yea. I really don't know. Is it possible I'm damaging something somehow?
Also, looking at the PDF manual on page 3, the plastic jumper thing on the diagram appears to be on the Vin side, rather than the Vdd side. Is that correct?
Jeff T.
The jumper on your BoE must be set to Vdd if you are plugging the PSC into one of the servo ports on the BoE. The "power" that goes through the red wire from the servo port to the PSC needs to be the "regulated" Vdd -- which is a stable 5v. Vin is raw power from the batter and *could* damage your PSC.
- jumper on BoE to Vdd
- no jumper on PSC (so it responds to channels 0-15)
- plug a servo into any channel on the PSC and run the code I posted most recently. Wait at least 64 seconds and the servo should move through it's cycle twice.
- if not, triple-check your connections again and go through the PSC manual one step at a time. It can be tedious sometimes, but it's always worth it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
I took out my stamp and ran some code.
(Channels and stuff were correct). And it worked, again. After running it a couple of times, it stopped working, again.
I then tried your program that inputs position values through the DEBUG terminal, and that didn't work either. (I triple checked channels) In fact, the PSC wasn't even holding it in place. I could push the servo horn without any resistance at all. (the green LED still flickered though).
So I turned it off and went to work on another project, and disconnected it from the stamp.
And then...
I heard a gurgling sound and I looked around frantically for the source - It was my battery pack: one of the batteries leaked a blackish liquid! My PSC was off and disconnected at the time, so I don't know if that damaged it somehow, but this makes me suspect that the underlying cause of all my problems is with the power. Any ideas guys? What does this battery leak mean?
(All batteries were fresh from the same box, btw)
Post Edited (skatj) : 1/20/2008 9:05:06 PM GMT
Jeff T.
What do you mean by this? I've been meaning to ask this, but is there some protocol on what to turn off when you're DLing a program? I usually turn off the PSC first, then switch the Stamp power back to 1, DL the program, then turn on the PSC and switch the stamp power back to 2, but I know there are times when I didn't follow this order.
But yea, I'll try connecting the battery leads to the terminals this time.
(I heated up the solder on the pins and sort of flicked it off, if there's a little solder left on them but they aren't touching the other pins, that's okay right?)