View unanswered posts | View active topics It is currently Wed Aug 20, 2014 11:23 pm






Reply to topic  [ 6 posts ] 
project for solving maze 
Author Message
Rookie

Joined: Tue Jun 05, 2012 2:31 pm
Posts: 11
Post project for solving maze
this my project for solving the maze
in first test the robot will learn the maze
the second time will take less time because it save the true way
any advice from u
because i have the problem but i don't know where
the sonar sensor i but it on the robot in the left side
i use left hand algorithm

Code:
#pragma config(Sensor, S1,     color,          sensorCOLORFULL)
#pragma config(Sensor, S2,     touch,          sensorTouch)
#pragma config(Sensor, S3,     compass,        sensorI2CHiTechnicCompass)
#pragma config(Sensor, S4,     sonar,          sensorSONAR)
#pragma config(Motor,  motorA,          ma,            tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorB,          mb,            tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorC,          mc,            tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

// Calibration values, these may be different for you
void readfile[100][2];
void reaad();
void write();
int readindex;
int index = 0;
int local_index = 0;
int local_index2 = 0;
int ar[100][2];
int ar_filter[100][2];
int road[100][2];

int timevalue_first;
int timevalue_last;
int timevalue;

int north_degree = 313;
int south_degree =253;
int east_degree = 306;
int west_degree = 275;

int vector_value;
int char_vector_value;

const string FILENAME = "fff.dat";


void VectorChar()
{
    if ((vector_value >= west_degree - 2) && (vector_value <= west_degree + 2))
    {
        char_vector_value = 1;
    }
    else if ((vector_value >= east_degree - 2) && (vector_value <= east_degree +2))
    {
      char_vector_value = 2;
    }
    else if ((vector_value >= south_degree - 2) && (vector_value <= south_degree + 2))
    {
      char_vector_value = 3;
    }
    else if  ((vector_value >= north_degree - 2) && (vector_value <= north_degree + 2))
    {
      char_vector_value = 4;
    }

    // w = 1
    // e = 2
    // s = 3
    // n = 4
}

bool comparevalue(int val01,int val02,int val11,int val12)
{
  if ((val01 == 3) && (val11 == 4))
  {
   return false;
  }
  else if ((val11 == 3) && (val01 == 4))
  {
   return false;
  }
  if ((val01 == 1) && (val11 == 2))
  {
   return false;
  }
  else if ((val11 == 1) && (val01 == 2))
  {
   return false;
  }
  else
  {
   return true;
  }

}
void filteration()
{
  int var1 = 0;
  int var2 = 0;

  for (int i=0;i<index;i++)
  {
      var1 = ar[i][0];
      var2 = ar[i][1];
      bool result = comparevalue(var1,var2,ar[i+1][0],ar[i+1][1]);
      if (result)
      {
         ar_filter[local_index][0] = ar[i][0];
         ar_filter[local_index][1] = ar[i][1];
         local_index++;
      }
      else
      {
         i = i+2;
      }

  }
  for (int j=0;j<local_index;j++)
  {
      bool result2 = comparevalue(ar_filter[j][0],ar_filter[j][1],ar_filter[j+1][0],ar_filter[j+1][1]);
      if (result2)
      {
         road[local_index2][0] = ar_filter[j][0];
         road[local_index2][1] = ar_filter[j][1];
         local_index2++;
      }
      else
      {
         j = j+2;
      }
  }
  write();
}
void write()
{
  TFileIOResult dIOResult ;
  Delete(FILENAME, dIOResult);

   TFileIOResult nIOResult ;
   TFileHandle LIGHTFILE ;
   int FileSize = index ;
   int i;

   OpenWrite ( LIGHTFILE , nIOResult , FILENAME , FileSize );

   for (i=0;i < local_index2 ;i ++)
   {
     WriteShort( LIGHTFILE , nIOResult ,road[i][0]);
    WriteShort( LIGHTFILE , nIOResult ,road[i][1]);
   }

   Close ( LIGHTFILE , nIOResult );
}
void reaad()
{
 TFileIOResult nIOResult ;
TFileHandle LIGHTFILE ;
   int FileSize = index ;
   int i;
   int n;
OpenRead ( LIGHTFILE , nIOResult , FILENAME , FileSize );
for (i=1;i <=readindex  ;i ++) {

ReadShort ( LIGHTFILE , nIOResult ,n);


}
Close ( LIGHTFILE , nIOResult );
}
task main(){
reaad();
  while (true)
  {
     while(SensorValue(touch) == 0)   //a while loop is declared with the touchsensor's value being 0 as it true condition
     {
        timevalue_first = nSysTime;
        if((SensorValue(sonar)>=3)&&(SensorValue(sonar)<=4))
        {
              motor[mc]=+60;
              motor[mb]=+60;
            }
        else if((SensorValue(sonar)>=1)&&(SensorValue(sonar)<=2))
        {
              motor[mc]=+60;
              motor[mb]=+50;
        }
            else if((SensorValue(sonar)>=5)&&(SensorValue(sonar)<6))
            {
              motor[mc]=+50;
              motor[mb]=+60;
            }
            else if(SensorValue(sonar)>15)
            {
                timevalue_last = nSysTime;

                motor[mc]=0;
                motor[mb]=+60;
                wait1Msec(1000);
                motor[mc]=+60;
                motor[mb]=+60;
                wait1Msec(500);

                timevalue = timevalue_last - timevalue_first;
                vector_value = SensorValue(compass);
                VectorChar();
                ar[index][0] = char_vector_value;
                ar[index][1] = timevalue;
                index++;
                nxtDisplayTextLine(1, "Raw: %3d, %3d",char_vector_value,timevalue);

            }

      }

      timevalue_last = nSysTime;
      timevalue = timevalue_last - timevalue_first;
         vector_value = SensorValue(compass);
         VectorChar();
         ar[index][0] = char_vector_value;
         ar[index][1] = timevalue;
         index++;
         nxtDisplayTextLine(5, "Raw: %3d, %3d",char_vector_value,timevalue);

        motor[mb] = -60;                   //motor A is run at a -75 power level
        motor[mc] = -60;
        wait1Msec(300);
        motor[mb] = +60;                   //motor A is run at a -75 power level
        motor[mc] = -60;         //motor B is run at a -75 power level
        wait1Msec(1000);                       //the program waits 1000 milliseconds before running further code
if(sensorvalue(color)==1)
  break;
filteration();

  }
}


