Struct openpilot::common::ext_kal_fltr::GPS
source · pub struct GPS {
pub earth_r: f64,
pub obs_model: Array2<f64>,
pub covar: Array2<f64>,
pub init_lat: f64,
pub init_lon: f64,
}
Expand description
Represents a GPS sensor with specific parameters.
Fields§
§earth_r: f64
Earth radius constant for distance calculations.
obs_model: Array2<f64>
Observation model matrix for the GPS sensor.
covar: Array2<f64>
Covariance matrix for the GPS sensor.
init_lat: f64
Initial latitude for position calculations.
init_lon: f64
Initial longitude for position calculations.
Implementations§
source§impl GPS
impl GPS
sourcepub fn new(xy_idx: (usize, usize), dims: usize, var: f64) -> Self
pub fn new(xy_idx: (usize, usize), dims: usize, var: f64) -> Self
Creates a new GPS
instance with specified parameters.
§Arguments
xy_idx
- Tuple representing the indices of X and Y coordinates in the observation model matrix.dims
- Number of dimensions for the observation model.var
- Variance for the covariance matrix.
§Returns
(GPS
): A new GPS
instance.
§Examples
use openpilot::common::ext_kal_fltr::GPS;
let xy_idx = (0, 1);
let dims = 2;
let var = 1e4;
let gps = GPS::new(xy_idx, dims, var);
sourcepub fn _haversine(&self, lat1: f64, lon1: f64, lat2: f64, lon2: f64) -> f64
pub fn _haversine(&self, lat1: f64, lon1: f64, lat2: f64, lon2: f64) -> f64
Calculates the Haversine distance between two points on the Earth’s surface.
§Arguments
lat1
- Latitude of the first point.lon1
- Longitude of the first point.lat2
- Latitude of the second point.lon2
- Longitude of the second point.
§Returns
(f64
): Haversine distance between the two points.
§Examples
use openpilot::common::ext_kal_fltr::GPS;
let gps = GPS::new((0, 1), 2, 1e4);
let distance = gps._haversine(37.7749, -122.4194, 38.0000, -121.0000);
sourcepub fn convert_deg2m(&self, lat: f64, lon: f64) -> (f64, f64)
pub fn convert_deg2m(&self, lat: f64, lon: f64) -> (f64, f64)
Converts latitude and longitude coordinates to meters.
§Arguments
lat
- Latitude coordinate.lon
- Longitude coordinate.
§Returns
((f64, f64)
): Tuple containing converted X and Y coordinates in meters.
§Examples
use openpilot::common::ext_kal_fltr::GPS;
let gps = GPS::new((0, 1), 2, 1e4);
let (xs, ys) = gps.convert_deg2m(37.7749, -122.4194);
sourcepub fn _convert_m2deg(&self, xs: f64, ys: f64) -> (f64, f64)
pub fn _convert_m2deg(&self, xs: f64, ys: f64) -> (f64, f64)
Converts X and Y coordinates in meters to latitude and longitude coordinates.
§Arguments
xs
- X coordinate in meters.ys
- Y coordinate in meters.
§Returns
((f64, f64)
): Tuple containing converted latitude and longitude coordinates.
§Examples
use openpilot::common::ext_kal_fltr::GPS;
let gps = GPS::new((0, 1), 2, 1e4);
let (lat, lon) = gps._convert_m2deg(100.0, 200.0);
sourcepub fn read(&self, latlon: &[f64], accuracy: Option<f64>) -> SensorReading
pub fn read(&self, latlon: &[f64], accuracy: Option<f64>) -> SensorReading
Reads GPS data and returns a SensorReading
instance.
§Arguments
latlon
- Array containing latitude and longitude values.accuracy
- Optional accuracy value. If not provided, the default covariance of the sensor is used.
§Returns
(SensorReading
): A new SensorReading
instance based on GPS data and covariance.
§Examples
use openpilot::common::ext_kal_fltr::GPS;
let mut gps = GPS::new((0, 1), 2, 1e4);
gps.init_pos(&[37.7749, -122.4194]);
let sensor_reading = gps.read(&[37.7749, -122.4194], Some(10.0));