Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
if (sharp_IR_reading > scan_thresh)//object detected { if (scan_angle>41) //overflow protection scan_angle-=2;//scan right } else //object not detected { if (scan_angle<=max_scan_angle) //maximum servo angle scan_angle+=2; //scan left
if (sharp_IR_reading > scan_thresh)//object detected { if (scan_angle>41) //overflow protection scan_angle-=1;//scan right } else //object not detected { if (scan_angle<=max_scan_angle) //maximum servo angle scan_angle+=1; //scan left
What are the voltages (or ADC values) you are getting from the Sharp? Does the voltage to distance match the graph in the data sheet?The Sharp draws a large current when its switches on its LED. Try adding a cap right on the Sharp PCB at the connector pins. Try at least a 10uF preferably one with low ESR.
Realistically, I think you're thresholding at a distance that's too low.
distance_cm = 7955 * (adcVal) ^ (-1.20) // ^ in this case is the exponent function, e.g., 4^3 = 4*4*4 = 64 adcVal = 1681 * (distance_cm) ^ (-0.82)
scan_thresh = 120; // or whatever threshold value you pick.
I would suggest commenting out thisautocalibrate();in the main routine. do this to comment it out.//autocalibrate();now underneath writescan_thresh=30;this should set your scan threshhold to scan for objects between about 4cm to 22cm.If you still have problems then I would suggest that it isnt to do with the program. (dont waste time graphing your sensor output, you already verified that it is working. This is a very simple program and does not require spending time graphing sensor data).