Adding IR sensor GP2D12 to Xan's code

I’m not really satisfied with my code yet.

When i walk to an object i want it to walk backwards. This works. But as soon as the object is in range, it starts walking back to the point where the bot measured it’s first range. I want it to walk back further.

So for example:

**when Range is >300 walk back to range 100

instead of walking back to 300 wich is about nothing (or a cm or so)
**
Does anyone know how to do this?

Does this look right?

SensorInput: adin P19,scanrange ' Read sensor value IF scanrange > 300 then scanrange = scanrange+200 GaitType = 1 NomGaitSpeed = 30 TravelLengthZ = 50 ' BodyRotX = -10 TravelrotationY = 40

Hi Mano,

I guess the real question is does it work right?

Kurt

Oops! You got me there. I am still ill and wasn’t able to program it. Usually I’m not getting it right so wanted to check with you guys first.

Let me put my question this way. The way I wrote the code, is this acceptable for the program? It does compile…

Or maybe I need to have some patience and have to wait unroll I feel a bit better.

Thanks anyway!

Well, it seems to be working, but when the pod is walking back it is sooo slow. How can i speed that up? i tried putting “NomGaitSpeed = 90” in the list but that doesn’t seem to make a diffenrence. I also tried 150.

I tried putting “sscTime = 400”… no difference either.

Any idea?

hi mano1979

just been playing about with the code and i had to make a change to even see if it was working as numbers were too small to get any movement:

[code] ; [SENSOR DATA CALCULATION]
SensorInput:
adin P19,scanrange ’ Read sensor value
IF scanrange > 150 then
GaitType = 0
TravelrotationY = 15
TravelLengthZ = 50

ENDIF
if scanrange > 200 then  
    BodyPosZ = BodyPosZ-42  ' Move back
            if BodyPosZ < -42 then   ; about the limit joystick code had...
        BodyPosZ = -42   
    endif
elseif 
        BodyPosZ < 0  ; scanrange is <=300 so start going back
        BodyPosZ = BodyPosZ+40 'Move Front
    ENDIF[/code]

ok so from this i was able to get the robot to move back (body ik) when sensor pick up object (my hand)… great,

but im thinking that if the sensor was to give realtime feedback so that the closer you get the more it moves back rather than just moving and holding position intill sensor detects nothing and returns to center again.

does this make sense?

i know why the code is only doing the above but im not sure how to fix it. i have tried adding a scantable but till no luck.

at this stage im only interested in getting the body to move in relation to sensor readings, and once its giving nice smooth feedback i may add a few steps once object gets too close…

Earlyer in this post i used a different code. That Will do exactly what you said. THE last posted code is not compatible with the bytetable.

gotchya! :wink:

thanks. missed it by miles.

Can you keep me posted on any updates you make on the script?

as far as updates go i only have what we already know. it works but my intention was to get the hex to walk back once the body move has reached its limit. ill work on this once i get time.

[code]
scantable bytetable 80,80,80,80,80,80,80,80,80,78, |
76,74,72,70,68,66,64,62,60,59, |
58,57,55,53,52,51,50,49,48,47, |
45,43,42,41,40,39,38,37,35,33, |
32,31,30,30,29,29,28,28,27,27, |
26,26,26,25,25,25,24,24,24,23, |
23,22,22,21,21,20,20,20,19,19, |
18,18,18,17,17,16,16,16,15,15, |
15,14,14,13,13,13,12,12,11,11, |
11,10,10,10,10,10,10,10,10,10

;-------------------------------------------------------
scanrange var sword ’ A/D result variable

;-------------------------------------------------------

  IF (DualShock(2).bit1 = 0) THEN ;R2 Button test
	  ;   [SENSOR DATA CALCULATION]

SensorInput:
adin P19,scanrange ’ Read sensor value
if scanrange > 200 then ’ Test for obstacle to close to detector default and max =512
BodyPosZ = BodyPosZ-10 ’ Move body back
Sound P9,[20\400]
else
if scanrange < 200 then ’ Read sensor value
BodyPosZ = 0 ’ Move body to center (WAS BodyPosZ = BodyPosZ+10)

    floating = tofloat( scanrange) / 5.12            ' Limit value to <200 values
    val = scantable(toint floating)                  ' Convert A/D to measurement
    debug [REAL floating," ",DEC val,13]             ' Output result to debug window
    serout S_OUT,i38400,[REAL floating\2," - ",DEC val," cm",13]

else

 IF BodyPosZ > 5 then                                ' Detect body move distance limit
 TotalTransZ = 10                                    ' Walk back
 TravelLengthZ = 10
 ENDIF
 ENDIF
ENDIF[/code]

I found that it really gets unstable while doing both. I whas looking for àway to to do THE body movement first and then let os walk back. Or THE other way around. The Same with THE rotation for walking around objects.

I found a motion sensor in my old junk. Does anyone know how to attach it? I can’t Find a diagram.

What kind of motion sensor? PIR?

You may need to look up a model number.

What are my options in sensors for tracking an object of any kind? Would that work with an gd12p2 ir sensor? Or do i use THE motion sensor? THE sensor only says 418s and has àmetal round casing with three wires.

i feel i can answer this one, being the in security industry. PIRs Passive infrared sensor’s, have may different jobs. some are IR some are Sonar.

Without the board, the sensor itself works just the same.

it really depends on what type of sensor AND model you can as to how you attach it. you will find some info on the net using the data printed on the sensor. if not you will have to find the whole thing as one unit and try and work out what model sensor you have.

they will wire up much the same as a normal standard senser.
:wink:

If there’s three wires then they must be standard pinout. Are the wires color coded? if so, connect red to 5v and black to the ground, and the remaining colored wire connects to the I/O on bot board. The sensor should be digital output (most are) so just run a program that reads the sensor like it’s a switch. The program should output a 0 or 1.

Do you happen to have THE code i need? I am not able to write it myself since i am dislectic. I can adjust code but can’t read THE manual.

Thanx in advance!

Sorry, I have not programmed in BASIC for so long now that I forget. it should be pretty simple. hopefully someone else can help. :slight_smile:

Brandon C.

I found a file on parallax.com for there 3 pin interface PIR sensor. it looks pretty simple to modify for the Basic Atom:

' =========================================================================
'
'   File...... PIR_Simple.bs2
'   Purpose... Show Output State Of PIR Sensor
'   Author.... Parallax, Inc.
'   E-mail.... [email protected]
'   Started... 12-14-2005
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================

' ----- Program Description ]---------------------------------------------

' This program displays the current state of the PIR Sensor connected to P0
' on the DEBUG screen.


' ----- Program Code ]----------------------------------------------------

Main:
  DO
    DEBUG HOME, BIN1 IN0                ' Display Status Of P0 At Home Pos.
    PAUSE 100                           ' Small Delay
  LOOP                                  ' Repeat Forever

Thanx!