Paul, we can help you here but we do need a bit more information to go on.
Firstly, which PicAxe chip are you using, and are you using one of the pre-built PicAxe boards or is this on a board of your own design? Also, how is the robot steering? From the code it looks like you’re controlling direction both with motors and a servo - Is this right? A good photograph of the robot and a circuit diagram would help us enormously.
The first thing that stands out in the code is that you’re using pin 0 both as an analogue input for the range sensor and an output for the servo. Pin 0 can do both, but not in the same circuit. Which pins are these actually connected to?
Post back with the answers and we’ll see what we can do for you.
Its been a while since the last time I worked with picaxe. I am indeed a bit foggy on analog/digital pin designations.
A better point of his is the version of the chip etc. The newer chips have moved on to using a letter/number combination and I can’t remember if simply using an analogRead command means the chip knows to use A0 as instead of a digital pin. Point is, more info is good.
**I think I may have been speaking Arduino for too long now… Gotta get back to the basics once and a while, it looks like. (you can take or leave the pun as you all see fit)
my servo keeps on jettring when i place my hand in front of the SHARP IR… and when i remove my hand servo wont move to any side nd my robot would jst move forward.
Hi Paul. You’ve made a symbol Servo_turn but you haven’t used it anywhere. The servo needs time to reach it’s position after you tell it to turn. The reason being the picaxe executes commands much faster than the servo can move. So you slow the processor down with a pause. Could be something else but I’d start there. Stick a Pause servo_turn in both the lturn and rturn and stopinst subs just after the servo command.
It appears we have exhausted all the “standard” stuff. At this point, you need to break everything down and do this systematically. The first thing I would do is write the simplest program you can to do the following:
Center sensor servo at start-up (leave it centered)
Drive forward
Keep checking sensor
if sensor is closer than threshold then stop (as long as something is there, the bot should remain stopped --remove your hand and the bot should start going forward again)
That’s it. Its really your code, without a servo sweep or any turning. This will tell you if the most basic flow of your code is correct. Once this is established, you can start putting your look-left/look-right back in as well as the turns.
I suspect this simple test program will uproot the problem with your main code quickly.
Well I’m sorry Paul. I guess I haven’t got the answer for you then. As all you give me is it doesn’t turn I haven’t got much to go on. Could be maybe an inadequate power supply, incorrect circuit then. I’d take Chris’s advice and break it down into smaller parts. Get your servo to turn first, get your motors to run one way then another, make the IR trigger an led, and then put the code blocks and circuits together. I would suggest you read this article first and then give it another go.
my bot worked it will sence whats in front but it will only turn right nd if nothings ther then it will go forward. i thing my sharp is not returning a second value in whichway. how shoul i correct it.
It sounds like you have a working system. At this point, I would set it aside and try the next simple code.
For this next program, I would skip the motors and move on to the servo. Leave the chassis motionless and write a program that does only this:
Swing servo to left side, take reading
Put this reading in a variable called "left-something"
Swing servo to the right side, take reading
Put this reading in a variable called "right-something"
Send these readings to your terminal or debug window
Confirm that these numbers are what you are expecting
When you get these numbers coming thorough ok, I would add some code to simply determine with direction is the better way to go (which direction you would want the robot to go) and have that data sent to the terminal or debug window as well.
With this “isolated” test, you can confirm your numbers are what they should be, and you can check this one off the list.
i tested as chris have told. my servo is moving too fast to each side and am not getting a return value from sharp always. some times it return a value. how can i make the srevo move slowly??