I have been flying my Arducopter on the Arducopter_alpha_RC1 and ArducopterNG source code, but now I want to move to the ArduPirates source code so that I can use the downward-facing Sonar that I've just installed. When I attempt to compile the AruduPirates code, I get this error message:
'i' was not declared in this scope
ArduPiratesNG.cpp: In function 'void APM_Init()':
System:186: error: 'i' was not declared in this scope
Has anyone encountered this? Did I do something wrong during setup?
Here are the steps I took to retrieve and setup the sketches/libraries:
1. I downloaded the ArduPiratesNG-sketches.zip and ArduPiratesNG-libraries from http://code.google.com/p/ardupirates/downloads/list.
2. I moved the ArduPiratesNG-sketches folder into my sketches folder (and renamed it to to simply ArduPiratesNG).
3. I renamed my old Arducopter-related library folders with a _old, then moved the new ArduPiratesNG-library folders into my libraries folder, then stopped and restarted Arduino.
5. I opened the ArduPiratesNG sketch. I can see all the expected tabs.
6. I ran the Online Universal Ardu Configator, generated a config.h, and copied the generated code into the config.h file (replacing the old).
7. After setting my Board and Serial Port, I then try to compile and get the error message shown above.
Normally, when writing my own Arduino sketches, I know this means I forgot to define a variable and/or I've defined it in the wrong function. In this case, since I didn't write or modify any of this code, I assume it means that perhaps it's not finding one of the libraries or something like that. I'm not sure where I should go next.
Replies
I found the problem:
When using the Online Universal ArduConfiguator there is checkbox for whether you are going to use the Configurator or not. I left that unchecked because I don't use the Configurator. I use the CLI instead (I like the interface and I'm on a Mac).
Later, when I tried to compile the ArduPiratesNG code, it showed the error above.
When I looked closer I see that Line 186 is inside a #ifndef CONFIGURATOR in ArudPiratesNG.pde. I assume that because I left "Use Configurator" unchecked earlier, it didn't bring in the necessary code that declared the i variable.
So, I manually put "int i;" above the "for each" loop to declare the required variable.
The sketch now compiles.
Onward and upward.