4 servo walking Hexapod using 18M2 Chip

View attachment 12065View attachment 12066

I have just finished creating this hexapod robot, I have the 18M2 programmed to take 5 steps forward, then the IR Sensor to turn via a servo motor left, right, and calculate which way is not obstructed then to go off into the corresponding right turn or left turn, it can also walk backwards if an obstacle is in front of the IR sensor. I am working on an interupt at the moment but am struggling, if anyone can help I will trade my CAD plans of the robot for knowledge ;-)
 

Jamster

Senior Member
That looks really cool :) nice project.

Where abouts on the interrupts are you struggling? What do you want it to do? I assume it's to stop it running into things but is this via a switch or the IR sensor?

We need more info :)
Jamster

P.S. I assume you've read up on the setint command in manual 2.
 
Thanks buddy! ;-)

Im stuck completely! Below is the code ive written so far, ive only started using the PICAXE a few weeks ago so im only familiar with basic commands.

symbol counter = b1


init:'put all servos to default position'
servo 7,150
servo 6,150
servo 5,150
servo 4,150
pause 1000
goto view


view:'look straight ahead to check if path is clear'
readadc C.1,b1
if b1 > 70 then danger
goto main




whichway:'turn and look for a clear way'
servopos 7,100
pause 1000
readadc C.1,b1
servopos 7, 200
pause 1000
readadc C.1, b2
servopos 7, 150

if b1<b2 then gosub left
if b2<b1 then gosub right
if b1=b2 then gosub danger

goto main



main:'walk forwards'
for counter = 1 to 3
servopos 4, 100
pause 200
servopos 6,100
pause 200
servopos 5,100
pause 200
servopos 4,200
pause 200
servopos 6,200
pause 200
servopos 5,200
pause 200
next counter

servo 7,150
servo 6,150
servo 5,150
servo 4,150
pause 1000


goto whichway


left: 'turn left'
servopos 6,100
pause 1000
servopos 6,200
pause 1000
servopos 6,100
pause 1000
servopos 6,200
pause 1000
goto view

right: 'turn right'
servopos 5,100
pause 1000
servopos 5,200
pause 1000
servopos 5,100
pause 1000
servopos 5,200
pause 1000
goto view

danger:'walk backwards'
servopos 4, 200
pause 200
servopos 6,100
pause 200
servopos 5,100
pause 200
servopos 4,100
pause 200
servopos 6,200
pause 200
servopos 5,200
pause 200
goto view
 
At the moment it walks a few steps which is the main program. After which it goes to 'whichway', rotates the IR sensor left, then right, then goes off into a subroutine called 'left turn' or 'right turn' depending on which direction had no obstacles. However i want to do away with the walking a few steps then stopping to choose a way to go, but react instantaneously via a interrupt command as soon as an obstacle is there, as at the moment if an obstacle presents itself during the main program of walking a few steps it just keeps on going until the end when it goes to the 'whichway'.
 

Jamster

Senior Member
I think what might be best for your project is actually multitasking rather than an interrupt, that way you can have one task looking around constantly to find obstructions and another moving the robot. You can find more details in Manual 1 under "Parallel task processing". :)

If you want I can write some basic code for you that will set you on the right tracks. :)

Jamster
 
Top