Sharp distance sensor

hello admin,
i have a problem with this program, i wanted to program let the sensor detect obstacle then make a left turn.
this is my program:

int main()
{
unsigned int sensor_values[5];
pololu_3pi_init(2000);
int front_proximity = analog_read(7);

	while(1);
	{		
		if(analog_read(7) => 2000)
		set_motors(0,50);  
		else if(analog_read(7) =<2000)
		set_motors(50,50);
		delay_ms(100)		
			
	}
}

Hello.

One immediate problem I see is that analogRead() never returns a value over 1023, so your first check can never be true. Also, if you want to use analog input 7, make sure you have removed the ADC7 jumper that ties it to the trimpot. Finally, the first three lines of your program don’t do anything useful. A good way to figure out what is going on would be to have your program print the sensor readings to the LCD.

Before you make future posts, please read our post on advice for getting help. Your opening post is not adequate. For example, if you post a program, please simplify it as much as possible and say what happens when the program runs (and please use [ code ][ /code ] tags to make it more readable). You also should provide more information about your setup (e.g. what sensor are you using and how is it connected?).

- Ben

Hello,
i am using a sharp distance sensor which mount in front of the robot. i connected the pin to ADC7 and removed the ADC7 jumper wire. thanks for the advice of testing the sensor reading to the LCD

Do you all have a simpler program for the robot to check for obstacles ahead, if have the robot wll turn left continues its path.

I don’t have something that does exactly what you want, but you might want to take a look at our wall-following application note. By the way, I gathered from your thread subject that you are using a Sharp distance sensor; there are several different Sharp distance sensors, which is why I asked what sensor you are using.

- Ben

Hello,
ok thanks for the guide of looking into the wall follower, sorry so how i dont understand some codes
if (get_ms() % 15000 > 14000) {
back_up();
continue;
}
// If something is directly in front turn to the right in place
int front_proximity = analog_read(5);
if (front_proximity > 200) {
turn_in_place();
continue;
}

i not v sure about this code , (get_ms() % 15000 > 14000). i know it is in case it gets stuck: for 1 second every 15 seconds back up. why is need > 14000?
the continue; is it to continue the next command?

Hi,

The get_ms() % 15000 returns the remainder of get_ms()/15000. I only want to back up when the remainder is greater than 14000 to get it to back up for one second at the end of the 15 seconds. The continue statement goes back to the top of the loop. The code keeps putting the robot into the backing-up state again and again for the whole second it is supposed to be backing up. I could have simply used a delay inside the back_up() method, but I favored having the main loop be in control at all times.

This style actually has an effect on the behavior in the case of the turn_in_place code. If 14 seconds have elapsed and the robot is trying to turn in place, it will stop trying to turn in place immediately back up instead.

- Ryan