Let's Make Robots!



I'm working now on the code for my new robot and it's not doing what it has to do.

It's supposed to drive around and detect walls, turn and drive furthur.

Do you guys know what's wrong?

This is the code:


Symbol danger = 10
Symbol servo_turn = 700
Symbol turn = 500
readadc 0, b1
readadc 1, b2
if b1 <danger then
gosub nodanger
else gosub whichway
end if
goto main
high 5 : high 7 : low 4 : low 6 'vooruit
gosub totalhalt
gosub servoturn
pause servo_turn
readadc 0, b1
readadc 1, b2
if b1<b2 then
gosub lturn
gosub rturn
end if
low 4 : low 5 : low 6 : low 7
servo 0, 150
servo 1, 150
wait 1
servo 0, 250
servo 1, 50
high 5 : low 4 : low 6 : low 7
pause turn : gosub totalhalt
high 7 : low 4 : low 5 : low 6
pause turn : gosub totalhalt



Comment viewing options

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

That's the wrong code for this sensor or the wrong sensor for this code. This sensor is more like digital. You can set the range with this little screw to your danger distance. The output of this sensor is just  "0"  or  "1"  ...yes kind of digital. The range you set with this screw just triggers the output to  "1" . There is no analog output related to the distance.

You just have to check if b1 is "1" or "0" and b2 is "1" or "0"

I think I wrote (some part of?) that code - it looks like my old standard labels :)

But I do not think I can recognize the mechanics of the robot?!

It looks like a strange mashup, and I think this is what you need to do:

Do not use my code, but delete everything.

Make 1 thing work! Very, very simple thing, make it work 100%, and have no code but the code to make that one thing work.

When done, add one line of code, to make the next thing work. Only 1 thing!!

Move on from there - and if stuck again, you are only stuck with 1 thing, and you can explain to us how you are stuck with that single thing, in every detail. And we need that in order to help.

But I think that if you take the approach of making one thing working at a time, you will not need help the same way ;)

Note; Wen I wrote the original code, and when ever I, and or any body are making something that works, this is excactly how we do it. It's the only way to write code for a robot.

what is the problem , what's it not doing, i looked at your code just quickly nothing sticks out  

your first if could include b2 as well as b1    less than <     grater than >

if b1 < danger and b2 < danger  then 

gosub nodanger


gosub whichway

you may wont to put your left and right readings in byte b3 b4 so you can compare the 4 readings

meh im gessing as to how i think you need it

look into that maybe ?

there's nothing in front the robot so it has no reason to look to the side's and only one wheel is turning.

but thanks for the tips.

yor are only switching 1 motor on at a time  in your motor driver ruteen  2 high's and 2 low's is what is needed


^ the link is to your sensors, if that's the  ir sensors your using , there not analog there switches and you need to adjust the range on the device by hand and read the sensor as a switch / button because all it will give you is a 0 or a 1  0v and 5v

the sensor has a 3 to 80 cm range witch needs to be adjusted to your requirements you may of been in range furthermore sun light can have some affect/effect  on IR sensors  

Good on ya chuckie. That will make a difference. I didn't see how you adjust the distance with it though. Is there a pot on the back? Those rings around it?

The rings around the sensor are mounting rings.

And in the back ther's a little screw which you can adjust the distance.

i would imagine it will be a trim-pot on the back near the led