I'm currently writing this code for a school project using the components stated in the title. I have been debugging and attempting to get a verified code to upload to the micro, but I keep getting an awkward "expected initializer before "mySerial"". I've searched through the arduino forums and it seems like an uncommon error to have with the TX/RX. Any ideas on why I may be receiving this error message? Thanks in advance, I don't know what I would do without this site.
Code: Select all
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_BMP085_U.h>
#include <Adafruit_10DOF.h>
#include <Adafruit_GPS_Library_master.h>
#include <SoftwareSerial.h>
/* Assign a unique ID to the sensors */
Adafruit_10DOF dof = Adafruit_10DOF();
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(30302);
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(18001);
int targetHeading; // where we want to go to reach current waypoint
int currentHeading; // where we are actually facing now
int headingError;
int distanceTodestination,// signed (+/-) difference between targetHeading and currentHeading
#define HEADING_TOLERANCE 5 // tolerance +/- (in degrees) within which we don't attempt to turn to intercept targetHeading
#define GPSECHO false // set to TRUE for GPS debugging if needed
//#define GPSECHO true // set to TRUE for GPS debugging if needed
SoftwareSerial mySerial(0, 1);
Adafruit_GPS_Library_master GPS(&mySerial);
boolean usingInterrupt = false;
float currentLat,
currentLong,
targetLat,
targetLong,
// distance to original waypoing when we started navigating to it
/* Update this with the correct SLP for accurate altitude measurements */
//
// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect)
{
GPS.read();
}
//
// turn interrupt on and off
void useInterrupt(boolean v)
{
if (v) {
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
usingInterrupt = true;
} else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
}
float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
/**************************************************************************/
/*!
@brief Initialises all the sensors used by this example
*/
/**************************************************************************/
void initSensors()
{
if(!accel.begin())
{
/* There was a problem detecting the LSM303 ... check your connections */
Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!"));
while(1);
}
if(!mag.begin())
{
/* There was a problem detecting the LSM303 ... check your connections */
Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
while(1);
}
if(!bmp.begin())
{
/* There was a problem detecting the BMP180 ... check your connections */
Serial.println("Ooops, no BMP180 detected ... Check your wiring!");
while(1);
}
}
/**************************************************************************/
/*!
*/
/**************************************************************************/
void setup(void)
{
Serial.begin(115200);
Serial.println(F("ARLISS FALL SEMESTER BOYEEEEEE")); Serial.println("");
/* Initialise the sensors */
initSensors();
//
// start GPS and set desired configuration
GPS.begin(9600); // 9600 NMEA default speed
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); // turns on RMC and GGA (fix data)
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
GPS.sendCommand(PGCMD_NOANTENNA); // turn off antenna status info
useInterrupt(true); // use interrupt to constantly pull data from GPS
delay(1000);
//
// Wait for GPS to get signal
#ifndef NO_GPS_WAIT
}
/**************************************************************************/
/*!
@brief Constantly check the roll/pitch/heading/altitude/temperature
*/
/**************************************************************************/
void loop(void)
{
sensors_event_t accel_event;
sensors_event_t mag_event;
sensors_event_t bmp_event;
sensors_vec_t orientation;
// Process GPS
if (GPS.newNMEAreceived()) // check for updated GPS information
{
if(GPS.parse(GPS.lastNMEA()) ) // if we successfully parse it, update our data fields
processGPS();
}
/* Calculate the heading using the magnetometer */
mag.getEvent(&mag_event);
if (dof.magGetOrientation(SENSOR_AXIS_Z, &mag_event, &orientation))
{
/* 'orientation' should have valid .heading data now */
Serial.print(F("Heading: "));
Serial.print(orientation.heading);
Serial.print(F("; "));
}
calcDesiredTurn(); // calculate how we would optimatally turn, without regard to obstacles
Serial.println(F(""));
delay(1000);
}
void processGPS(void)
{
currentLat = convertDegMinToDecDeg(GPS.latitude);
currentLong = convertDegMinToDecDeg(GPS.longitude);
if (GPS.lat == 'S') // make them signed
currentLat = -currentLat;
if (GPS.lon = 'W')
currentLong = -currentLong;
// update the course and distance to waypoint based on our new position
distanceToTarget();
courseToWaypoint();
} // processGPS(void)
void calcDesiredTurn(void)
{
// calculate where we need to turn to head to destination
headingError = targetHeading - currentHeading;
// adjust for compass wrap
if (headingError < -180)
headingError += 360;
if (headingError > 180)
headingError -= 360;
// calculate which way to turn to intercept the targetHeading
if (abs(headingError) <= HEADING_TOLERANCE) // if within tolerance, don't turn
Serial.println("Straight");
else if (headingError < 0)
Serial.println("Left");
else if (headingError > 0)
Serial.println("Right");
else
Serial.println("Straight");
} // calcDesiredTurn()
int distanceToTarget()
{
float delta = radians(currentLong - targetLong);
float sdlong = sin(delta);
float cdlong = cos(delta);
float lat1 = radians(currentLat);
float lat2 = radians(targetLat);
float slat1 = sin(lat1);
float clat1 = cos(lat1);
float slat2 = sin(lat2);
float clat2 = cos(lat2);
delta = (clat1 * slat2) - (slat1 * clat2 * cdlong);
delta = sq(delta);
delta += sq(clat2 * sdlong);
delta = sqrt(delta);
float denom = (slat1 * slat2) + (clat1 * clat2 * cdlong);
delta = atan2(delta, denom);
distanceTodestination = delta * 6372795;
return distanceTodestination;
} // distanceToWaypoint()
// converts lat/long from Adafruit degree-minute format to decimal-degrees; requires <math.h> library
double convertDegMinToDecDeg (float degMin)
{
double min = 0.0;
double decDeg = 0.0;
//get the minutes, fmod() requires double
min = fmod((double)degMin, 100.0);
//rebuild coordinates in decimal degrees
degMin = (int) ( degMin / 100 );
decDeg = degMin + ( min / 60 );
return decDeg;
}
int courseToWaypoint()
{
float dlon = radians(targetLong-currentLong);
float cLat = radians(currentLat);
float tLat = radians(targetLat);
float a1 = sin(dlon) * cos(tLat);
float a2 = sin(cLat) * cos(tLat) * cos(dlon);
a2 = cos(cLat) * sin(tLat) - a2;
a2 = atan2(a1, a2);
if (a2 < 0.0)
{
a2 += TWO_PI;
}
targetHeading = degrees(a2);
return targetHeading;
} // courseToWaypoint()