Finally finishing the "start here" bot

I just got the part I need for the "start here" bot, which is the new GP2Y0A02YK0F. My first problem is, I can't remove the old GP2D12 from the cable that connects it to the PICAXE board. If I am also correct, The setup should be the same as the old GP2D12 right? Like where the wires are supposed to go?

 

EDIT: Okay, I got it working kind of. I see one infrared light on in the sensor, but the other doesnt show anything. Is it supposed to light up? Secondly, When i use the program on the "start here" page, My robot just looks left and right, turns, and repeats. Never drives forward. Any suggestions?

EDIT2: Well, after much struggle, I am at a loss. I have nothing else to do. The Sharp IR lights up, no smoke or smells, but whatever I try I just cannot get it to recognize my hand at all. Its hooked up correctly, I am sure of it. I measured 20cm back from the sensor, no response still. I am afraid that I must give up on this if I can't figure out a solution.

Thanks

Oops, posted wrong

probably the problem why

probably the problem why your robot is turning is  because the motor pins are not matching with the code.

Try:

exchange the pins of the motor wires

Well I can’t really exchange

Well I can’t really exchange the pins since everything is already glued together. I could change the code but I am not exactly sure how to put it in. The values that worked for me were:

low 4

high 5

high 6

low 7

 

How do I put those into the code?

well before editing i would

well before editing i would have to know that which pin runs which motor(left or right ) ?

The wire marked “A” goes to

The wire marked “A” goes to the left motor, and the one marked “B” goes to the right.

put this codelow 4high 5and

put this code

low 4

high 5

and tell me which wheel is moving forward(left one or the right one )

**left **

left

 

try this and let me know '

try this and let me know

just copy paste

 

