Sharp programing on picaxe
Ok so I want a basic obstacle avoiding program with my sharp sensor. It is made on the start here robot. The programming language is picaxe basic. After hours of trying I still cant get it going correctly. So i hope u can help me. Thanks
The idea- It is supposed to read the distance and then decide whether it is far enough away to proceed forward or to go to sub program ahead (go backword, I know confusing haha sorry). So if you have any ideas please tell me. Better yet revise my program or make a new one and show me it. Thanks! First time with sharp.
main:
readadc 1, b1
if b1 < 170 then : goto behind : else : goto ahead: endif (yes I know they are switched in the names sorry)
wait 2
goto main
behind:
backward A ' motor wiring is that way to go forward
forward B
goto main
ahead:
forward A
backward b
goto main



@ Thu, 2011-06-02 00:24
That is what is it supposed to do!
Your code is working properly.
In terms of the readadc in the sub routine --You can do something like this:
behind:
backward A
forward B
readadc 1, b1
if b1 < 170 then goto behind
else
return
@ Thu, 2011-06-02 00:44
final mostly working program
main:
readadc 1, b1
if b1 < 184 then : gosub behind : else : gosub ahead : end if
return
behind:
backward A
forward B
readadc 1, b1
if b1 < 184 then : goto behind : else : return
end if
ahead:
forward A
backward b
return
@ Thu, 2011-06-02 00:35
ok.. this is what i have with what u just said
ok.. this is what i have with what u just said but it still goes forward then backward randomly.
main:
readadc 1, b1
if b1 < 180 then : gosub behind : else : gosub ahead : end if
return
behind:
backward A
forward B
readadc 1, b1
if b1 < 180 then : goto behind : else : return
end if
ahead:
forward A
backward b
return
@ Thu, 2011-06-02 00:26
haha
oh ok i had them switched haha. i see i have much to learn with sensors. thanks chris for bieng so patient with a begginer. :)
@ Wed, 2011-06-01 23:54
Alright no worries
No problem, you are actually closer than you think.
At this point, you gotta "think" like the program. What I do a lot is to grab a pencil or sylus or whatever and actually point at the screen, line-by-line and "step" through my program manually. As you get to your goto's and gosubs, you can actually see your pencil-pointer loop its way through the program. This seems silly, I know, but it will help plenty. Take for example, your code above.
Try some gosubs and returns instead and also stick your pause into the sub-routine. Another thought is to stick another ADC check into your subroutine. You can keep checking your sensor within the subroutine and if it is still < or still> you can stay in the subroutine. If the sensor says you have moved enough, then you can return to the main loop.
@ Thu, 2011-06-02 00:17
ok...
ok for some reason it just goes forward for a bit then backwards. also where do i put my waits or pauses?
does this need to be changed? -
main:
readadc 1, b1
if b1 > 176 then : gosub behind : else gosub ahead : end if
return
a
@ Thu, 2011-06-02 00:05
new program
ok how does this look? from what u said i think i did it right but u know more than me haha
main:
readadc 1, b1
if b1 < 170 then : gosub behind : end if
if b1 > 180 then : gosub ahead : end if
goto main
behind:
backward A
forward B
readadc 1, b1
wait 1
return
ahead:
forward A
backward b
readadc 1, b1
wait 1
return
@ Wed, 2011-06-01 23:59
thanks so much keep posted !
ok thanks makes good sense. thanks for putting this so i can understand. will show u what i come up with.
@ Wed, 2011-06-01 23:21
Thanks, birdmun
I sorta wondered about that too...
I just went ahead and assumed that this was quickly-written psudeo-code. It's probably good that you made mention of the fact that it might not be. In the event that this is the actual code used, a little direction might save a lot of frustration.
--Oh, and bird... Picaxe is NOT case sensitive nor does it care about tabbing. Weird...
Questions:
Is this the actual code you are using?
Is forward and backward actual commands? --As I remember, picaxe has some "classroom" commands built in. I.e. wait (seconds) instead of pause (milliseconds) etc. I think "forward" and "reverse" might actually be real commands, designed to work with 4 pre-determined pins. Is this the case?
@ Wed, 2011-06-01 23:31
thanks but...
ok first of all the numbers i got are from the debug. also yes the forward is just replacing the high 4, low 5. If u look on the start here robot. I used that code just took out the servos. does that help? I have used subs but it seems that they dont do much good. thanks