View unanswered posts | View active topics It is currently Mon Dec 17, 2018 8:45 am






Reply to topic  [ 2 posts ] 
RobotC seems to have a problem with while statement‏ 
Author Message
Rookie

Joined: Mon Mar 14, 2016 11:12 am
Posts: 1
Post 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.


Mon Mar 14, 2016 11:23 am
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post 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

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Mar 14, 2016 1:11 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.