View unanswered posts | View active topics It is currently Thu Sep 19, 2019 4:36 am






Reply to topic  [ 1 post ] 
Environment Learning using Sonar sensor 
Author Message
Rookie

Joined: Fri Aug 21, 2009 9:46 am
Posts: 6
Post Environment Learning using Sonar sensor
Hi,
I made this program in which robot travel in a room and when it detect an object it changes its direction and carry on travelling straight until it detect an object agian. this program should also learn its path while it travel but for some reason it isnt:( can anyone please check my codes and let me know where I went wrong?
Code:
 //*!!Sensor,    S1,          sonarSensor, sensorSONAR,      ,                    !!*//
//*!!                                                                            !!*//
//*!!Start automatically generated configuration code.                           !!*//
const tSensors sonarSensor          = (tSensors) S1;   //sensorSONAR        //*!!!!*//


task main()
{
  int detect [255];

  int i;
  for (i =0;i <=254; i ++) {
    detect[i]=0;
  }
   motor[motorC] = 50;
   motor[motorB] = 50;

  while(true)
  {

    if(SensorValue(sonarSensor) > 0) {

      int val = SensorValue(sonarSensor);


      int i;
      int found =0;
      for (i =0;i <=254; i ++) {
        if (val == detect [i]){
          found = 1 ;

         motor[motorC] = 50;
        motor[motorB] = 50;

        }
     //    wait1Msec(500);

}

      if (found == 0){
        for (i =0;i <=254; i ++){
          if (detect[i] == 0){
            detect [i] = val ;

                  motor[motorC] = -50;
            motor[motorB] = -25;
          wait1Msec(1000);
            break;

          }
        }
      }
     wait1Msec(1000);

      motor[motorC] = 50;
      motor[motorB] = 50;
    }
  }

}


Thu Oct 08, 2009 2:34 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

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.