I am totally new to this type of stuff, so maybe you could enlighten me a little.
I am writing a program to get input from a 3-axis accelerometer and a gyroscope,
but I’m having trouble getting my code to work. Every time I try to build the code below,
I get an error:
c:/winavr-20090313/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr5\libc.a(fp_powsodd.o): In function `__fp_powsodd':
(.text.fplib+0x10): relocation truncated to fit: R_AVR_13_PCREL against symbol `__mulsf3' defined in .text section in c:/winavr-20090313/bin/../lib/gcc/avr/4.3.2/avr5\libgcc.a(_mul_sf.o)
c:/winavr-20090313/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr5\libc.a(fp_powsodd.o): In function `__fp_powsodd':
(.text.fplib+0x20): relocation truncated to fit: R_AVR_13_PCREL against symbol `__mulsf3' defined in .text section in c:/winavr-20090313/bin/../lib/gcc/avr/4.3.2/avr5\libgcc.a(_mul_sf.o)
make: *** [XYZ.elf] Error 1
Build failed with 1 errors and 0 warnings...
I don’t know what to do, and I don’t know what this error means.
#include <avr/io.h>
#include <pololu/orangutan.h>
#include <stdlib.h>
#include <math.h>
double vX0 = 0;
double vY0 = 0;
double vZ0 = 0;
double velocityX = 0;
double velocityY = 0;
double velocityZ = 0;
double trueVX = 0;
double trueVY = 0;
double deltaT = .01; //Assumes data comes in at .01 sec intervals.
const double PI = 3.141592;
int choosing;
double xDisplacement = 0;
double yDisplacement = 0;
double zDisplacement = 0;
long byteX, byteY, byteZ, byteTheta;
double xAcceleration = 0;
double yAcceleration = 0;
double zAcceleration = 0;
double totalDisplacementXY = 0;
double angleRotated = 0;
double theta = 0;
int sensorX()
{
int byte = analog_read(PORTC5);
return byte;
}
int sensorY()
{
int byte = analog_read(PORTC4);
return byte;
}
int sensorZ()
{
int byte = analog_read(PORTC3);
return byte;
}
int sensorTheta()
{
int byte = analog_read(PORTC2);
return byte;
}
void getData()
{
byteX = sensorX();
byteY = sensorY();
byteZ = sensorZ();
byteTheta = sensorTheta();
xAcceleration = (5*byteX)/1023; //This converts a value from 0 to 1023 to g's of acceleration.
yAcceleration = (5*byteY)/1023;
zAcceleration = (5*byteZ)/1023;
theta = (.0033/100)*(((5*byteTheta)/1023)-1.65);//This converts from a number between 0 and 1023 to degrees / cs (hundredth of a second)
// and the value of the coefficient divider is equal to the number of decimal places
} // .0033 needs to be set back (to deciseconds, centiseconds, milliseconds, ect...)
double getTrueVelocity( int chooser ){
if(angleRotated!=0 && chooser == 1)
{
angleRotated += theta;
trueVX = velocityX * cos ((angleRotated*PI/180));
return trueVX;
}
else if (angleRotated !=0 && chooser == 2)
{
angleRotated += theta;
trueVY = velocityY * cos ((angleRotated*PI/180));
return trueVY;
}
else
return 0.0;
}
double getX(){
getData();
choosing = 1;
velocityX = vX0 + (xAcceleration*9.8*deltaT); //Consider using just xAcceleration
vX0 = velocityX;
return getTrueVelocity(choosing);
}
double getY(){
choosing = 2;
velocityY = vY0 + (yAcceleration*9.8*deltaT); //Consider using just yAcceleration
vY0 = velocityY;
return getTrueVelocity(choosing);
}
double getZ(){
velocityZ = vZ0 + (zAcceleration*9.8*deltaT);
vZ0 = velocityZ;
return velocityZ;
}
void getTotalDisplacement(){
totalDisplacementXY = sqrt ((xDisplacement*xDisplacement)+(yDisplacement*yDisplacement)); //a^2 + b^2 = c^2
}
int main (int argc, char * const argv[]) {
set_analog_mode(MODE_10_BIT);
DDRC&=~((1<<PORTC5)|(1<<PORTC4)|(1<<PORTC3)|(1<<PORTC2));
xDisplacement += (getX()*deltaT);
yDisplacement += (getY()*deltaT);
zDisplacement += (getZ()*deltaT);
getTotalDisplacement();
clear();
print("Press");
lcd_goto_xy(0, 1);
print("button");
wait_for_button(ALL_BUTTONS);
clear();
while (1){
xDisplacement += (getX()*deltaT);
yDisplacement += (getY()*deltaT);
zDisplacement += (getZ()*deltaT);
getTotalDisplacement();
lcd_goto_xy(0, 0);
print("Dx= ");
long integer_xDisplacement = xDisplacement / 100;
print_long(integer_xDisplacement);
print(".");
long x_decimal = xDisplacement - integer_xDisplacement * 100;
if (x_decimal < 10)
print("0");
print_long(x_decimal);
lcd_goto_xy(0, 1);
print("Dy= ");
long integer_yDisplacement = yDisplacement / 100;
print_long(integer_yDisplacement);
print(".");
long y_decimal = yDisplacement - integer_yDisplacement * 100;
if (y_decimal < 10)
print("0");
print_long(y_decimal);
//Print stuff out
//Here
delay_ms(10);
clear();
}
return 0;
}
Any help with getting input would be greatly appreciated.