I was trying to remove the extraneous material. I am sorry if that was not as good thing to do. Here are the unadulterated files and the errors
Inititial try declaring a static const double array
/*
Compass and Motor commands kept here to make the sketch easier to debug
*/
#ifndef I2C_h
#define I2C_h
#include "Arduino.h"
#define LEFTMOTOR 0x58 // Address of MD03 1
#define RIGHTMOTOR 0x59 // Address of MD03 2
#define SOFTREG 0x07 // Byte to read software
#define CMDBYTE 0x00 // Command byte
#define STATUSREG 0x00 // Byte to read status register
#define SPEEDBYTE 0x02 // Byte to write to speed register
#define ACCELBYTE 0x03 // Byte to write to accelleration register
#define TEMPREG 0x04 // Byte to read temprature
#define CURRENTREG 0x05 // Byte to read motor current
#define COMPASS 0x60 // Defines address of CMPS10
class I2C
{
public:
I2C()
{
};
static void begin();
static int getBearing(char *pitch,char *roll);
static void getRawData(int *mX,int *mY,int *mZ,int *aX,int *aY,int *aZ );
static byte getData(int address,byte reg);
static void sendData(int address,byte reg, byte val);
static void setSpeed(int address,byte speed,int direction);
static void setAcceleration(byte accel);
static const double adjustReading[12] ={0.0,0.1,0.2,
0.3,0.4,0.5
0.6,0.7,0.8,
0.9,0.10,0.11};
static const double magneticAdjustment = -1.4666667;
//static char pitch;
//static char roll;
//static int bearing;
};
#endif
Here is the error report
In file included from RPiControlledBadger.ino:6:
C:\Arduino\libraries\I2C/I2C.h:38: error: a brace-enclosed initializer is not allowed here before '{' token
C:\Arduino\libraries\I2C/I2C.h:41: error: invalid in-class initialization of static data member of non-integral type 'const double [12]'
Second attempt removing the const and trying to set the values in the constructor
/*
Compass and Motor commands kept here to make the sketch easier to debug
*/
#ifndef I2C_h
#define I2C_h
#include "Arduino.h"
#define LEFTMOTOR 0x58 // Address of MD03 1
#define RIGHTMOTOR 0x59 // Address of MD03 2
#define SOFTREG 0x07 // Byte to read software
#define CMDBYTE 0x00 // Command byte
#define STATUSREG 0x00 // Byte to read status register
#define SPEEDBYTE 0x02 // Byte to write to speed register
#define ACCELBYTE 0x03 // Byte to write to accelleration register
#define TEMPREG 0x04 // Byte to read temprature
#define CURRENTREG 0x05 // Byte to read motor current
#define COMPASS 0x60 // Defines address of CMPS10
class I2C
{
public:
I2C()
{
adjustReading[0]= 0.0;
adjustReading[1]= 0.0;
adjustReading[2]= 0.0;
adjustReading[3]= 0.0;
adjustReading[4]= 0.0;
adjustReading[5]= 0.0;
adjustReading[6]= 0.0;
adjustReading[7]= 0.0;
adjustReading[8]= 0.0;
adjustReading[9]= 0.0;
adjustReading[10]= 0.0;
adjustReading[11]= 0.0;
};
static void begin();
static int getBearing(char *pitch,char *roll);
static void getRawData(int *mX,int *mY,int *mZ,int *aX,int *aY,int *aZ );
static byte getData(int address,byte reg);
static void sendData(int address,byte reg, byte val);
static void setSpeed(int address,byte speed,int direction);
static void setAcceleration(byte accel);
static double adjustReading[12];
static const double magneticAdjustment = -1.4666667;
//static char pitch;
//static char roll;
//static int bearing;
};
#endif
Here are the reported errors
I2C\I2C.cpp.o: In function I2C::getBearing(char*, char*)': C:\Arduino\libraries\I2C/I2C.cpp:40: undefined reference to
I2C::adjustReading'
C:\Arduino\libraries\I2C/I2C.cpp:40: undefined reference to I2C::adjustReading' C:\Arduino\libraries\I2C/I2C.cpp:45: undefined reference to
I2C::adjustReading'
C:\Arduino\libraries\I2C/I2C.cpp:45: undefined reference to `I2C::adjustReading'
the I2C.C file is the following:
/*
Compass and Motor commands kept here to make the sketch easier to debug
*/
#include "Arduino.h"
#include "I2C.h"
#include "C:\Program Files\arduino-1.0.3\libraries\Wire\Wire.h"
void I2C::begin()
{
Wire.begin();
delay(100);
}
int I2C::getBearing(char *p,char *r)
{
byte highByte, lowByte; // highByte and lowByte store high and low bytes of the bearing and fine stores decimal place of bearing
char pitch, roll; // Stores pitch and roll values of CMPS10, chars are used because they support signed value
int bearing; // Stores full bearing
Wire.beginTransmission(COMPASS); //starts communication with CMPS10
Wire.write(2); //Sends the register we wish to start reading from
Wire.endTransmission();
Wire.requestFrom(COMPASS, 4); // Request 4 bytes from CMPS10
while(Wire.available() < 4); // Wait for bytes to become available
highByte = Wire.read();
lowByte = Wire.read();
pitch = Wire.read();
roll = Wire.read();
bearing = ((highByte<<8)+lowByte); // Calculate full bearing
// look up bearing in the table
int posBottom = bearing/30;
int posTop = (posBottom+1)%12;
double varBottom = adjustReading[posBottom];
double varTop = adjustReading[posTop];
double bottom = posBottom*30;
double diff = varBottom+(varTop-varBottom)*(bearing-bottom)/30;
bearing = bearing+diff + magneticAdjustment;
//Serial.print("Bearing ");Serial.print(bearing);
//Serial.print(" Pitch ");Serial.print(int(pitch));
//Serial.print(" Roll ");Serial.println(int(roll));
*p=pitch;
*r=roll;
return bearing;
}
void I2C::getRawData(int *mX,int *mY,int *mZ,int *aX,int *aY,int *aZ )
{
byte MXh,MXl,MYh,MYl,MZh,MZl,AXh,AXl,AYh,AYl,AZh,AZl;
Wire.beginTransmission(COMPASS); //starts communication with CMPS10
Wire.write(2); //Sends the register we wish to start reading from
Wire.endTransmission();
Wire.beginTransmission(COMPASS); //starts communication with CMPS10
Wire.write(10); //Sends the register we wish to start reading from
Wire.endTransmission();
Wire.requestFrom(COMPASS, 12); // Request 4 bytes from CMPS10
while(Wire.available() < 12); // Wait for bytes to become available
MXh = Wire.read();
MXl = Wire.read();
MYh = Wire.read();
MYl = Wire.read();
MZh = Wire.read();
MZl = Wire.read();
AXh = Wire.read();
AXl = Wire.read();
AYh = Wire.read();
AYl = Wire.read();
AZh = Wire.read();
AZl = Wire.read();
*mX = (MXh<<8)+ MXl;
*mY = (MYh<<8)+ MYl;
*mZ = (MZh<<8)+ MZl;
*aX = (AXh<<8)+ AXl;
*aY = (AYh<<8)+ AYl;
*aZ = (AZh<<8)+ AZl;
}
byte I2C::getData(int address,byte reg)
{ // function for getting data from MD03
Wire.beginTransmission(address);
Wire.write(reg);
Wire.endTransmission();
Wire.requestFrom(address, 1); // Requests byte from MD03
while(Wire.available() < 1); // Waits for byte to become availble
byte data = Wire.read();
return(data);
}
void I2C::sendData(int address,byte reg, byte val)
{ // Function for sending data to MD03
Wire.beginTransmission(address); // Send data to MD03
Wire.write(reg);
Wire.write(val);
Wire.endTransmission();
}
void I2C::setSpeed(int address,byte speed,int direction)
{
I2C::sendData(address,SPEEDBYTE, speed);
I2C::sendData(address,CMDBYTE, direction);
}
void I2C::setAcceleration(byte accel)
{
I2C::sendData(RIGHTMOTOR,ACCELBYTE,accel);
I2C::sendData(LEFTMOTOR, ACCELBYTE,accel);
}