BeanieBots
Moderator
Code now added
New features added
Here are some rather naff pictures. I'll update those as well at some time.
Hopefully, you can see just how simple it really is.
Features:-
1.Plug-n-play using PICAXE AXE020 project board.
2.No soldering required (once you've made up the AXE020)
3.2X Sharp GP2D12 sensors for "eyes"
4.Only three servos to control six legs.
5.Can walk in a curve rather than just turn on the spot to avoid obsticles.
6.Uses pulsout rather than servo for "glitch free" servo control.
7.Plenty of room for improvement
8.Easy to build.
9.More impressive than wheels.
10.Easy to modify code to suite YOUR design & servos.
Here's the latest code which I'll update as/when new features get added.
New features added
Here are some rather naff pictures. I'll update those as well at some time.
Hopefully, you can see just how simple it really is.
Features:-
1.Plug-n-play using PICAXE AXE020 project board.
2.No soldering required (once you've made up the AXE020)
3.2X Sharp GP2D12 sensors for "eyes"
4.Only three servos to control six legs.
5.Can walk in a curve rather than just turn on the spot to avoid obsticles.
6.Uses pulsout rather than servo for "glitch free" servo control.
7.Plenty of room for improvement
8.Easy to build.
9.More impressive than wheels.
10.Easy to modify code to suite YOUR design & servos.
Here's the latest code which I'll update as/when new features get added.
Code:
'************************************************************
'* 22/09/2007 Added user speed & stride adjustments *
'* 21/09/2007 Added height adjustment. *
'* 20/09/2007 Added variable eye sensitivity *
'* 18/09/2007 First published on PICAXE forum *
'* 17/09/2007 Changed a few more hard numbers into symbols *
'* 16/09/2007 Tidied up symbols & added #directives *
'* 19/03/2007 Added comments *
'* 11/01/2007 Converted from servo to pulses *
'* 31/07/2005 Autonomous BUG Copyright BeanieBots *
'************************************************************
'User 'tombstone settings
'0 eye sensitivity LSB
'1 eye sensitivity MSB
'2 stride LSB
'3 stride MSB
'4 spare
'5 Height
'6 Speed
'7 Speed
'Hardware:-
'AXE020, L293D not fitted. ULN2003 replaced with 330R resistor DIL
'8-way SIL pin header fitted next to outputs for direct servo connection
'2X Sharp GP2D12 analog IR range detectors (10cm to 80cm range)
'3X cheap hobby servos (Futaba or Hitech type connectors)
'4X AAA 900mAHr NiMh batteries & holders, Off switch & hookup wire.
'Light plywood board 170mm X 90mm, 600mm length of coat-hanger wire.
'about 700mm of 1/4" dowel for legs and optional grommets for feet
'a few squirts of expoxy glue and a few nuts & bolts.
#PICAXE 28X 'or 28X1 and easily modified for 18X
#gosubs 255 'a few too many calls to update servos to use only 16
symbol Normal_Speed=3 'Overall walking pace. (typ 5 min 3 max 9)
symbol Frame=9 'Servo update rate (also affects speed min 5 max 25)
symbol step_size=12 'default stride.(min 5 max 25)
symbol MC=150 'Center leg neutral
symbol LC=150 'Left leg neutral
symbol RC=150 'Right leg neutral
symbol H=12 'Center leg height
symbol Lup=MC+H 'Left up demand
symbol Rup=MC-H 'Right up demand
symbol Adjust = infra 'reasign infra variable for tombstone values
symbol C_pos = b0 'Center leg actual position
symbol L_pos = b1 'Left leg actual position
symbol R_pos = b2 'Right leg actual position
symbol C_dem = b3 'Center leg required position
symbol L_dem = b4 'Left leg required position
symbol R_dem = b5 'Right leg required postion
symbol speed = b6 'Rate of change of leg position
symbol step_size_L = b7 'Left leg stride size
symbol step_size_R = b8 'Right leg stride size
symbol Command = b9 'What to do (state engine value)
symbol eye_R = b10 'Right eye value
symbol eye_L = b11 'Left eye value
symbol Steps = b12 'How many steps to take for each command (state)
symbol Step_Adjust = b13'Adjustment for user selected step size
symbol L_leg = 5 'output assignment for left leg servo
symbol R_leg = 6 'output assignment for right leg servo
symbol C_leg = 7 'output assignment for center leg servo
symbol EyeInL = 0 'Left eye analog input
symbol EyeInR = 1 'Right eye analog input
symbol Normal = 1 'Command for walk straight forwards.
symbol Back_Straight =2 'Command to backup in a straight line.
symbol Back_Left = 3 'Backup to the left
symbol Back_Right = 4 'Backup to the right
symbol Turn180 = 5 'Not implemeted yet.
main:
speed=Normal_Speed 'set up default variable values
step_size_L=-step_size
step_size_R=-step_size
command=Normal
L_dem=LC
R_dem=RC
C_Dem=MC
R_pos=R_dem
L_pos=L_dem
C_pos=C_dem
'*************************************************************
walk: 'start of main walking loop
Adjust=pin5*5 'height adjustment
C_Dem=MC+H+Adjust 'convert to center leg position demand
gosub C_UP 'raise the legs
gosub check_inputs 'find out what to do
L_dem=LC+step_size_L 'set left leg position demand
R_dem=RC+step_size_R 'set right leg position demand
gosub do_step 'do the step
Adjust=pin5*5 'height adjustment
C_Dem=MC-H-Adjust 'convert to center leg position demand
gosub C_Down 'put the legs back down
gosub check_inputs 'find out what to do
L_dem=LC-step_size_L 'set demand
R_dem=LC-step_size_R 'set demand
gosub do_step 'do the step
goto walk 'go back and repeat
'*************************************************************
Check_inputs: 'read inputs from eyes and jumpers
readadc EyeInL,eye_L 'how close are we to objects on the left?
readadc EyeInR,eye_R 'how close are we to objects on the right?
Adjust=pins & %00000011 'only use the firts two bits for eye adjustment
Adjust=11-adjust 'gives range 8 to 11. Link(s) fitted = more sensistive
eye_R=eye_R/adjust*3 'scale and granulate the Right value
eye_L=eye_L/adjust*3 'scale and granulate the left value
Adjust=pins & %11000000 'gets user speed adjustment
Adjust=Adjust/64 'scale accordingly
Step_Adjust=pins & %00001100 'get user stride adjustment
Step_Adjust=Step_Adjust*2
if Steps > 1 then Check_inputs_end 'don't change command until all steps done.
if eye_L > 14 or eye_R > 14 then
speed=Normal_Speed-1+adjust 'slow down a bit when object very close
else
speed=Normal_Speed+1+adjust 'speed up a bit if all clear
endif
'we only come here once the last command has completed ie steps=1
if command=Back_Left or command=Back_Right then
command=Normal
endif
if command=Back_Straight and eye_R > eye_L then
command=Back_Left
endif
if command=Back_Straight and eye_R < eye_L then
command=Back_Right
endif
if eye_R > 10 and eye_L > 10 then 'forward path blocked
Command=Back_Straight
endif
gosub pulse_servos 'send pulses out to servos
select case Command 'what to do for each set of conditions
case Normal 'normal forwards motion
step_size_L=step_size-eye_R+step_Adjust 'reduce left step size by RHS eye value
step_size_R=step_size-eye_L+step_Adjust 'reduce right step size by LHS eye value
steps=2 'take 2 steps before changing
speed=Normal_Speed+adjust 'do it at normal speed
case Back_Straight 'backwards straight
step_size_L=-step_adjust-step_size/2 'halve the step size when going backwards
step_size_R=-step_adjust-step_size/2
Steps=4 'take 4 steps in this condition
speed=Normal_Speed+adjust 'do it at normal speed
case Back_Left 'back left
step_size_L=-step_adjust-step_size/2 'halve the step size when going backwards
step_size_R=step_adjust+step_size/2
steps=9 'steps are smaller so do 9 in this condition
speed=Normal_Speed-1+adjust 'do it a bit slower
case Back_Right 'back right
step_size_L=step_adjust+step_size/2
step_size_R=-step_adjust-step_size/2
steps=9
speed=Normal_Speed-1+adjust 'do it a bit slower
endselect
check_inputs_end: 'jump to here if steps for current command not complete
Steps=Steps-1 min 1 'step complete, so reduce step counter
Return
Do_Step:
If L_pos > L_dem then L_dec 'decrement left leg position if it's too far forward
If L_pos < L_dem then L_inc 'increment left leg position if it's too far back
Do_Right: 'similar for right leg
If R_pos > R_dem then R_dec
If R_pos < R_dem then R_inc
'keep going until both actual leg positions = both demanded positions
If R_pos<>R_dem OR L_pos<>L_dem then Do_Step
Return
L_dec:
L_pos=L_pos-speed min L_dem 'move leg in correct direction by "speed" amount
gosub pulse_servos 'tell the servos to actually do it.
goto Do_right
L_inc: 'similar for the other legs
L_pos=L_pos+speed max L_dem
gosub pulse_servos
goto Do_Right
R_dec:
R_pos=R_pos-speed min R_dem
gosub pulse_servos
goto Do_step
R_inc:
R_pos=R_pos+speed max R_dem
gosub pulse_servos
goto Do_step
C_UP:'sub
if C_pos=C_Dem then C_UP_exit
C_pos=C_pos+speed+1 max C_Dem
gosub pulse_servos
goto C_UP
C_UP_exit:
gosub pulse_servos
pause 1
gosub pulse_servos
return
C_Down:'sub
if C_pos=C_Dem then C_Down_exit
C_pos=C_pos-speed-1 min C_Dem
gosub pulse_servos
goto C_Down
C_Down_exit:
gosub pulse_servos 'do this twice
pause 1
gosub pulse_servos 'to make sure legs are fully up
return
pulse_servos: 'routine that sends pulse width to servos.
pulsout C_Leg,C_pos
pulsout L_Leg,L_pos
pulsout R_Leg,R_pos
pause Frame
return
Last edited: