Pages: [1] 2   Go Down
Author Topic: Arduino Uno - error msg: expected initializer before 'bridge' - plus another sim  (Read 2553 times)
0 Members and 1 Guest are viewing this topic.
Nanaimo, BC, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Using EasyVR, I got a program off the internet, to turn an LED off, and on, with voice commands.
Compiling gave many error messages, and I was able to correct them all, except the following two:

- expected initilalizer before 'bridge'

- In function 'void setup()': 'bridge was not declared in this scope

Code:

#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
  #include "SoftwareSerial.h"
SoftwareSerial port(12,13);
#endif

  #include "EasyVR.h"

EasyVR easyvr(port);

//Groups and Commands
enum Groups

  GROUP_0 = 0,
GROUP_1 = 1,
}

enum Group0
{
  G0_ARDUINO = 0,
}

enum Group1
{
  G1_LED_AN = 0,
G1_LED_AUS = 1,
}

EasyVRBridge bridge;
int8_t group, idx;

void setup()
{
  // bridge mode?
if (bridge.check())


I have searched in the forum for "expected initializing before ..." and found nothing helpful but,
 as I am new to this, I may easily have overlooked something.

Any suggestions appreciated.
Thanks,
Don Oliver
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
There is a library dedicated to EasyVR and in this library 2 classes are defined
- EasyVR and
- EasyVRBridge

Therefore you have to include the file EasyVRBridge.h and
add create the object bridge with the following line:
EasyVRBridge bridge;

Take care as I'm not familiar with this library, maybe additional parameters are needed

Hope this will help

Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't have semicolons on your enum statements.

Code:
enum Groups

  GROUP_0 = 0,
GROUP_1 = 1,
}

enum Group0
{
  G0_ARDUINO = 0,
}

enum Group1
{
  G1_LED_AN = 0,
G1_LED_AUS = 1,
}
Logged

Nanaimo, BC, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
There is a library dedicated to EasyVR and in this library 2 classes are defined
- EasyVR and
- EasyVRBridge

Therefore you have to include the file EasyVRBridge.h and
add create the object bridge with the following line:
EasyVRBridge bridge;

Take care as I'm not familiar with this library, maybe additional parameters are needed

Hope this will help


Thanks for your answer.
Two things:
- I included EasyVRBridge.h, and still get the same error message.
- TestEasyVR.pde does not include this file, and works perfectly

Don
Logged

Nanaimo, BC, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't have semicolons on your enum statements.

Code:
enum Groups

  GROUP_0 = 0,
GROUP_1 = 1,
}

enum Group0
{
  G0_ARDUINO = 0,
}

enum Group1
{
  G1_LED_AN = 0,
G1_LED_AUS = 1,
}


I don't believe that semicolons are required after enum statements, at least, in the examples that I have seen???

Thanks, Don
Logged

Offline Offline
God Member
*****
Karma: 17
Posts: 748
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I don't believe that semicolons are required after enum statements, at least, in the examples that I have seen???

Thanks, Don

You believe wrongly then.  You need a semicolon after the closing curly brace on each one. 
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I don't believe that semicolons are required after enum statements, at least, in the examples that I have seen???
How long would it have taken to test?
Logged

Nanaimo, BC, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Quote
I don't believe that semicolons are required after enum statements, at least, in the examples that I have seen???
How long would it have taken to test?

Thanks for the replies.
You are right, of course, I should have tried it.
So, today I did, and got the error message: "expected identifier before ';' token" on each one.
The original errors,regarding 'bridge', however, did not show.

I did not make the program, I am only trying to run it.

As I said, I am new to this, so maybe did not do it correctly?

Modified code:
Code:
// Groups and Commands
enum Groups
{;
  GROUP_0 = 0,
GROUP_1 = 1,
};

enum Group0
{
  G0_ARDUINO = 0,
};

enum Group1
{;
  G1_LED_AN = 0,
G1_LED_AUS = 1,
};

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49074
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
As I said, I am new to this, so maybe did not do it correctly?
I'm sure that the compiler had something to say about this:
Code:
enum Groups
{;
And, I'm sure that it was not "Nice job!".
Logged

Nanaimo, BC, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
As I said, I am new to this, so maybe did not do it correctly?
I'm sure that the compiler had something to say about this:
Code:
enum Groups {;
And, I'm sure that it was not "Nice job!".

