ROBOTC.net forums
http://robotc.net/forums/

Environment Learning using Sonar sensor
http://robotc.net/forums/viewtopic.php?f=1&t=1875
Page 1 of 1

Author:  irfan0611 [ Thu Oct 08, 2009 2:34 pm ]
Post subject:  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;
    }
  }

}

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/