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

RobotC seems to have a problem with while statement‏
http://robotc.net/forums/viewtopic.php?f=1&t=13624
Page 1 of 1

Author:  WinCisky [ Mon Mar 14, 2016 11:23 am ]
Post subject:  RobotC seems to have a problem with while statement‏

Hi everybody,
I am facing a strange error with my latest code:
when I use the while statement it gives me the following warning
"*Warning*:')' exepected before ';'. Automatically inserted."
so it generetes another warning and an error
"*Warning*:';' found following 'while' statement. Is this intentional?"
"**Error**:Unexpected ')' during parsing"
Have I done something wrong? What should I do?

This is the code:
Code:
#pragma config(Sensor, S1,      gyroscope,       sensorEV3_Gyro)
#pragma config(Sensor, S2,      SENSOR_RIGHT,   sensorEV3_Ultrasonic)
#pragma config(Sensor, S3,      SENSOR_FRONTAL, sensorEV3_Ultrasonic)
#pragma config(Motor,  motorD, wheelLeft,       tmotorNXT, PIDControl, encoder)
#pragma config(Motor,  motorA, wheelRight,       tmotorNXT, PIDControl, encoder)
#define TIME       2500;
#define SPEED       25;
#define DISTANCE    12;

typedef struct{
   int x;
   int y;
} pos;

typedef struct{
   pos position;
   string orientation;
} positions;

int      lengthListNextPositions;
int        lengthListUncertainPositions;
positions pickedPosition;
positions location;
positions ListNextPositions[50];
positions ListUncertainPositions[50];
short      powerWheelLeft;
short       powerWheelRight;

void GoForward(){
   clearTimer(T1);

   while(time1[T1]< TIME)
   {
     setMotorSpeed(wheelLeft,powerWheelLeft);
      setMotorSpeed(wheelRight,powerWheelRight);
  }
}

void Turn(const string side){
   resetGyro(gyroscope);
   if(side=="right"){
      while(currentDegrees<90){
         setMotorSpeed(wheelLeft,SPEED);
         setMotorSpeed(wheelRight,-SPEED);
      }
      ChangeDirection("right");
   }else{
      while(currentDegrees<90){
         setMotorSpeed(wheelLeft,-SPEED);
         setMotorSpeed(wheelRight,SPEED);
      }
      ChangeDirection("left");
   }
}

void CheckForWall(){
   InsertIntoList("left");
   if(SonarFwd>DISTANCE){
      InsertIntoList("forward");
   }
   if(SonarRight>DISTANCE){
      InsertIntoList("right");
   }
}

void Check(const string dir){
   if(dir=="forward"){
      if(SonarFwd>DISTANCE){
         InsertIntoList("forward");
      }
   }else{
      if(SonarRight>DISTANCE){
         InsertIntoList("right");
      }
   }
}

void InsertIntoList(const string dir){
   if((dir=="forward")||(dir=="right"){
      lengthListNextPositions++;
      ListNextPositions[lengthListNextPositions].position.x=location.x;
      ListNextPositions[lengthListNextPositions].position.y=location.y;
      if(dir=="forward"){
         ListNextPositions[lengthListNextPositions].orientation=direction;
      }else{
         if(direction=="nord"){
            ListNextPositions[lengthListNextPositions].orientation="est";
         }else if(direction=="est"){
            ListNextPositions[lengthListNextPositions].orientation="sud";
         }else if(direction=="sud"){
            ListNextPositions[lengthListNextPositions].orientation="ovest";
         }else{
            ListNextPositions[lengthListNextPositions].orientation="nord";
         }
      }
   }else if(dir=="left"){
      lengthListUncertainPositions++;
      ListUncertainPositions[lengthListUncertainPositions].position.x=location.x;
      ListUncertainPositions[lengthListUncertainPositions].position.y=location.y;
      if(direction=="nord"){
         ListNextPositions[lengthListNextPositions].orientation="ovest";
      }else if(direction=="est"){
         ListNextPositions[lengthListNextPositions].orientation="nord";
      }else if(direction=="sud"){
         ListNextPositions[lengthListNextPositions].orientation="est";
      }else{
         ListNextPositions[lengthListNextPositions].orientation="sud";
      }
   }else{
      //si sta inserendo il punto 12,12 sud per farne il wavfron, senza inserirlo nelle liste
   }
}

void PickPosition(const string listName){
   if(listName=="NextPositions"){
      pickedPosition.position.x=ListNextPositions[lengthListNextPositions].position.x;
      pickedPosition.position.y=ListNextPositions[lengthListNextPositions].position.y;
      pickedPosition.orientation=ListNextPositions[lengthListNextPositions].orientation;
      lengthListNextPositions--;
   }else{
      pickedPosition.position.x=UncertainPositions[lengthListUncertainPositions].position.x;
      pickedPosition.position.y=UncertainPositions[lengthListUncertainPositions].position.y;
      pickedPosition.orientation=UncertainPositions[lengthListUncertainPositions].orientation;
      lengthListUncertainPositions--;
   }
}

void Wavefront(){

}

void GoToPosition(){

}

task SonarValueUpdate(){
   while (true)
   {
      SonarFwd    = SensorValue[SENSOR_FRONTAL];
      SonarRight    = SensorValue[SENSOR_RIGHT];
      currentDegrees   = getGyroHeading(gyroscope);
      sleep(updateTime);
   }
}

task main(){
   lengthListNextPositions=0;
   lengthListUncertainPositions=0;

   while((lengthListNextPositions>0)||(lengthListUncertainPositions>0)){
      if(lengthListNextPositions>0){
         PickPosition("NextPositions");
         Wavefront();
         GoToPosition();
         GoForward();
      }else if(lengthListUncertainPositions>0){
         PickPosition("UncertainPositions");
         Wavefront();
         GoToPosition();
         //devo controllare avanti oppure a destra?
         Check("forward");
      }else{
         //devo andare alla casella 12,12(centro) e girarmi a nord
         Wavefront();
         GoToPosition();
      }
   }
}


I will include a screenshot with the problem.
Image

Thanks.

Author:  mightor [ Mon Mar 14, 2016 1:11 pm ]
Post subject:  Re: RobotC seems to have a problem with while statement‏

There are several issues with your code, but the main one is this:
Code:
#define TIME       2500
#define SPEED       25
#define DISTANCE    12

Do not put semicolons at the end of a define :)

= Xander

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