Detecting variation in horizontal surface distance

I’m sure this must have been asked before, but I can’t find any solution for detecting variation in horizontal surface distance say for a BRAT. What I’m looking for is to be able to scan and detect a change in distance, say using an IR sensor, that is pointing down and ahead (and could be applied with multiple sensors on back and sides) of the BRAT, e.g. so that it can detect and avoid a slope or edge of the surface before it gets to it.

Thanks

hello

i have made a program for my boebot and ping sensor that will do that but because i only have 1 ping there is blind spots which makes it dangrous i therefore found that you will need 8 sensors to cover the perimeter and most of the blindspots but i have not tryed this because of the cost

regards,
codemaster

Do you have a way of reading the sensor outputs in realtime? Like an LCD that you can print the output on? My advice would be to mount the sensor at your desired angle, depending on how far away you want to detect something, then read the output of the sensor. Use that value as a base line and add a bit of hysteresis on both sides; because from my observations the BRAT body doesn’t stay completely level while walking and you don’t want your bot to react when there isn’t an object or drop off in the way. In your program if the voltage drops below your level of hysteresis then there’s and edge or a drop, if the voltage rises above the level of hysteresis then there’s a slope or an object.

If you need to know the actual distance then it might take a little more work. The output from a sharp sensor isn’t linear. You could use your sensor to take voltage measurements at small distance intervals. Then, pop those values into a graphing program and ask the program to produce an approximate best fit eqauation. The equation should closely model the distance/output relationship for that sensor.

I think there are several places up on the forum that show how to convert the IR values into things like cms… Here is some code from one of my Rover programs:
(I am not sure, but this code may have come originally from Xan)

; This table is used to convert Sharp IR readings into CM
IRCMTable bytetable     80,80,80,80,80,80,80,80,80,78, | 
                        76,74,72,70,68,66,64,62,60,59, | 
                        58,57,55,53,52,51,50,49,48,47, | 
                        45,43,42,41,40,39,38,37,35,33, | 
                        32,31,30,30,29,29,28,28,27,27, | 
                        26,26,26,25,25,25,24,24,24,23, | 
                        23,22,22,21,21,20,20,20,19,19, | 
                        18,18,18,17,17,16,16,16,15,15, | 
                        15,14,14,13,13,13,12,12,11,11, | 
                        11,10,10,10,10,10,10,10,10,10 

;--------------------------------------------------------------------
;[GetIRSensorInCM]
IRPin		var byte
scanrange 	var word                 ' A/D result variable 


GetIRScanInCM[IRPIN]
                        
	; first read in the IRvalue.
	adin IRPin,scanrange
	
	; If it is greater than 512 it is out of range we will return 0
	IF scanrange > 512 THEN		; outside our table so return 0 to signal too close 
		return 0
	ENDIF 
	
	; now convert entry to cm from table.  Old program
	; divided value by 5.12 using floating point, but could simply multiply by 100 and divide by 512
	; in integer math, which should be a lot quicker.  512*100 < 65536 so fits in word...
	return IRCMTable((scanrange*100)/512)

Kurt

This is a good start…many thanks for the info!

Like what everyone mentioned above,

All you need to do is figure out how to convert the ir sensor readings into something meaningful(like cm or in) or take measurements at different distances and make a table of the values. Then just react to different readings in your code. For example if the reading is very high(looking over an edge), the robot perhaps should stop walking or even turn around.