Hexapod code using Ping Sonar

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

Well I figured out the problem with the code, now my new problem is that I’m trying to use 2 PING sensors and I’m not sure how to go about writing the code. I tried what I thought might work, but it only wanted to read one sensor at a time and wouldn’t walk right. I read another post on here about someone trying to use multiple sensors but I couldn’t gain much from it.

Any help?Please?

Justen

I’m not a great programmer, but I will try to help. What hexapod are you using? Is it a 2DOF? Are you using the SSC-32’s hexapod sequencer? This type of problem will require us to see the wiring, do you have a schematic? Posting what you tried would be a good idea. More info…

Sorry, I didn’t realize you responded. However, I did get the robot working how I wanted it too. I ended up using 3 sonar sensors so it can see to the front, right, and left and respond accordingly. The problem was with how I had my IF statements nested, and also I wasn’t turning “off” the XSpeed when I was turning the Steering “on”.

Well glad you got it going.