This project was created because of an earlier one, a magnetic self-balancing platform used to demonstrate the principles of Maglev control. I then wanted to add a Kalman filter, which uses both accelerator and gyroscope data at once to correct the imperfections in the gyroscope, which would otherwise result in drift, especially over long periods of time.
An easier option is to add calibration that assumes the gyroscope is not moving; however, it doesn't work as well. When I have runned the code it is showing below error. I don't know how to solve the problem kindly help me to solve the problem.
#include<Wire.h>
#define gyro_address 0x68
int16_t accel_x, accel_y, accel_z, temp, gyro_x, gyro_y, gyro_z;
array gyro_data = []; //this stores the past data from the sensor, giving the kalman filter some of its neccasary data.
array accel_data = []; //this stores the past data from the sensor, giving the kalman filter some of its neccasary data.
array gyro_current = []; //this feeds into the main variable, but it's here just to better orginize the X, Y. & Z values.
array accel_current = []; //this feeds into the main variable, but it's here just to better orginize the X, Y. & Z values.
void setup() {
Wire.begin();
Wire.beginTransmission(gyro_address);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true); //set this to false, and it doesn't end. simple enough, right?
Wire.beginTransmission(gyro_address);
Wire.write(0x6a);
Wire.requestFrom(gyro_address, 1, true);
int usercontrol = Wire.read();
Wire.endTransmission(true);
Serial.begin(9600);
double x_rotation = 0, y_rotation = 0, z_rotation = 0;
}
void loop() {
Wire.beginTransmission(gyro_address);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H).this number may change depending on how the gyroscope transferrs data.
Wire.endTransmission(false);
Wire.requestFrom(gyro_address, 14, true); // request a total of 14 registers (again, it may be different for your gyroscope)
accel_x = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
accel_y = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
accel_z = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
temp = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
gyro_x = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
gyro_y = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
gyro_z = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
accel_current = [accel_x,accel_y,accel_z];
gyro_current = [gyro_x,gyro_y,gyro_z];
Serial.print(" | Accelerometer X:");
Serial.print(accel_x);
Serial.print(" | Accelerometer Y:");
Serial.print(accel_y);
Serial.print(" | Accelerometer Z:");
Serial.print(accel_z);
Serial.print(" | Temperature:");
Serial.print(temp / 340.00 + 36.53);
Serial.print(" | Gyro X:");
Serial.print(gyro_x);
Serial.print(" | Gyro Y:");
Serial.print(gyro_y);
Serial.print(" | Gyro Z:");
Serial.println(gyro_z);
gyro_data[gyro_data.length()] = gyro_current;
accel_data[accel_data.length()] = accel_current;
delay(100);//this is important to make sure the board and arduino both aren't overloading. slower-operating gyros may need a bigger number.
}
Error displayed
sketch_mar30b:26: error: storage size of 'array' isn't known
int array [];
^
sketch_mar30b:28: error: 'array' does not name a type
array gyro_data = []; //this stores the past data from the sensor, giving the kalman filter some of its neccasary data.
^
sketch_mar30b:29: error: 'array' does not name a type
array accel_data = []; //this stores the past data from the sensor, giving the kalman filter some of its neccasary data.
^
sketch_mar30b:30: error: 'array' does not name a type
array gyro_current = []; //this feeds into the main variable, but it's here just to better orginize the X, Y. & Z values.
^
sketch_mar30b:31: error: 'array' does not name a type
array accel_current = []; //this feeds into the main variable, but it's here just to better orginize the X, Y. & Z values.
^
C:\Users\deb\AppData\Local\Temp\arduino_modified_sketch_610669\sketch_mar30b.ino: In function 'void loop()':
sketch_mar30b:69: error: 'accel_current' was not declared in this scope
accel_current = [accel_x,accel_y,accel_z];
^
C:\Users\deb\AppData\Local\Temp\arduino_modified_sketch_610669\sketch_mar30b.ino:19:9: note: 'int16_t accel_x' declared here
int16_t accel_x, accel_y, accel_z, temp, gyro_x, gyro_y, gyro_z;
^
C:\Users\deb\AppData\Local\Temp\arduino_modified_sketch_610669\sketch_mar30b.ino:19:18: note: 'int16_t accel_y' declared here
int16_t accel_x, accel_y, accel_z, temp, gyro_x, gyro_y, gyro_z;
^
C:\Users\deb\AppData\Local\Temp\arduino_modified_sketch_610669\sketch_mar30b.ino:19:27: note: 'int16_t accel_z' declared here
int16_t accel_x, accel_y, accel_z, temp, gyro_x, gyro_y, gyro_z;
^
C:\Users\deb\AppData\Local\Temp\arduino_modified_sketch_610669\sketch_mar30b.ino: In lambda function:
sketch_mar30b:69: error: expected '{' before ';' token
accel_current = [accel_x,accel_y,accel_z];
^
C:\Users\deb\AppData\Local\Temp\arduino_modified_sketch_610669\sketch_mar30b.ino: In function 'void loop()':
sketch_mar30b:70: error: 'gyro_current' was not declared in this scope
gyro_current = [gyro_x,gyro_y,gyro_z];
^
C:\Users\deb\AppData\Local\Temp\arduino_modified_sketch_610669\sketch_mar30b.ino:19:42: note: 'int16_t gyro_x' declared here
int16_t accel_x, accel_y, accel_z, temp, gyro_x, gyro_y, gyro_z;
^
C:\Users\deb\AppData\Local\Temp\arduino_modified_sketch_610669\sketch_mar30b.ino:19:50: note: 'int16_t gyro_y' declared here
int16_t accel_x, accel_y, accel_z, temp, gyro_x, gyro_y, gyro_z;
^
C:\Users\deb\AppData\Local\Temp\arduino_modified_sketch_610669\sketch_mar30b.ino:19:58: note: 'int16_t gyro_z' declared here
int16_t accel_x, accel_y, accel_z, temp, gyro_x, gyro_y, gyro_z;
^
C:\Users\deb\AppData\Local\Temp\arduino_modified_sketch_610669\sketch_mar30b.ino: In lambda function:
sketch_mar30b:70: error: expected '{' before ';' token
gyro_current = [gyro_x,gyro_y,gyro_z];
^
C:\Users\deb\AppData\Local\Temp\arduino_modified_sketch_610669\sketch_mar30b.ino: In function 'void loop()':
sketch_mar30b:85: error: 'gyro_data' was not declared in this scope
gyro_data[gyro_data.length()] = gyro_current;
^
sketch_mar30b:86: error: 'accel_data' was not declared in this scope
accel_data[accel_data.length()] = accel_current;
^
Multiple libraries were found for "Wire.h"
Used: C:\Users\deb\AppData\Local\Arduino15\packages\Intel\hardware\i686\1.6.7+1.0\libraries\Wire
Not used: C:\Users\deb\AppData\Local\Arduino15\packages\Intel\hardware\i686\1.6.7+1.0\libraries\Servo
Not used: C:\Program Files (x86)\Arduino\libraries\Wire
Using library Wire at version 1.0 in folder: C:\Users\deb\AppData\Local\Arduino15\packages\Intel\hardware\i686\1.6.7+1.0\libraries\Wire
exit status 1
storage size of 'array' isn't known[color=red][/color]