Let's Make Robots!

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.


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



backward A ' motor wiring is that way to go forward 

forward B

goto main



forward A

backward b

goto main

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

after i used the start here program I then made my own simplified program. i hope it helps and please reply :)

**I am not a PICAXE moderately well versed/expert.

He is correct. You need to know what numbers to expect for a given distance.

The rest of this is more academic.

If the listing you show is the extent of your program, then I fnd it hard to believe you will ever get anything to move. I don't know if PICAXE basic is case sensitive, but, I am fairly confident that forward/backward, A/B/b are not defined.

*PICKING NITS* If you care, you should use subroutines and therefore gosub/return rather than, for example, ahead:/goto main. Proper programming would see you replace goto ahead with gosub ahead and then in your subroutine when it is finished return instead of goto main.

Skip the motor for now and just put a debug into your code after readadc. From here you can see what the actual numbers are coming out of the sharp sensor. This should tell you clearly if your sensor is working correctly and what values you should be using as a "turning threashold".