PVector addition resulting in a NAN result ... can't figure out why.
in
Programming Questions
•
2 years ago
Hi Folks,
I've been trying to figure this out for a few hours and have hit a wall.
I'm trying to update drawing position based on some data from a 6DOM accelerometer/gyro combo.
I've got some code that combines the accelerometer and gyro data (using a Kalman filter) into a the best estimated acceleration vector.
I'm then simply trying to add that vector to a velocity vector and then add that to a position vector.
But when I try to add the incoming acceleration vector to the velocity vector I get NaNs across the board.
Here is the relevant code:
- float [] RwEst = new float[3];
- //RwEst is the acceleration vector produced by the kalman filter
- PVector location;
- PVector velocity;
- PVector accelertaion;
- void setup()
- {
- size(VIEW_SIZE_X, VIEW_SIZE_Y, P3D);
- smooth();
- location = new PVector(width/2, height/2,0);
- velocity = new PVector(0.0, 0,0);
- accelertaion = new PVector(0.0, 0.0,0);
- }
-
void draw() {getInclination();update();ellipse(location.x, location.y, 10, 10);}
- void update() {
- //RwEst is the acceleration vector produced by the kalman filter
- println("RwEst= "+RwEst[0]+" "+RwEst[1]+" "+RwEst[2]+" " );
- accelertaion.set(RwEst);
- println("acc= "+accelertaion);
- velocity.add(accelertaion);
- println("velo= "+velocity);
- location.add(velocity);
- println("location= "+location);
- println(" " );
- }
Here is a sample of the output:
RwEst= -0.80083185 0.2533032 -9.964663
acc= [ -0.80083185, 0.2533032, -9.964663 ]
velo= [ NaN, NaN, NaN ]
location= [ NaN, NaN, NaN ]
RwEst= -0.8005298 0.25594395 -9.96462
acc= [ -0.8005298, 0.25594395, -9.96462 ]
velo= [ NaN, NaN, NaN ]
location= [ NaN, NaN, NaN ]
Any thoughts would be great.
Thanks!
1