Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nan #1

Open
maciekish opened this issue Jan 19, 2015 · 4 comments
Open

nan #1

maciekish opened this issue Jan 19, 2015 · 4 comments

Comments

@maciekish
Copy link

Hi,
I'm trying to implement this in my custom location manger on iOS but get_lat_long get_bearing and get_mph all just return nan.

I'm creating the filter like this:

self.kalmanFilter = alloc_filter_velocity2d(self.noise); //Noise is 1.0f

Updating it like this:

update_velocity2d(self.kalmanFilter, location.coordinate.latitude, location.coordinate.longitude, timeIntervalSinceUpdate); //Where timeIntervalSinceUpdate is an NSTimeInterval since the last CLLocation

And reading it like this:

CLLocationDegrees lat, lon;
get_lat_long(self.kalmanFilter, &lat, &lon);
CLLocationDirection bearing = get_bearing(self.kalmanFilter);
CLLocationSpeed speed = get_mph(self.kalmanFilter) * 0.44704f; //Convert mph to meters per second
NSLog(@"%.1f %.1f %1.f %1.f", lat, lon, speed, bearing);

All i get is "nan nan nan nan"

@maciekish
Copy link
Author

Turns out this is the culprit:

NSTimeInterval timeIntervalSinceUpdate = [location.timestamp timeIntervalSinceDate:self.lastRawLocation.timestamp];

if (!self.lastRawLocation || timeIntervalSinceUpdate > 0) {
    update_velocity2d(_kalmanFilter, location.coordinate.latitude, location.coordinate.longitude, timeIntervalSinceUpdate);

    self.lastRawLocation = location;
}

If i replace timeIntervalSinceUpdate in update_velocity2d with 1 it start working. What does this parameter do and does it really need to be seconds since last update? What happens if i leave it at 1?

@resqrobert
Copy link

@maciekish, any luck with this issue?

@PierrotLL
Copy link

Hi, I just used this code (transposed in AS3) and it works very well. Many thanks to the author.

Make sure your values (latitude, longitude, elapsed time) aren't NaN when you update the filter.

I know the guys above will probably never see this answer, but it's more for future viewers.

@GeneralJing
Copy link

@PierrotLL can you supply some test examples? I met the same question. below is my code:
// KalmanFilter f = alloc_filter(2, 1);
KalmanFilter f = alloc_filter(7, 4);

/* The train state is a 2d vector containing position and velocity.
    Velocity is measured in position units per timestep units. */

// set_matrix(f.state_transition,
// 1.0, 1.0,
// 0.0, 1.0);
set_matrix(f.state_transition,
1, 0, 0, 0, 1, 0, 0,
0, 1, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0, 1,
0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants