我正在尝试使用FreeIMU库将加速度计Arduino板上的重力补偿加速度数据发送到我的计算机。以下是引发错误的.pde文件的一部分:
float q[4];
int raw_values[9];
float ypr[3]; // yaw pitch roll
char str[256];
float values[9];
// Set the FreeIMU object
FreeIMU my3IMU = FreeIMU();
//The command from the PC
char cmd;
void setup() {
Serial.begin(115200);
Wire.begin();
my3IMU.init(true);
// LED
pinMode(13, OUTPUT);
}
void loop() {
if(Serial.available()) {
cmd = Serial.read();
if(cmd=='v') {
sprintf(str, "FreeIMU library by %s, FREQ:%s, LIB_VERSION: %s, IMU: %s", FREEIMU_DEVELOPER, FREEIMU_FREQ, FREEIMU_LIB_VERSION, FREEIMU_ID);
Serial.print(str);
Serial.print('\n');
}
else if(cmd=='r') {
uint8_t count = serial_busy_wait();
for(uint8_t i=0; i<count; i++) {
my3IMU.getRawValues(raw_values);
sprintf(str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,", raw_values[0], raw_values[1], raw_values[2], raw_values[3], raw_values[4], raw_values[5], raw_values[6], raw_values[7], raw_values[8], raw_values[9], raw_values[10]);
Serial.print(str);
Serial.print('\n');
}
}
else if(cmd=='g') {
uint8_t count = serial_busy_wait();
for(uint8_t i=0; i<count; i++) {
my3IMU.getQ(q);
my3IMU.getValues(values);
float acc[3];
acc[0] = values[0];
acc[1] = values[1];
acc[2] = values[2];
my3IMU.gravityCompensateAcc(acc, q);
sprintf(str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,", &acc[0], &acc[1], &acc[2], &values[3], &values[4], &values[5], &values[6], &values[7], &values[8], &values[9], &values[10]);
Serial.print(str);
Serial.print('\n');
}
}
我收到的错误是:
FreeIMU_serial_edit1.cpp.o: In function `loop':
/Applications/FreeIMU_serial_edit1.ino:70: undefined reference to `FreeIMU::gravityCompensateAcc(float*, float*)'
有问题的函数在FreeIMU.cpp中定义:
/**
* Compensates the accelerometer readings in the 3D vector acc expressed in the sensor frame for gravity
* @param acc the accelerometer readings to compensate for gravity
* @param q the quaternion orientation of the sensor board with respect to the world
*/
void FreeIMU::gravityCompensateAcc(float * acc, float * q) {
float g[3];
// get expected direction of gravity in the sensor frame
g[0] = 2 * (q[1] * q[3] - q[0] * q[2]);
g[1] = 2 * (q[0] * q[1] + q[2] * q[3]);
g[2] = q[0] * q[0] - q[1] * q[1] - q[2] * q[2] + q[3] * q[3];
// compensate accelerometer readings with the expected direction of gravity
acc[0] = acc[0] - g[0];
acc[1] = acc[1] - g[1];
acc[2] = acc[2] - g[2];
}
C ++对象my3IMU中的其他函数,例如my3IMU.getQ,工作正常;我不明白为什么编译器报告gravityCompensateAcc是未定义的。非常感谢任何帮助,谢谢!
答案 0 :(得分:0)
我刚遇到同样的问题。
答案很简单,函数定义在#if语句中,更准确地说是{5}左右的#if HAS_MS5611()
。
将它移到#if...#endif
语句之外,它会起作用。