GP2D12 sensor on hex?

Im going to be using a Sharp GP2D12 sensor on my hexapod project and ill be using Xans code i found on your site for the main program for this idea.

ill be using the sensor in the same way matt denten made his hexapod react but with IR not Sonar.

The sensor should sense an object in front of it at say 40 cm, coursing the body to move back (not moving the feet - just the body).
Then once the object gets closer at about 20cm and the body move has reached its limits i want the robot to step back so the robot stays 20cm from the object. (these numbers are only an example)

for the body movement would i need something like this?

[code]
BodyPosZ var sword

GP2D12 var bit

if (GP2D12 = 1) then
BodyPosZ = BodyPosZ + 1 max 20
elseif(GP2D12 = 0)
BodyPosZ = BodyPosZ - 1 min -20
endif[/code]

what about getting it to walk back when it gets to close?
i wish to use a button on my ps2 to put it into IR mode (autonomous)

i have BotBoard2 SSC-32 and BA-pro.

thanks you in advance. :slight_smile:

Maybe like this:…?

[code]GP2D12_Threshold con 250
GP2D12_SoundThreshold con 112

GP2D12Enable var Bit
BodyPosZ var Bit
GP2D12 var Word

IF (DualShock(2).bit6 = 0) and LastButton(1).bit6 THEN ;Cross Button test
GP2D12Enable = GP2D12Enable ^ 1
if GP2D12Enable then
Sound 9,[100\880,100\1480]
else
BodyPosZ = 0
sound 9,[100\1480,100\880]
endif
endif

in main…

if GP2D12Enable then
	adin AX0,2,AD_RON,GP2D12
	BodyPosZ = 0
	
	if GP2D12 > GP2D12_Threshold then
		BodyPosZ = BodyPosZ+1
		Sound 9,[20\200]
		
	elseif GP2D12 > GP2D12_SoundThreshold
		Sound 9,[10\(GP2D12 * 10)]
	
	endif
endif[/code]

I’m not a programming guru but the Phoenix code runs on an atom pro, your adin command appears to be using the atom format.

this came from info i pulled from your site somewhere. i just placed it together in a way i could understand. it may not be correct as you say.

what would be the right way to do this?

Get or download the atom pro manual and look up the command. You are going to need it if you are serious about programming. If you have trouble converting the format there are many who can help.