Mon Jul 09, 2012 5:45 am
Profile
Rookie

Joined: Tue Jun 05, 2012 2:31 pm
Posts: 11
Post Re: project for solving maze
project for solving maze
this my project for solving the maze
in first test the robot will learn the maze
the second time will take less time because it save the true way
any advice from u
because i have the problem but i don't know where
the sonar sensor i but it on the robot in the left side
i use left hand algorithm

Code:
#pragma config(Sensor, S1, color, sensorCOLORFULL)
#pragma config(Sensor, S2, touch, sensorTouch)
#pragma config(Sensor, S3, compass, sensorI2CHiTechnicCompass)
#pragma config(Sensor, S4, sonar, sensorSONAR)
#pragma config(Motor, motorA, ma, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorB, mb, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorC, mc, tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

// Calibration values, these may be different for you
void readfile[100][2];
void reaad();
void write();
int readindex;
int index = 0;
int local_index = 0;
int local_index2 = 0;
int ar[100][2];
int ar_filter[100][2];
int road[100][2];

int timevalue_first;
int timevalue_last;
int timevalue;

int north_degree = 313;
int south_degree =253;
int east_degree = 306;
int west_degree = 275;

int vector_value;
int char_vector_value;

const string FILENAME = "fff.dat";


void VectorChar()
{
if ((vector_value >= west_degree - 2) && (vector_value <= west_degree + 2))
{
char_vector_value = 1;
}
else if ((vector_value >= east_degree - 2) && (vector_value <= east_degree +2))
{
char_vector_value = 2;
}
else if ((vector_value >= south_degree - 2) && (vector_value <= south_degree + 2))
{
char_vector_value = 3;
}
else if ((vector_value >= north_degree - 2) && (vector_value <= north_degree + 2))
{
char_vector_value = 4;
}

// w = 1
// e = 2
// s = 3
// n = 4
}

