The Inner Workings of the Pusherbot
Methods

In writing my program for Pusherbot, I began by defining everything: the left, right, eye, bumper one and bumper two, as well as the threshold. Then, I went on to write the main task. Within the main task, I included the directions I wanted the robot to travel in, such as straight forward or turn and reverse. Then I wrote that if the light sensor came across a black line, (THRESHOLD 40) it would back up, turn, and go straight once again. I also told the robot to turn a little to the right and then straight if the right bumpers were touched. The Pusherbot would go to the left if the left bumpers were touched. This is so that Pusherbot can push all the objects out of the area. In addition, I programmed the robot to randomly move when it is not hitting a black line or pushing things. The random part is set in a task called move. Since I do not want my robot ever leaving the premises, I typed that sequence of reversing after sensing a black line into every random case.

Here is the source code for my robot:

//roboticsproject.nqc - remain in area while moving objects to the edge
#define EYE SENSOR_2 //define objects so may be used in program
#define LEFT OUT_A
#define RIGHT OUT_C
#define THRESHOLD 40 //distinguishing wavelength (black)
#define BUMP1 SENSOR_1
#define BUMP2 SENSOR_3

task main()
{
SetSensor(EYE, SENSOR_LIGHT);
SetSensor(BUMP1, SENSOR_TOUCH);
SetSensor(BUMP2, SENSOR_TOUCH);
OnFwd(LEFT+RIGHT); //turn on and go straight
Wait(100);
while(true)
{
if (EYE <= THRESHOLD) //wavelength is less than 40
{
stop move; //stopping the other task
Rev(LEFT+RIGHT); //instruction for robot when it senses a black line
Wait(75);
Rev(RIGHT);
OnFwd(LEFT);
Wait(50);
start move; //starting the other task again
}
else if(EYE > THRESHOLD) //wavelength is greater than 40
{
start move;
while(true)
{
if(BUMP1==1) //the touch sensor senses an object
{
stop move;
Off(LEFT); //instructions for robot when it touches an object
Wait(30);
OnFwd(LEFT+RIGHT);
until (EYE <= THRESHOLD); //continue instructions until it senses a black line
}
else if(BUMP2==1)
{
stop move;
Off(RIGHT);
Wait(30);
OnFwd(LEFT+RIGHT);
until(EYE <= THRESHOLD);
}
else if (EYE <= THRESHOLD)
{
stop move;
Rev(LEFT+RIGHT);
Wait(75);
Rev(RIGHT);
OnFwd(LEFT);
Wait(50);
start move;
}
}
}
}
}
task move()
{
int x;

x=Random(2); //robot moves around in random direction by choosing random number
switch(x)
{
case 0:
if (EYE > THRESHOLD)
{
OnFwd(LEFT+RIGHT);
Wait(100);
}
else if (EYE <= THRESHOLD) //robot continually checks for black line
{
Rev(LEFT+RIGHT);
Wait(75);
Rev(RIGHT);
OnFwd(LEFT);
Wait(50);
}
break;
case 1:
if (EYE > THRESHOLD)
{
Off(RIGHT);
Wait(75);
OnFwd(LEFT+RIGHT);
Wait(100);
}
else if (EYE <= THRESHOLD)
{
Rev(LEFT+RIGHT);
Wait(75);
Rev(RIGHT);
OnFwd(LEFT);
Wait(50);
}
break;
case 2:
if (EYE > THRESHOLD)
{
Off(LEFT);
Wait(75);
OnFwd(LEFT+RIGHT);
Wait(100);
}
else if (EYE <= THRESHOLD)
{
Rev(LEFT+RIGHT);
Wait(75);
Rev(RIGHT);
OnFwd(LEFT);
Wait(50);
}
break;
}
}

Home

Introduction | Methods | Materials | Conclusion | Acknowledgments | References