Nanaimo, BC, Canada
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« on: May 20, 2012, 01:35:09 pm » |
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 #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
Newbie
Karma: 0
Posts: 12
|
 |
« Reply #1 on: May 20, 2012, 02:07:22 pm » |
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
Faraday Member
Karma: 19
Posts: 3118
|
 |
« Reply #2 on: May 20, 2012, 02:13:24 pm » |
You don't have semicolons on your enum statements. 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
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #3 on: May 20, 2012, 03:01:40 pm » |
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
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #4 on: May 20, 2012, 03:53:18 pm » |
You don't have semicolons on your enum statements. 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
Sr. Member
Karma: 6
Posts: 399
|
 |
« Reply #5 on: May 20, 2012, 10:02:21 pm » |
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
Faraday Member
Karma: 19
Posts: 3118
|
 |
« Reply #6 on: May 21, 2012, 05:48:18 am » |
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
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #7 on: May 21, 2012, 08:30:50 am » |
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: // 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
Brattain Member
Karma: 313
Posts: 35506
Seattle, WA USA
|
 |
« Reply #8 on: May 21, 2012, 08:36:18 am » |
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: enum Groups {; And, I'm sure that it was not "Nice job!".
|
|
|
|
|
Logged
|
|
|
|
|
Nanaimo, BC, Canada
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #9 on: May 21, 2012, 09:12:02 am » |
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: enum Groups {; And, I'm sure that it was not "Nice job!". It was not  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
Brattain Member
Karma: 313
Posts: 35506
Seattle, WA USA
|
 |
« Reply #10 on: May 21, 2012, 09:14:41 am » |
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. enum Groups { GROUP_0 = 0, GROUP_1 = 1, };
|
|
|
|
|
Logged
|
|
|
|
|
Nanaimo, BC, Canada
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #11 on: May 21, 2012, 09:48:14 am » |
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. 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: // 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: 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
Brattain Member
Karma: 313
Posts: 35506
Seattle, WA USA
|
 |
« Reply #12 on: May 21, 2012, 10:06:32 am » |
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. 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
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #13 on: May 21, 2012, 10:34:57 am » |
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. You have not posted all of your code, so it is impossible to say what is wrong.
Complete 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
Brattain Member
Karma: 313
Posts: 35506
Seattle, WA USA
|
 |
« Reply #14 on: May 21, 2012, 11:06:55 am » |
it just displays "Say a command in Group" That's because that is what you told it to do: Serial.print("Say a command in Group"); 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. 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
|
|
|
|
|
|