bool comparevalue(int val01,int val02,int val11,int val12)
{
if ((val01 == 3) && (val11 == 4))
{
return false;
}
else if ((val11 == 3) && (val01 == 4))
{
return false;
}
if ((val01 == 1) && (val11 == 2))
{
return false;
}
else if ((val11 == 1) && (val01 == 2))
{
return false;
}
else
{
return true;
}

}
void filteration()
{
int var1 = 0;
int var2 = 0;

for (int i=0;i<index;i++)
{
var1 = ar[i][0];
var2 = ar[i][1];
bool result = comparevalue(var1,var2,ar[i+1][0],ar[i+1][1]);
if (result)
{
ar_filter[local_index][0] = ar[i][0];
ar_filter[local_index][1] = ar[i][1];
local_index++;
}
else
{
i = i+2;
}

}
for (int j=0;j<local_index;j++)
{
bool result2 = comparevalue(ar_filter[j][0],ar_filter[j][1],ar_filter[j+1][0],ar_filter[j+1][1]);
if (result2)
{
road[local_index2][0] = ar_filter[j][0];
road[local_index2][1] = ar_filter[j][1];
local_index2++;
}
else
{
j = j+2;
}
}
write();
}
void write()
{
TFileIOResult dIOResult ;
Delete(FILENAME, dIOResult);

TFileIOResult nIOResult ;
TFileHandle LIGHTFILE ;
int FileSize = index ;
int i;

OpenWrite ( LIGHTFILE , nIOResult , FILENAME , FileSize );

for (i=0;i < local_index2 ;i ++)
{
WriteShort( LIGHTFILE , nIOResult ,road[i][0]);
WriteShort( LIGHTFILE , nIOResult ,road[i][1]);
}

Close ( LIGHTFILE , nIOResult );
}
void reaad()
{
TFileIOResult nIOResult ;
TFileHandle LIGHTFILE ;
int FileSize = index ;
int i;
int n;
OpenRead ( LIGHTFILE , nIOResult , FILENAME , FileSize );
for (i=1;i <=readindex ;i ++) {

ReadShort ( LIGHTFILE , nIOResult ,n);


}
Close ( LIGHTFILE , nIOResult );
}
task main(){
reaad();
while (true)
{
while(SensorValue(touch) == 0) //a while loop is declared with the touchsensor's value being 0 as it true condition
{
timevalue_first = nSysTime;
if((SensorValue(sonar)>=3)&&(SensorValue(sonar)<=4))
{
motor[mc]=+60;
motor[mb]=+60;
}
else if((SensorValue(sonar)>=1)&&(SensorValue(sonar)<=2))
{
motor[mc]=+60;
motor[mb]=+50;
}
else if((SensorValue(sonar)>=5)&&(SensorValue(sonar)<6))
{
motor[mc]=+50;
motor[mb]=+60;
}
else if(SensorValue(sonar)>15)
{
timevalue_last = nSysTime;

motor[mc]=0;
motor[mb]=+60;
wait1Msec(1000);
motor[mc]=+60;
motor[mb]=+60;
wait1Msec(500);

timevalue = timevalue_last - timevalue_first;
vector_value = SensorValue(compass);
VectorChar();
ar[index][0] = char_vector_value;
ar[index][1] = timevalue;
index++;
nxtDisplayTextLine(1, "Raw: %3d, %3d",char_vector_value,timevalue);

}

}

timevalue_last = nSysTime;
timevalue = timevalue_last - timevalue_first;
vector_value = SensorValue(compass);
VectorChar();
ar[index][0] = char_vector_value;
ar[index][1] = timevalue;
index++;
nxtDisplayTextLine(5, "Raw: %3d, %3d",char_vector_value,timevalue);

motor[mb] = -60; //motor A is run at a -75 power level
motor[mc] = -60;
wait1Msec(300);
motor[mb] = +60; //motor A is run at a -75 power level
motor[mc] = -60; //motor B is run at a -75 power level
wait1Msec(1000); //the program waits 1000 milliseconds before running further code
if(sensorvalue(color)==1)
break;
filteration();

}
}


Mon Jul 09, 2012 5:48 am
Profile
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post Re: project for solving maze
I'm working on line solving, so probably not much help there. but check out http://www.societyofrobots.com/member_tutorials/node/94 - seems to cover the wall maze topic.

I looked quickly at your code, and could not follow what it was trying to do - so my first impression is overly complicated.

In my project, downloadable from here; http://www.spiked3.com/?p=319

look at the file MazeSolve1.cs. the basics for a line maze solving robot is there, in a fairly compact and (hopefully) readable format. Don't let the fact that it is c# bother you. The maze solving code part is (intentionally) simple non oop code.

_________________
Mike aka Spiked3
http://www.spiked3.com


Mon Jul 09, 2012 1:28 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post Re: project for solving maze
Hi Fahd,

Can you describe in more detail the problem your having?

Scott B-)

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Wed Jul 11, 2012 12:12 am
Profile WWW
Rookie

Joined: Tue Jun 05, 2012 2:31 pm
Posts: 11
Post Re: project for solving maze
Spiked3 wrote:
I'm working on line solving, so probably not much help there. but check out http://www.societyofrobots.com/member_tutorials/node/94 - seems to cover the wall maze topic.

thanks so mush it is really useful


Wed Jul 11, 2012 2:47 am
Profile
Rookie

Joined: Tue Jun 05, 2012 2:31 pm
Posts: 11
Post Re: project for solving maze
starwarslegokid wrote:
Hi Fahd,

Can you describe in more detail the problem your having?

Scott B-)

the problem i think it's in synchronization in every step
i will make comments for every line in this code


Wed Jul 11, 2012 2:49 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.