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

Implement NavHpPosEcef message and PositionECEF #74

Merged
merged 8 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ublox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "MIT"
name = "ublox"
readme = "../README.md"
repository = "https://github.com/lkolbly/ublox"
version = "0.4.4"
version = "0.4.5"

[features]
alloc = []
Expand Down
61 changes: 61 additions & 0 deletions ublox/src/ubx_packets/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,66 @@ struct NavHpPosLlh {
vertical_accuracy: u32,
}

#[ubx_extend_bitflags]
#[ubx(from, into_raw, rest_reserved)]
bitflags! {
#[derive(Default, Debug)]
pub struct NavHpPosEcefFlags: u8 {
const INVALID_ECEF = 1;

}
}

/// High Precision Geodetic Position Solution (ECEF)
#[ubx_packet_recv]
#[ubx(class = 0x01, id = 0x13, fixed_payload_len = 28)]
struct NavHpPosEcef {
/// Message version (0 for protocol version 27)
version: u8,

reserved1: [u8; 3],

/// GPS Millisecond Time of Week
itow: u32,

/// ECEF X coordinate
#[ubx(map_type = f64, alias = ecef_x_cm)]
ecef_x: i32,

/// ECEF Y coordinate
#[ubx(map_type = f64, alias = ecef_y_cm)]
ecef_y: i32,

/// ECEF Z coordinate
#[ubx(map_type = f64, alias = ecef_z_cm)]
ecef_z: i32,

/// High precision component of X
/// Must be in the range -99..+99
/// Precise coordinate in cm = ecef_x + (ecef_x_hp * 1e-2).
#[ubx(map_type = f64, scale = 1e-1, alias = ecef_x_hp_mm)]
ecef_x_hp: i8,

/// High precision component of Y
/// Must be in the range -99..+99
/// 9. Precise coordinate in cm = ecef_y + (ecef_y_hp * 1e-2).
#[ubx(map_type = f64, scale = 1e-1, alias = ecef_y_hp_mm)]
ecef_y_hp: i8,

/// High precision component of Z
/// Must be in the range -99..+99
/// Precise coordinate in cm = ecef_z + (ecef_z_hp * 1e-2).
#[ubx(map_type = f64, scale = 1e-1, alias = ecef_z_hp_mm)]
ecef_z_hp: i8,

#[ubx(map_type = NavHpPosEcefFlags)]
flags: u8,

/// Horizontal accuracy estimate (mm)
#[ubx(map_type = f64, scale = 1e-1)]
p_acc: u32,
}

/// Navigation Position Velocity Time Solution
#[ubx_packet_recv]
#[ubx(class = 1, id = 0x07, fixed_payload_len = 92)]
Expand Down Expand Up @@ -3606,6 +3666,7 @@ define_recv_packets!(
NavSolution,
NavVelNed,
NavHpPosLlh,
NavHpPosEcef,
NavTimeUTC,
NavTimeLs,
NavSat,
Expand Down
26 changes: 26 additions & 0 deletions ublox/src/ubx_packets/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ pub struct Position {
pub alt: f64,
}

/// Represents a world position in the ECEF coordinate system
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy)]
pub struct PositionECEF {
/// Logitude in degrees
pub x: f64,
LarsJaeger marked this conversation as resolved.
Show resolved Hide resolved

/// Latitude in degrees
LarsJaeger marked this conversation as resolved.
Show resolved Hide resolved
pub y: f64,

/// Altitude in meters
LarsJaeger marked this conversation as resolved.
Show resolved Hide resolved
pub z: f64,
}


#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Velocity {
Expand Down Expand Up @@ -47,6 +62,17 @@ impl<'a> From<&NavHpPosLlhRef<'a>> for Position {
}
}

impl<'a> From<&NavHpPosEcefRef<'a>> for PositionECEF {
fn from(packet: &NavHpPosEcefRef<'a>) -> Self {
PositionECEF {
x: 10e-2 * (packet.ecef_x_cm() + 0.1 * packet.ecef_x_hp_mm()),
y: 10e-2 * (packet.ecef_y_cm() + 0.1 * packet.ecef_y_hp_mm()),
z: 10e-2 * (packet.ecef_z_cm() + 0.1 * packet.ecef_z_hp_mm()),
}
}
}


impl<'a> From<&NavVelNedRef<'a>> for Velocity {
fn from(packet: &NavVelNedRef<'a>) -> Self {
Velocity {
Expand Down
Loading