’ This is the program ued to make the video on letsmakerobots.com/start. The program is optimized to make the robot look alive on video, and so it is made to stop up and look around at objects. and if it finds something close (like the camera :wink: it stops and animates.
’ The program is not optimized for abject avoidance or anything else like that.
’ Makes a cute robot, though :slight_smile: And if you made the robot just like the instructions, it should be ready to just download and run!

wait 5 ’ just to give you time to put it down on the table

symbol way = bit0 ’ which direction is head moving
symbol neck = b1 ’ value for servo turning Sharp
symbol maxdistvalue = b2 ’ max value for distance when panning
symbol maxdistvaluepos = b3 ’ position where maxdistvalue is achieved
symbol dist = b4 ’ Value returning from Sharp. non liniar, closer is higher, 35 is 40cm away, but from 100-150 (10 CM) it starts to count dramatically down
symbol lastturn = b5
symbol sharppin = 0
symbol servocenter = b6
symbol soundvar = b7
symbol servopin = 0

gosub lightoff

servocenter = 150

main:
servo servopin, servocenter ’ look forward
gosub distance ’ measure distance
   
    if dist > 60 and dist < 80 then ’ hey, something ahead, turn a little to the side we where turning last time
    servocenter = 150
    gosub lighton
    if lastturn > 175 then
        gosub driveright
                inc lastturn
        else
            gosub driveleft
                inc lastturn
            end if
            gosub lightoff
            goto main
        end if   
   
if dist >80 and dist < 115 then ’ Hey, lets have a look around
servocenter = 150

gosub totalhalt ’ stop
    pause 500 ’ make a natural stop
    gosub choser ’ enter subroutine that decides where to look and stuff
    goto main ’ now return and see if all is OK, and we can proceed
endif

if dist >= 115 then ’ danger: Something is close
servocenter = 150
gosub totalhalt ’ stop
gosub hard_chose
    goto main
endif

if dist < 90 then ’ no danger. we can proceed
gosub driveforward ’ drive forward
endif

if dist < 40 then ’ Absolutely no danger. Look around while drivin
   
    if way = 1 then
    servocenter = servocenter +1 max 225
    else
    servocenter = servocenter -1 min 75
    end if
    if servocenter = 225  or servocenter = 75 then
        inc way
       
    end if

endif

goto main ’ start over


choser:

 maxdistvalue = 0 maxdistvaluepos = servocenter ’ initialize everything

for neck = servocenter to 75 step -1
    servo servopin, neck ’ turn neck
    pause 30 ’ allow servo to turn
    gosub distance ’ measure distance
        if dist >70 then
            ‘pause 50 ’ move hed slower on closer objects
            ‘neck = neck - 3 min 75
        end if
    if dist >  maxdistvalue then
            maxdistvalue = dist
            maxdistvaluepos = neck
    end if
next neck
servo servopin, maxdistvaluepos wait 1
servo servopin, servocenter pause 50 ’ turn neck
   
for neck = servocenter to 225 step 1
    servo servopin, neck ’ turn neck
    pause 30 ’ allow servo to turn
    gosub distance ’ measure distance
        if dist >70 then
            ‘pause 50 ’ move hed slower on closer objects
            ‘neck = neck + 3 max 225
        end if
    if dist >  maxdistvalue then
            maxdistvalue = dist
            maxdistvaluepos = neck
    end if
next neck

’********
’ maxdistvaluepos  is now where the closest object is
’here should be inserted: If really close, have a look, pause and move on
if maxdistvalue > 121 then
    servo servopin, maxdistvaluepos
    wait 2
    for soundvar = 120 to maxdistvalue
        sound 4, (soundvar, 1) pause 1
        sound 6, (soundvar, 1) pause 1
                sound 1, (soundvar, 1) pause 1
                sound 1, (soundvar, 1) pause 1
    next soundvar
end if
’wait 1 ’ look back at the closest object


’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
'calculate opposite:
if maxdistvaluepos <= 150 then
    neck = 150 - maxdistvaluepos
    neck = neck +150
   
    servo servopin, neck ’ turn head to opposite
    maxdistvaluepos = neck
    pause 200
    'start turning body and all
    for neck = maxdistvaluepos to 150 step -1
        servo servopin, neck ’ turn neck while turning body
        gosub driveright pause 3 lastturn = 175
    next neck
   
    dontstopturningA: ’ keep turning till we are frr in front
        gosub distance
            if dist > 60 then goto dontstopturninga
else
    maxdistvaluepos = maxdistvaluepos -150
    neck = 150- maxdistvaluepos
   
    servo servopin, neck ’ turn head to opposite
    maxdistvaluepos = neck
    pause 200
    'start turning body and all
    for neck = maxdistvaluepos to 150 step 1
        servo servopin, neck ’ turn neck while turning body
        gosub driveleft pause 3 lastturn = 0
    next neck
   
    dontstopturningB:
        gosub distance
            if dist > 60 then goto dontstopturningB
   
end if


’servo servopin, neck wait 10 ’ look away from closest


return



hard_chose:
high 1
servo servopin, 75
wait 1
gosub distance
maxdistvalue = dist

servo servopin, 225
wait 1
gosub distance
    servo servopin, 150
    wait 1
   
    if  maxdistvalue > dist then
   
    turnon:
    gosub driveleft
    gosub distance
    if dist > 50 then goto turnon
   
    else
       
        turnoff:
        gosub driveright
            gosub distance
                if dist > 50 then goto turnoff
            end if
    low 1
return



distance:
readadc sharppin, dist
return

totalhalt:
low 4 low 5 low 6 low 7
return

driveright:
‘servo servopin, alltv
high 5 low 4  ’ h
high 7 low 6’ v
return

driveleft:
'servo servopin, allth
high 4 low 5  ’ h
high 6 low 7  ’ v
return

driveforward:
low 4
high 5
high 6
low 7
return


lightoff:
high 2
return

lighton:
low 2
return

Now it just spins in a

Now it just spins in a circle the same direction and does not stop.

oh sorry my bad i just gave

oh sorry my bad i just gave you the code attached in the start here section

just give me few moments

This should work Symbol

This should work

 

Symbol dangerlevel = 70 ’ how far away should thing be, before we react?
symbol turn = 300 ’ this sets how much should be turned
symbol servo_turn = 700 ’ This sets for how long time we should wait for the servo to turn (depending on it´s speed) before we measure distance

main: ’ the main loop
readadc 0, b1 ’ read how much distance ahead
if b1 < dangerlevel then
gosub nodanger ’ if nothing ahead, drive forward
else
gosub whichway ’ if obstacle ahead then decide which way is better
end if
goto main ’ this ends the loop, the rest are only sub-routines


nodanger:’ this should be your combination to make the robot drive forward, these you most likely need to adjust to fit the way you have wired your robots motors
low 4 : high 5 : high 6: low 7
return


whichway:
gosub totalhalt ’ first stop!

‘Look one way:
gosub lturn ’ look to one side
pause servo_turn ’ wait for the servo to be finished turning
readadc 0, b1
gosub totalhalt


’Look the other way:
gosub rturn ’ look to another side
pause servo_turn ’ wait for the servo to be finished turning
readadc 0, b2
gosub totalhalt

’ Decide which is the better way:
if b1<b2 then
gosub body_lturn
else
gosub body_rturn
end if
return

body_lturn:
low 5 : high 4 : high 6 : low 7 ’ this should be your combination that turns the robot one way
pause turn : gosub totalhalt
return

body_rturn:
low 4 : high 5 : high 7 : low  6 ’ this should be your combination that turns the robot the other way
pause turn : gosub totalhalt
return

rturn:
servo 0, 100 ’ look to one side
return

lturn:
servo 0, 200 ’ look to the other side
return

totalhalt:
low 4 : low 5 : low 6 : low 7 ’ low on all 4 halts the robot!
Servo 0,150 ’ face forward
wait 1 ’ freeze all for one second
return

Well now it goes straight

Well now it goes straight all the time, but it never turns , doesnt seem to notice any obstacles either.

step by step…

Do this:

Main:

readadc whatever_pin_you_are_using,b1

debug

goto main

 

Run that and see if you are getting numbers from your sharp. --I assume you have gotten all the highs and lows worked out so your motors go the way you want them?

I am not getting any change

I am not getting any change when I use all of the pin numbers I can tell. It worked when I first bought it. Also, the IR light is on when I look into it, but only one of them? It was like this as soon as I turned it on.

One is an IR led, the other

One is an IR led, the other is the sensor.

Oh! Thank you I was worried.

Oh! Thank you I was worried.

Alright you are wicked close.

You simply need to do some checking of your senor and the good news is that there are only a few things that can be wrong.

First off, triple check your pins. I am figuring you have a pigtail that came with or matches your sensor. The first thing to do is goto any webshop that sells that sensor and find the PDF data sheet that comes with it. Find the pinout diagram and confirm that the colors of the pigtail are indeed what you think they are. Next, consult /node/75 and triple check those wires are going to the correct pins on the picaxe board. Also note what ADC input you are using. I think we have decided you are using adc 0 (closest to the headphone jack) but again, double check with /node/75.

You may also want to pull the other adc pins down to ground using a little jumper block over the pins. This may or may not be an issue. You can skip this for now --if everything else does not work, you can come back to this.

Plug everything in and check with a digital camera. To the naked eye you should/may see a dim red light in one of the “lenses” on the sensor. Using a camera, you should see a bright purple light. Confirm this.

Run this:

main:

readadc 0,b1

debug

goto main

You should now be able to wave your hand in front of the sensor and see the value of b1 change as your hand moves closer to the sensor and further away. If not, we have one more check…

Grab your multimeter and set it for DC and whatever is closest to 5v. The black lead goes to any ground you can find on the board or battery, the red lead goes to the signal pin on your sensor. You should see the voltage change when you do the hand test. --The multi-tester test must be done when the sensor is powered with 5v (like it would be during normal use).

If we fail the debug test and/or we fail the multimeter test, your sensor is fried or you need to do another round of checking wires and pinouts. If it works, we can move on to why your code is not dealing with it.

–Just a thought, when was the last time you changed your batteries?

Alright, I bought the sensor

Alright, I bought the sensor from here: http://www.pololu.com/catalog/product/1137

I dont see a PDF file other than a data sheet, is that what I want? Second, I used this picture to help me know where to plug things in. http://img854.imageshack.us/i/headpins.jpg/

 Next, I checked the node/75 and all of my wires are connected right. (I assume from my mediocre knowledge) I already have a jumper block over the other pins, so that isnt a problem. When I look at it plugged in, the light does show, so I know it cant be fried. Still doing the readadc debug I do not get any results moving my hand in front of the sensor. I will do the multimeter test in just a bit, I just have to find it. I am using 3 AA batteries in a 3 battery clip, all 1.5v. The batteries are brand new and from the package.

Hope this is enough to find any other problems.