 It was not  smiley

As I included in my last message, it said:  expected identifier before ';' token

I do not know where to go from here.
Thanks,
Don
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49074
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I do not know where to go from here.
Perhaps you should look at some code that does compile. You'll notice that there are hardly ever semicolons in the middle of a statement. The sole exception that I can think of is the for statement.

Code:
enum Groups
{
  GROUP_0 = 0,
GROUP_1 = 1,
};
Logged

Nanaimo, BC, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I do not know where to go from here.
Perhaps you should look at some code that does compile. You'll notice that there are hardly ever semicolons in the middle of a statement. The sole exception that I can think of is the for statement.

Code:
enum Groups
{
  GROUP_0 = 0,
GROUP_1 = 1,
};


The only examples that I could find, using enum, did not use semicolons.

OK, I changed the section to:
Code:
// Groups and Commands
enum Groups
{
  GROUP_0 = 0,
GROUP_1 = 1,
};

enum Group0
{
  G0_ARDUINO = 0,
};

enum Group1
{
  G1_LED_AN = 0,
G1_LED_AUS = 1,
};

Now, it compiles, and runs, without error but, instead of the Serial Monitor displaying "Say a command in Group 0", then Group1, Group2,
it just displays "Say a command in Group"

The TestEasyVR program, which similar, but does not use enum, runs  perfectly.
 It uses the following instead:

Code:
EasyVR easyvr(port);

int8_t set = 0;
int8_t group = 0;
uint32_t mask = 0; 
uint8_t train = 0;
char name[32];
bool useCommands = true;

EasyVRBridge bridge;

It seems to me that my problem is with the use of enum?

Thanks to all for your patience,
Don
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49074
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Now, it compiles, and runs, without error but, instead of the Serial Monitor displaying "Say a command in Group 0", then Group1, Group2,
it just displays "Say a command in Group"
You have not posted all of your code, so it is impossible to say what is wrong.

Quote
It seems to me that my problem is with the use of enum?
An enum is simply a way of assigning names to numbers, and using the names in place of the numbers, is cases where names make more sense. For instance, the days of the week are either Sunday, Monday, Tuesday, etc. or 0, 1, 2, etc. If you want to remember that Thursday is equal to 4, that's fine, but most people would rather use a name.

So, it is unlikely that your problem is with the use of enum. It is more likely that your problem is with the misuse of enum.
Logged

Nanaimo, BC, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So, it is unlikely that your problem is with the use of enum. It is more likely that your problem is with the misuse of enum.

I believe that you may be right, but I find it confusing.

Quote
You have not posted all of your code, so it is impossible to say what is wrong.

Complete code:

Code:

#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
  #include "SoftwareSerial.h"
SoftwareSerial port(12,13);
#endif

#include "EasyVR.h"

EasyVR easyvr(port);

// Groups and Commands
enum Groups
{
  GROUP_0 = 0,
GROUP_1 = 1,
};

enum Group0
{
  G0_ARDUINO = 0,
};

enum Group1
{
  G1_LED_AN = 0,
G1_LED_AUS = 1,
};

EasyVRBridge bridge;
int8_t group, idx;

void setup()
{
  // bridge mode?
if (bridge.check())

{
cli();
bridge.loop(0,1,12,13);
  }
// run normally
Serial.begin(9600);
port.begin(9600);

if (!easyvr.detect())
{
  Serial.println("EasyVR not detected!");
for (;;);
}

easyvr.setPinOutput(EasyVR::IO1, LOW);
Serial.println("EasyVR detected!");
easyvr.setTimeout(5);
easyvr.setLanguage(3);

group = EasyVR::TRIGGER; // -- start group (customize)

pinMode(11, OUTPUT);
digitalWrite(11, LOW);  // set the LED off

}

void action ();

void loop()
{
  easyvr.setPinOutput(EasyVR::IO1, HIGH);  // LED on (listening)

Serial.print("Say a command in Group");
easyvr.recognizeCommand(group);

do
{
  // can do some processing while waiting for a spoken command
}
while (!easyvr.hasFinished());

easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off

idx = easyvr.getWord();
if (idx = 0)
{
  // built-in trigger (ROBOT)
// group = GROUP_X; <-- jump to another group X
return;
  }
idx = easyvr.getCommand();
if (idx = 0)
{
  // print debug message
uint8_t train = 0;
char name [32];
Serial.print("Command:");
Serial.print(idx);
if (easyvr.dumpCommand(group, idx, name, train))
{
  Serial.print(" = ");
Serial.println(name);
}
else
  Serial.println();
easyvr.playSound(0, EasyVR::VOL_FULL);
// perform some action
action();
}
else // errors or timeout
{
  if (easyvr.isTimeout())
  Serial.println("Timed out, try again...");
int16_t err = easyvr.getError();
if (err  = 0)
{
  Serial.print("Error ");
Serial.println(err, HEX);
  }

group = GROUP_0;
}
}

void action()
{
switch (group)
  {
case GROUP_0:
  switch (idx)
{
case G0_ARDUINO:
  // write your action code here
  group = GROUP_1; // -- or jump to another group X for composite command
break;
case GROUP_1:
  switch (idx)
{
case G1_LED_AN:
  // write your action code here
group = GROUP_0; //-- or jump to another group X for composite command

digitalWrite(11, HIGH); // set the LED on

break;
case G1_LED_AUS:
  // write your action code here
group = GROUP_0; // - or jump to another group X for composite command
digitalWrite(11, LOW);  //set the LED off

break;
}
break;
}
  }
}

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49074
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
it just displays "Say a command in Group"
That's because that is what you told it to do:
Code:
Serial.print("Say a command in Group");

Code:
easyvr.recognizeCommand(group);
group was initialized to 0. I'm not sure what this function does, but it seems to me that the value passed in would be an index into a 2D array of words that the thing is supposed to compare what it hears to.

Code:
if (idx = 0)
if (idx = 0)
{
if (err  = 0)
{
These are assignments, not equality tests. The result of the assignment is 0 (false), so the if test never evaluates to true.
« Last Edit: May 21, 2012, 11:09:01 am by PaulS » Logged

Pages: [1] 2   Go Up
Jump to: