Hello, i have a joystick that has two pots that rotate. i’ve connected the pots to the Bot Board II and i’m having trouble getting a program to move a servo porportionally. I’ve tested the values of the pots and they are 540 to 799. I’ve tried setting a servo position to the pot variable but had no luck. Any suggestions?
loopit:
adin ax0,1,ad_ron,xpotvariable
adin ax1,1,ad_ron,ypotvariable
DEBUG [dec xpotvariable, 19]
DEBUG [dec ypotvariable, 19]
PAUSE 1000
goto loopit[/code]
ps (is there anyway to post a image from my desktop?)
It is sort of hard to answer this as you have not stated what you have tried, nor how the servos are connected to your board. Are the plugged into your BB2 or are they connected to an ssc32?
But for now assume that you have a servo connected to pin P4 and you are getting the range 6 to 225.
An obvious starting point is to use the servo command and simply scale the values. On the atom using the servo command, I believe that the valid range for the positions is from -1200 to 1200 with 0 as the center.
So for example lets take the mid point between 6 and 225. It is pretty close to 115. Now if multiply these values by 10 we get pretty close to the full range:
if the adin value is 6 we would calculate (6-115)*10=-1090
if the adin value is 225 we would calculate (225-115)*10 = 1100
This may not give you the total complete range, but it might be good enough to experiment with. It also may not be proportional, this depends on how proportional your pots are. you may have to do corrections to make it linear. Code could be based off of lookup tables, etc.
I hope this helps
Kurt
P.S. - I have not compiled this or tested this so your millage may differ
I played with inputting servo positions from a pot that is on Loki’s QwikFlash controller board. The pot is read into an analog channel, and scaled in range to match the range of one of the 'bot servos. Code is in C for a PIC, so I don’t know if any of it would be useful.
But I believe you’ll want to scale the FS (full scale) range of the pot into the desired range of a servo in the same fashion.
I’m connected to BB2 and using pins (for the pots) ax0 & ax1. My servo ranges are 750 to 2500 with 1500 has 0.
So could i set the xservo variable (after the equation) the pot value and put in like this.
[code]
xpotvariable var byte
xservo var sword
servoloop:
adin ax0,1,ad_ron,xservo
xservo = (xservo - 115) * 10
for counter = 1 to 10
pulsout p0, xservo
pause 10
next
goto servoloop[/code]
(let me get my atom out and try it)
If in your example you needed the range of 750 to 2250 with a center of 1500, you would probably want the xservo equation to look maybe something like:
xservo = 1500 + (xservo-115)*7
So at the value of 6: 737
And at 225: 2270
You may want to use the min and max functions to limit the low and high ends to the valid range for your servo. Or you might want to try the servo command which has the scaling I mentioned in the first reply.
servoloop:
adin ax0,1,ad_ron,xservo
xservo = 1500 + (xservo-115)*7
for counter = 1 to 10
pulsout p0, xservo
pause 10
next
goto servoloop[/code]
humm, the servo just goes to its max position and stalls. I think the value is greater then 2500. (i’ll play around with the #'s)
Can you make xservo value between 750 -2500 with this^?
I’m at school right now, but i’ll look up max and min when i get home.
I’m unformilar with this command but will do some research on it. Right of hand, would it be better to use it for this?
I know what i was doing wrong before. I debugged my pot using a byte and then made the equation so that it would make into something that used a sword . But when i debugged it using a sword, and re-adjusted the math it worked!
However, there is a long time between when the pot is moved and when the servo moves. (way longer than needed )
I’m going to involve my sequencer next
Figured it out!
I read some more about the “servo command” and if you put a …, ttime variable on the end of a “servo” and ttime = 1, you can control the time of it.