Go Down

Topic: error: expected constructor, destructor, or type conversion before 'int'[solved] (Read 1 time) previous topic - next topic

OstroRobotics

Hello, I am working on robot for the FireFighting robot contest hosted by Trinity College and am using an Arduino Mega 2560.
While writing the new code for the robot it gave me the error:
Quote
error: expected constructor, destructor, or type conversion before 'int'

I've tried this method or inputing global variables before on this board (never as many in number though), and I've never had a problem compiling it and it always worked.
Here is (part of) the code:
Code: [Select]

//define motors
#define M1 52
#define M2 50
#define E1 3
#define E2 4

//define control LEDs
#define looking1LED 23
#define looking2LED 25
#define looking3LED 27
#define looking4LED 29
#define looking5LED 31
#define looking6LED 33
#define lookingDogLed 35
#define R1stateLED 37
#define L1stateLED 39
#define FstateLED 13

//define LED states
#define LEDon 1
#define LEDoff 0

//define distance sensors
#define leftfront 7
#define leftback 1
#define rightfront 6
#define rightback 2
#define front 3
#define back 0

//define distance sensor state:Busy/Clear
#define Busy 0
#define Clear 1

//constants for Straightening out
#define k 2
#define w_dis_cm 18

//state constants
#define start 0
#define looking 1
#define finish 2

//looking state case constants


//initialize global variables

int R1,R2;//R1- value of rightfront sensor, R2- value of rightback sensor
int L1,L2; //L1-valur of leftfront sensor, L1- value of leftback sensor
int F,B; //F-value of front sensor, B- value of back sensor
int CmR1,CmR2; //CmR1- distance in centimeters of rightfront sensor, CmR2- distance in centimeters of rightback sensor
int CmL1,CmL2; //CmL1- distance in centimeters of leftfront sensor, CmL2- distance in centimeters of leftback sensor
int CmF; //CmF- distance in centimeters of front sensor
int Fstate; //stores the state of front distance sensor: Busy or Clear
int L1state,L2state; //stores the state of the leftfront (L1state) and the leftback (L2state) distance sensors: Busy or Clear
int R1state,R2state; //stores the state of the rightfront (R1state) and the rightback (R2state) distance sensors: Busy or Clear
int state=start; //stores the current state to refer to, initizlized to start
int lookingCaseNumber; //stores current case to refer to inside looking
int previousCaseNumber; //stores previous looking case number in order to turn off its LED
int rightmotor=255; //PWM of right motor, initialized to maximal PWM of 255
int leftmotor=255; //PWM of left motor, initialized to maximal PWM of 255
int mone=1; //condition for checking start position

int convert (int val)
//converts the distance sensors output value to centimeters
{
 double temp=3027.4/val;
 double cm=pow(temp,1.2134);
 return cm;
}

void checkDistanceSensors()
//checks all distance sensors in use and stores thier values in the corresponding global variable
{
  L1=analogRead(leftfront);
  L2=analogRead(leftback);
  R1=analogRead(rightfront);
  R2=analogRead(rightback);
  F=analogRead(front);
  B=analogRead(back);
}

void StraightenToLeft()
//makes the robot drive straight in comaprison to the left wall
{
   CmL1=convert(L1);
   CmL2=convert(L2);
   int error=CmL1-CmL2;
    int fix1=abs(w_dis_cm-CmL1);
    int fix2=abs(w_dis_cm-CmL2);
    if(error>0)
    {
      leftmotor=leftmotor-k*fix1;
      rightmotor=255;
      analogWrite(E1,leftmotor);
      analogWrite(E2,rightmotor);
    }
    else
    {
      rightmotor=rightmotor-k*fix2;
      leftmotor=255;
      analogWrite(E1,leftmotor);
      analogWrite(E2,rightmotor);
    }
}
void turnRight()
//turn right based soley on when right sensor recconnects with the wall
{
   while (R1<180)
 {
   analogWrite(E2,255);
   digitalWrite(M1,LOW);
   digitalWrite(M2,HIGH);
   analogWrite(E1,175);
 }
 digitalWrite(M1,HIGH);
 analogWrite(E1,255);
}

void turnLeft()
//turn left based soley on when left sensor recconnects with the wall
{
while(L1<180)
 {
   analogWrite(E1,255);
   digitalWrite(M2,LOW);
   digitalWrite(M1,HIGH);
   analogWrite(E2,175);
   checkSensor();
 }
 digitalWrite(M2,HIGH);
 analogWrite(E2,255);
}

void StraightenBackwards()
//straighten out to the left while driving backwards
{
   CmL1=convert(L1);
   CmL2=convert(L2);
   int error=CmL1-CmL2;
   int fix1=abs(w_dis_cm-CmL1);
   int fix2=abs(w_dis_cm-CmL2);
   if(error>0)
   {
     rightmotor=rightmotor-k*fix1;
     leftmotor=255;
     analogWrite(E1,leftmotor);
     analogWrite(E2,rightmotor);
   }
   else
   {
     leftmotor=leftmotor-k*fix2;
     rightmotor=255;
     analogWrite(E1,leftmotor);
     analogWrite(E2,rightmotor);
   }
}

void setup()
{
 //define LEDs as output
 pinMode(looking1LED,OUTPUT);
 pinMode(looking2LED,OUTPUT);
 pinMode(looking3LED,OUTPUT);
 pinMode(looking4LED,OUTPUT);
 pinMode(looking5LED,OUTPUT);
 pinMode(looking6LED,OUTPUT);
 pinMode(L1stateLED,OUTPUT);
 pinMode(R1stateLED,OUTPUT);
 pinMode(FstateLED,OUTPUT);
   
 //define motor direction pins as output
 pinMode(M1,OUTPUT);
 pinMode(M2,OUTPUT);
}


Thank you :)

Nick Gammon

It's no good posting part of the code. When I tried to compile that I got:

Code: [Select]
sketch_dec29b.cpp: In function 'void turnLeft()':
sketch_dec29b:129: error: 'checkSensor' was not declared in this scope


You can attach your code to a post as an attachment. Click "additional options".
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

OstroRobotics

I apologize, I didn't want to swamp you with my code...
I attached the file here, I know there are additional compilation problems but I'm having a hard time finding them manually because the compiler won't move past the error i mentioned earlier.

holmes4


OstroRobotics

It was complaining about the line
Quote
int R1,R2;//R1- value of rightfront sensor, R2- value of rightback sensor


but while waiting for your answers I went over the rest of the program to find all the typos I inevitably made, I found a few missing ';' and such and when I pressed compile again it suddenly worked... My program has a mind of its own, but thank you for trying to help me!

Nick Gammon


... but thank you for trying to help me!


Quote from: Yoda

Try not.  Do, or do not.  There is no try.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

PaulS

Code: [Select]
int R1,R2;//R1- value of rightfront sensor, R2- value of rightback sensor
You might want to seriously consider getting your space key fixed.

Code: [Select]
int R1, R2;  // R1- value of rightfront sensor, R2- value of rightback sensor
is much easier to read.

Khalid


Quote from: Yoda

Try not.  Do, or do not.  There is no try.


The Grand Master of the Jedi Council is here;) :smiley-mr-green:
Simply...You can't afford me..

Author Of:
http://my-woodcarving.blogspot.com/
http://www.free3dscans.blogspot.com/
http://my-diysolarwind.blogspot.com/

Oops..some one gave me Karma...:)

Go Up