Adding IR sensor GP2D12 to Xan's code

great find. might have to do some covert borrowing at work and grab myself some units. lol.

just been trying to look to see if i can find any documentation on converting .bs2 to .bas.
no luck
but good luck with the hack.

i have this code for my sensor and it’s working fine. I just want the hexapod to walk back when it comes too close.

so what it does now:

When something comes in reach it will move it’s body back as if it’s scared. when i come closer is starts following my object.

what i still need is make the bot wait for about 5 seconds when the scanrange is bigger then 400 and then walk back with rotation so he can avoid the object.

Also i want it to move his head from left to right and back when something goes OUT OF range, and when the sensor detects the object again the headmoving should stop again.
I have a one servo head (left/right) with the sensor on pin19 (BBA-pro) and the servo on pin28 (ssc-32)

I really can’t find how to do it… any help is welcome!

here is the code i have untill now:

[code]; [SENSOR DATA CALCULATION]
SensorInput:
adin P19,scanrange ’ Read sensor value
if scanrange > 0 and scanrange < 150 then
BodyPosZ = BodyPosZ-3 ’ Move back

if BodyPosZ < -35 then   ; about the limit joystick code had... 
   BodyPosZ = -35    
endif
elseif BodyPosZ < 0  ; scanrange is <=300 so start going back 
       BodyPosZ = BodyPosZ+3 'Move Front

’ BodyRotX = 0
ENDIF

IF scanrange > 150 and scanrange < 300 then
 bodyposZ = 0
 Balancemode = 0
 TravelLengthZ = -80

’ BodyRotX = -10 ;(bodyheight/2)
endif
; if HeadHangle < 0 and ScanRange > 200 then
; travelrotationY = (HeadHAngle2)
; travellengthZ = -80
; headHangle = ((headhangle
2)-headhangle)
; endif
;
; if HeadHangle > 0 and ScanRange > 200 then
; travelrotationY = -(HeadHAngle2)
; travellengthZ = -80
; headHangle = ((headhangle
2)-headhangle)
; endif

IF scanrange > 300 then
pause 1152
	travelrotationY = 20
	travellengthZ = 60
 	stepsingait = 12

endif[/code]

Can somebody tell me how i can tell the bot to walk forward for a certain amout of distance? Of course i mean in Xan’s code.

When i push the X button i want the hexapod to walk forwards, then when it detects something (IR) i want it to walk to the object, take the attack posture, turn for +/- 90 degrees and repeat the whole thing.

All the code is covered allready, i just can’t seem to get it to walk forwards or turn a certain amount of distance…

I really need help with this!

Here is what you need to do. Convert the PS2 functions to serial input functions. Then add another microcontroller to the bot. This second micro will be the behavior “brains” of the bot. It will run much simpler code to read the sensors and send the proper serial commands to the main micro. By separating the low end leg movement and high end intelligence processes it will be much easier to get the reactions you desire. Trying to fit it all inside the main controller, although may be possible, would certainly be difficult even for the expert programmers. :wink:

Ah ok, so there is no automated function for that…

So i can’t tell it to run the gait twice? By standard the gait runs once and then stops…

Or maybe it is possible to make the bot think that i’m pushing the throttle? (in the code ofcourse)

You of all people should be able to tell me what is available. :wink: You have been around the block a few times here. I’m telling you how you can make your robot do what you want it to do. I’m sure it is possible to write the code so it does what you want. However it would likely cost a hundred or so programming hours for an experienced programmer to accomplish it. My proposal will allow an inexperienced programmer to do it and actually have some success in the process. :wink:

The current version of the Phoenix code (1.3) uses a single function to read it’s input commands. The function, called PS2input, starts by reading the PS2 input lines and writing the values from the joysticks and buttons to the correct values for the bot.

You could do the same but instead of reading the PS2 inputs you could read inputs from sensors that are located on the bot. So instead of moving the body with the joystick you could also let it move on an analog input from a IR sensor.

Writing the PS2 value to the body position:

 BodyPosZ = -(Dualshock(6) - 128)/2

Writing the value from the analog input to body position

range var word
ADIN 1, range ; reads the voltage on pin analog pin 1, the range will be 0 to 1023
BodyPosZ = range/4 ; you probably need to adjust the range by dividing it with a higher number and maybe invert the range to let it move backwards when it detects something.

Note: This is just a code snippet to give a global idea about where to start. The code is not tested so be careful. The range value could be to high. Please write the range value to the debug interface first.

I hope this sets you on the right track.

Xan

PS: the new version (2.0) will have a separate file that handles the input. It can be easy swapped to use other remotes or even AI logic.