Let's Make Robots!

Altered 'Start Here Bot' Code

Im trying to run my start here bot that is has a tamiya twin gearbox and SRF05 instead of the IR sensor on it. All the components work, just not together. I wrote my code (most copied from frits) but my robot just goes forward and back, sometimes sideways about 2 centimetres. Can you post anything wrong in the code that may help to fix this problem

symbol trig = 3
symbol echo = 6
symbol range = b1
Symbol dangerlevel = 65
symbol turn = 300
symbol servo_turn = 700

main:
pulsout trig,2
pulsin echo,1,range
pause 10
readadc 1, b1
if b1 < dangerlevel then
gosub nodanger
else
gosub whichway
end if
goto main

nodanger:
high 5 : high 7 : low 4 : low 6
goto main

whichway:
gosub totalhalt
gosub lturn
pause servo_turn
readadc 1, b1
gosub totalhalt
gosub rturn
pause servo_turn
readadc 1, b2
gosub totalhalt
if b1<b2 then
gosub body_lturn
else
gosub body_rturn
end if
return

body_lturn:
high 5: low 4
pause turn : gosub totalhalt
return

body_rturn:
high 7: low 6
pause turn : gosub totalhalt
return

rturn:
servo 0, 100
return

lturn:
servo 0, 200
return

totalhalt:
low 4 : low 5 : low 6 : low 7
Servo 0,150
wait 1
return








Comment viewing options

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

I kinda get it now. What command do i have to use to read a word variable?

Did you use a byte for range? If so, it probably overflowed and landed back on 35.

I used the b1 variable... The value was changing fine when i moved my hand back and forth. What symbol should I replace it with?

No where in your code do you compare your range to anything. You have triggered the sonar and gotten a number back but you didn't do anything with that number. Also, I noticed you left the dangerlevel symbol at 65 --this is way too low for your sonar. Do some tests with your sonar and get some good numbers. One more, you do have range defined at the beginning but it is b1 --most of your numbers returning from the sonar won't fit in just one byte and it will overflow, maybe many times. Use a word instead.

Ok. I did a test  with the sonar and round for a 30cm or so distance it was about 35... So whats up with that.. If anything I though my dangerlevel was too high...

You still have your read adc in there. If you switched from sharp sensor to a sonar, you dont need this. If nothing is plugged into the ADC channel, it probably returning a 0 thus your code is going to no danger everytime.

Yup, you have got them a lot of places it should not be.

So what should I replace it with to read the SRF05. The pins are kinda scattered everywhere so I have no idea what to write

I’m not an expert on PICAXE programming but I see something that I feel is a bit strange.

main:
    pulsout trig,2 
    pulsin echo,1,range 
    pause 10 
    readadc 1, b1 
    if b1 < dangerlevel then
        gosub nodanger 
    else
        gosub whichway
    end if
    goto main

nodanger:
    high 5
    high 7
    low 4
    low 6
    goto main

From your gosub ‘nodanger’ you'r not returning via a return commant, -but forcing it back on the main loop.
Either you should try returning with a return or you could use a goto nodanger in stead of gosub.
I have no idea if this helps but might be worth a try?