I am fairly new to robotics, and I am having trouble programming a Sharp GP2D12 sensor. I am using the atom pro 28 pin, an IDE, and I have two servos on pins 1 and 0, that I want to control from the information recieved from this sensor. What type of command would I use to recieve and use information from this sensor???
thanks
.You don’t program it, you read it. It has an analog output.
maslab.csail.mit.edu/2002/wiki/S … D12_E.html
Alan KM6VV
I think he means he needs to know how to program his atom pro to read the sensor. A quick search of the forum for [gp2d12 atom pro] revealed this…
Reading the sharp GP2D12 IR Sensor with Basic ATOM PRO
lynxmotion.net/viewtopic.php?t=570
I edited it to make it sticky so it will not be so difficult to find in the future. 8)
Here is how you control servos. Note the valid range is 2000 to 4000 with 3000 being centered. The pulsout uses 0.5uS resolution.
[code]low 0 'left servo
low 1 'right servo
leftsp = 3000 'stopped value
rightsp = 3000 ’
start:
pulsout 0,leftsp
pulsout 1,rightsp
pause 20
goto start[/code]
I will do my best to help you, but at some point you are going to have to crack open the manual. You use the debug programming feature instead of the program button. However this method would work too.
my_input var Word
loop:
ADIN P19, my_input
serout s_out,i9600,[dec my_input,13]
' debug [DEC my_input,13]
pause 20
goto loop
After it’s programmed with the program button you click on the terminal1 tab and select 9600 baud, then connect. It will show the results in the tab.
also, the program I am using is,
m var word
mike var word
loop
ADIN 19, mike;
pause 20
if mike < 200 then
gosub s
else
gosub l
endif
goto loop
s
pause 20
low p1
low p0
for m=0 to 200
pause 20
pulsout p0, 4000
pause 20
pulsout p1, 2000
next
return
l
low p0
pause 20
for m=0 to 25
pulsout p1, 4000
pause 20
next
return
the servos are very twitchy when they are operated under the s subroutine. what’s wrong?
First problem is you only need to make the outputs low once at the beginning, you are doing it in your loop. The second problem is you should only have one pause 20. Look again at my example.
[code]low 0 'left servo
low 1 'right servo
leftsp = 3000 'stopped value
rightsp = 3000 ’
start:
pulsout 0,leftsp
pulsout 1,rightsp
pause 20
goto start[/code]
my program is still very twithchy, the l subroutine works great, but in the s subroutine, the servos stop for about half a second, then continue for another half a second, and then repeat. I have tried numerous things to prevent this.
show me the code…
[code]
low p0
low p1
m var word
mike var word
loop
ADIN 19, mike;
if mike < 200 then
gosub s
else
gosub l
endif
goto loop
s
for m=0 to 200
pulsout p0, 4000
pulsout p1, 2000
pause 20
next
return
l
for m=0 to 25
pulsout p1, 4000
pause 20
next
return
[/code][/code]
Ive found that the twitching was just caused by bad batteries, now the program works well, thank you very much for your continued help.