Hi all,
I’m having trouble with my code. I have some Ping Sonar code integrated with my autonomous code. The hexapod can successfully walk forward and recognize an obstruction(wall) and then rotate/turn…and continues to keep rotating. I’m sure it’s simple, but I don’t know how to go about getting the hexapod to exit the “loop” and continue to walk forward. Here’s the section of the code…
[code] Steering = (Steering Max 120) min -120
Steering2 = Steering
Height = (Height Max 25) min -25
Height2 = Height
YSpeed = (YSpeed Max 120) min -120
XSpeed = -50
GaitSpeed = (GaitSpeed max 20) min 3
StepFlag = (GaitSpeedTmp - 2) max 3
LegUpShift = 70
if LegUpShift > 45 then
GaitKind = 1
GaitSpeed = GaitSpeed min 4
else
GaitKind = 0
endif
XSpeed = -50
low ping
high ping
pulsin ping, 0, pingRaw 'read the ping
low ping
;pingRaw = pingRaw / 2 'adj for per sec since reading are every 0.5 sec
;pingRange = pingRaw / 29 'convert to cm
pingRange = pingRaw / 148 'convert to inches
pingRangemin = pingRange
if pingRangemin <= 10 then ;it sees an obstruction
XSpeed = 0
YSpeed = 0
Steering = -60
else
XSpeed = -50
if pingRangemin > 10 then ;if it doesn't see an obstruction
XSpeed = -50
endif
endif[/code]
…also, I feel like I keep re-stating the ‘XSpeed’ too much. Any help?
Thanks,
Justen