Hello, I need to make a program that will move a servo until the GP2D12 reaches a desired value. The min range is 1" and max 14". The part that i don’t get is if i tell (in my program) for a servo to reach a value (ex. 275), the value 275 exists in two different areas on the IR sensors data sheet. Does anyone have a program that can determined between the two possable values and choose the right one?
O.K., the bad news, i’ve tried to make a few programs but they have utterly failed . But the good news is i’ve got LYNXMOTION!
Could i get some pointers on what types of commands to use as i describe the program?
I have a 14" track with roller tray controlled by a servo and a GP2D12 ir sensor for a “tray-positioning device”. I need a program that i can tell a servo to go until the ir sensor has reached a certain value.
so im going to attempt to make a program.
[code]
irvariable var byte
loop:
adin ax0,1,ad_ron,irvariable
“now i need a command that will make the servo move until irvariable reaches that value”
I’m not a programmer, but… I don’t think you need a “next” when using “repeat…until”. No idea if this’ll fix your problem, but hey, I might as well mention it.
thanks, i probably needed to put that in too:). Still, my compiler doesn’t like the
servo_pan_r [dec irvariable]
part of it. ???
anybody know how to make this work?
Oh, I think I see what the problem is. Looks like you’re trying to call your “servo_pan_r” subroutine, eh? For that, you need to use gosub. Look at the second syntax example here for your application:
One problem is that your variable irvariable is defined as a byte. A byte can have a maximum value of 255, so your testing against 400 or 1000 will not work. Try changing it to a word. That will give it a maximum value of 65535.
I am not sure what this code is supposed to do. It appears to me like this code is very likly to hang:
For example suppose the first adin gives you a result of lets say 250.
Now you have the code:
repeat
gosub servoR
until irvariable < 200
It says to repeat calling ServoR until the irvariable is less than 200. But there is nothing in this loop that changes the value of irvariable, so you will probably simply hang there. I am not sure exactaly how you wish for this code to work. If you are simply wanting to go right and go left, you might change the code to look something like:
[code]counter var word
irvariable var word
loopyloop:
repeat
adin ax0,1,ad_ron,irvariable
gosub servoR
until irvariable < 200
Oh that makes sense. So the
adin ax0,1,ad_ron,irvariable
part makes irvariable equal the sensor reading. Now it should constinely get new values for irvariable .
What is program is doing is using the GP2D12 as a positioning device for a servo on a linear track. the robot track looks simular to this one lynxmotion.com/images/html/proj038.htm
I would post a image if it was possable to do from my desktop .
I believe the documentation said that the AtoD converter was a 10 bit converter. So it has a range of 0-1023 which will not fit into a byte.
If it were me, I would probably add some debug messaging to the loop. For the Pro: I would do something like:
serout S_OUT,I2400,[dec var,13,10]…
Note: you need to set the appropriate baudmode for that atom and var is the name of the variable you wish to output. You can then connect one of the terminal windows at the bottom of the IDE to your communication port and output the values to see where they are going. If you find that it is outputing to many, you can make it sophisticated, like only do an output if the old and new values do not match, or only every so many times through the loop, or after a certain amount of time has elapsed…