Professional Documents
Culture Documents
TAG ROBOTICS
www.tagonnet.com
need to send logic 0 and not logic 1.
TAG ROBOTICS
www.tagonnet.com
Note: The switches are connected in an active-low configuration. Therefore, whenever a switch is
pressed, we will receive logic 0 on that particular pin and not logic 1.
TAG ROBOTICS
www.tagonnet.com
Let’s look at the LCD functions that we have at our disposal:
• LCD_INIT()
Initializes the LCD in 2 line 4 bit mode with blinking cursor.
• LCD_WRITE(‘T’)
Used to write any character T to the LCD.
• LCD_STRING(“Xplore Robotics”)
Used to write a string on the LCD (max 16 characters in length)
• LCD_CMD(X)
To give commands to the LCD. X can be as follows
PUTLINE1 – Places cursor on line1
PUTLINE2 - Places cursor on line2
To place the cursor on a particular character box it is addressed as follows:
Command = LCD_CMD(0b1XXX XXXX);
where xxx xxxx is the address of character in binary.
Note: LCD row 1 address starts at 0x00 and row 2 starts at 0x40 but with the MSB set, the
addresses
are 0x80 and 0xC0 respectively.
Eg: To put cursor on 3 character line 1
LCD_CMD(0x83);
To put cursor on 5 character line 2
LCD_CMD(0xC5);
• LCD_CLEAR()
Clears LCD screen.
Here’s a sample program for using the LCD module with the help of the above functions:
// Program using the LCD module//
#include<REG52MOD.h> //Include the necessary header files
#include<delay.h>
#include<LCD.h>
void main (void)
{
LCD_INIT(); //Initialize the LCD module
LCD_STRING("TRI"); //Send a string to display
LCD_CMD(PUTLINE2); //Move the cursor to second line
LCD_STRING("HELLO WORLD !!"); //Send a string to display
while(1){} //Loop Infinitely
}
TAG ROBOTICS
www.tagonnet.com
#include<LCD.h>
unsigned char RXED,TXED;
void UART_INIT(void) //UART Initialization
{
SBUF=0x00; //Empty Serial Buffer
SM0=0; //Set UART
SM1=1; //in mode 1
SM2=0;
REN=1; //Receive Enable
TMOD=0x2F; //Set baud
TH1=253; //rate as 9600bps
TR1=1;
ES=1; //Enable serial interrupts
EA=1; //Global interrupt enable
}
void TX(unsigned char dat) //Transmit Data
{
SBUF=dat;
delay(10);
}
void RXTX_int(void) interrupt 4 //Serial interrupt ISR
{
if(RI==1)
{
RI=0; //Reset receive data bit
RXED=SBUF;
LCD_WRITE(RXED); //Display received character on LCD
}
if(TI==1)
{
TI=0; //Reset transmit data bit
}
}
void main(void) //Main program begins here
{
LCD_INIT(); //Initialize LCD
UART_INIT(); //Initialize UART
delay(1); //wait for a while
TX('S'); //Transmit S
TX('t'); //Transmit t
TX('a'); //Transmit a
TX('r'); //Transmit r
TX('t'); //Transmit t
while(1){}
}
After loading the program on to your iBOT controller, open the Hyper Terminal on your PC.
You can find it in Start > Programs > Accessories > Communications > Hyper Terminal
Step 1: Enter a name for the connection
Step 2: Select the COM port and configure its properties
TAG ROBOTICS
www.tagonnet.com
configurations designed to do this.
Here’s one of the simplest and fail safe line follower’s algorithm:
In this configuration we use two line sensors.
YES
YES
YES
NO
YES
NO
NO
NO
START
Initialize
Ports
Is left line
sensor
active?
Is right line
sensor
active?
Turn right
Turn Left
Is left line
sensor
active?
Go straight
Is right line
sensor
active?
Basically, the robot will always try to get the sensors on the line alternately, thus moving in a
‘zigzag’
path and eventually follow the line. The following code is written to follow a ‘black’ line on a
‘white’ surface but it can be easily modified to follow a ‘white’ line on a black surface.
// LINE FOLLOWING ROBOT //
//Right line sensor connected to PORT1.0
//Left line sensor connected to PORT1.1
//Right motor connected at M2
//Left motor connected at M1
#include<REG52MOD.h> //we include the necessary header file here
#define forward 0x05; // 0000 01 01
#define right 0x01; // 0000 00 01
#define left 0x04; // 0000 01 00
#define linesensor_right P1_0
#define linesensor_left P1_1
void main(void) //main program begins here
{
P1=0xff; //initialize PORT 1 as input (sensors)
P2=0x00; //initialize PORT 2 as output (motors)
while (1) //since there is no where to return,
TAG ROBOTICS
www.tagonnet.com
//we put it in an infinite loop
{
if (linesensor_right==0) //check if right sensor has detected
// a line (black surface)
{
while(linesensor_left==1) //if detected, then turn right till
{ //the left sensor comes on the line
P2=right;
}
}
if (linesensor_left==0) // check if left sensor has detected
// a line
{
while(linesensor_right==1) //if detected, then turn left till
11
{ //the right sensor comes on the line
P2=left;
}
}
else
{
P2=forward; //else go forward
}
}
}
TAG ROBOTICS
www.tagonnet.com
while (1) //since there is no where to return,
//we put it in an infinite loop
{
if (obst_right==0) //check if right sensor has detected an obstacle
{
P2=turnleft; //if detected, turn left for some time
delay(30);
}
if (obst_left==0) //check if left sensor has detected an obstacle
{
P2=turnright; //if detected, turn right for some time
delay(30);
}
else
{
P2=forward; //else go forward
}
}
}
By changing the delay variable we can make the robot turn for some specific degrees after it
detects
an obstacle. But the turns will not be precise since they will change as the battery drains.
Note: In this particular case, the turning would be ‘in place’ i.e., while turning, both the motors
will
run in opposite direction unlike the line follower, where the turns were turning by ‘stopping’
either of
the motor.
8. Sumo Robot
In the previous two examples we learned how to
use the line sensing modules as well as the IR
proximity modules. Now let’s see how we can
have a behavior that uses both of these sensors
together. A sumo robot fits this bill perfectly.
Inspired from the tradition ‘human’ sumo
competitions held in Japan, robotics enthusiasts
soon started having robotics sumo. Sumo
robotics competitions are now held around the
world under various weight and size ‘classes’
just like the real ones.
In a typical sumo robotics competition, two
robots compete against each other inside a sumo
ring. The ring is a made up of a black surface
with a white line around its circumference as
shown. The idea is to push the opponent out of
the ring in the stipulated time frame.
TAG ROBOTICS
www.tagonnet.com
on the left and
me not on the
edge?
Is the right
line sensor
active?
Is the opponent
on the right and
me on the edge?
Is the opponent
in front and me
not on the edge?
Is the right
line sensor
active?
Turn left
Turn right
Go forward
Turn backwards
then turn left
Turn backwards
then turn right
Go forward
NO
NO
NO
NO
YES
YES
YES
YES
16
// SUMO ROBOT //
//Right line sensor connected to PORT1.0
//Left line sensor connected to PORT1.1
//Right proximity sensor connected to PORT1.2
//Left proximity sensor connected to PORT1.3
//Right motor connected at M2
//Left motor connected at M1
#include<REG52MOD.h> //we include the necessary header file here
#include<delay.h>
#define forward 0x05 // 0000 01 01
#define reverse 0x0A // 0000 10 10
#define turnleft 0x06 // 0000 01 10 left motor = backwards,
// right motor = forward
#define turnright 0x09 // 0000 10 01 left motor = forward,
// right motor = backwards
#define linesensor_right P1_0
#define linesensor_left P1_1
#define obst_right P1_2
#define obst_left P1_3
void main(void) //main program begins here
{
P1=0xff; //initialize PORT 1 as input (sensors)
P2=0x00; //initialize PORT 2 as output (motors)
while (1) //since there is no where to return,
TAG ROBOTICS
www.tagonnet.com
//we put it in an infinite loop
{
while ( obst_right==0 //check if right sensor has
&& obst_left==1 //detected the opponent
&& linesensor_right==1 //and make sure that the robot is
&& linesensor_left==1) //not on the edge
{
P2=turnright; //if detected, turn right
} //(i.e., towards the opponent)
while ( obst_left==0 //check if left sensor has
&& obst_right==1 //detected the opponent
&& linesensor_right==1 //and make sure that the robot is
&& linesensor_left==1) //not on the edge
{
P2=turnleft; //if detected, turn left
} //(i.e., towards the opponent)
while ( obst_left==0 //check if both sensors
&& obst_right==0 //have detected the opponent
&& linesensor_right==1
&& linesensor_left==1)
{
P2=forward; //if detected, go forward
} //chase him and push him
17
if (linesensor_right==0 ) //check if right line sensor has
// detected the ring
{
P2=reverse; //if detected, go reverse for a while
delay(40);
P2=turnleft; //then turn left for a while
delay(30);
P2=forward; //and go forward
}
if (linesensor_left==0 ) //check if left line sensor has
//detected the ring
{
P2=reverse; //if detected, go reverse for a while
delay(40);
P2=turnright; //then turn right for a while
delay(30);
P2=forward; //and go forward
}
else
{
P2=forward; //else go forward
}
}
}
TAG ROBOTICS
www.tagonnet.com