Edge avoider plus obstacle avoider robot

This is the SIXTEENTH PROGRAM in your course of FUNDAMENTALS OF ROBOTICS. To use this program, you must use our robotics kit already supplied to you.

Edge avoider plus obstacle avoider robot

Edge avoider plus obstacle avoider robot

If you do not have this kit, then you can purchase our distance learning programme in robotics or contact us to join our regular batches of robotics.

Now read the following program carefully and work as per the given instructions, to enjoy your FIRST COURSE in robotics.

To use this program directly for your robotic kit, copy it, create new project in AVR Studio and then paste it into the coding area. Then compile it. OR ELSE, DESIGN YOUR OWN, BY REFERRING TO THIS PROGRAM.

/*
	Level II project of 'Edge avoider + Obstacle avoider'
	Applicable to ATMega8/16/32/128
	Designed by: Vidyasagar Academy, Akola
	Website: www.vsagar.org

	*** CONNECTION DETAILS OF KIT ***
	1) The 2 motors in your kit, are connected to PB4-PB1, as follows:
	   Left motor:  PB4 -> (+) and PB3 -> (-)
	   Right motor: PB1 -> (+) and PB1 -> (-)
	2) Connect the 3 sensors to PC3, PC1 & PC0 in your kit.
	   See the note given at the end of this program.
*/

#define F_CPU 1200000UL // defining clock frequency for accurate delay
#include <avr/io.h> // includes input/output header file     
#include <util/delay.h> // includes delay header file  
int main(void)
	{
	DDRB=0b00011110; //PORTB as output Port connected to motors
	DDRC=0b0000000; //PORTC Input port connected to Sensors
	int S=0; 
		while(1) // infinite loop
		{
		S=0b00001011; // masking the status of both sensors
		
			if(S==9) // LS & RS are on white
				// and MS is not sensing any obstacle i.e MS=0
			{
			PORTB=18; // move forward
			}

			{ // obstacle avoiding logic
	
			if(S==11) // LS & RS are on white
					  // but MS is sensing obstacle 
					  // on table-top i.e. MS=1
			{
			PORTB=0; // stop
			_delay_ms(1000); 
			PORTB=12; // move backward
			_delay_ms(500); // adjust it as per requirement
			PORTB=16; // turn right
			_delay_ms(300); // adjust as required
			S=9;
			}

			} // end of obstacle avoiding logic

			{ // edge avoiding logic

			if(S==0) // both sensors outside the edge
			{
			PORTB=0; // stop
			_delay_ms(1000);
			PORTB=12; // move backward
			_delay_ms(500); // adjust it as per requirement
			PORTB=16; // turn right
			_delay_ms(300); // adjust as required
			S=9;
			}

			if(S==8) // LS on white, RS is outside the edge
			{
			PORTB=0; // stop
			_delay_ms(1000);
			PORTB=12; // move backward
			_delay_ms(500); // adjust it as per requirement
			PORTB=16; // turn right
			_delay_ms(300); // adjust as required
			S=9;
			}

			if(S==1) // RS on white, LS is outside the edge
			{
			PORTB=0; // stop
			_delay_ms(1000);
			PORTB=12; // move backward
			_delay_ms(500); // adjust it as per requirement
			PORTB=2; // turn left **** NOTE THIS STEP ****
			_delay_ms(300); // adjust as required
			S=9;
			}
			} // end of edge avoiding logic
			} // while closed
			} // main closed
About the author: Admin of Vidyasagar Academy to post all types of educational material required for our students. This material is equally helpful to our online students.

Comments on this entry are closed.