From 832cf74ef3ad74d9f6f6c68190972853a89d1d29 Mon Sep 17 00:00:00 2001 From: Glen Cornell Date: Sat, 18 Jun 2022 23:32:21 -0400 Subject: [PATCH 1/3] added support for ATT gpsd object --- gpsd/__init__.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/gpsd/__init__.py b/gpsd/__init__.py index 135cb2f..51cf4e0 100644 --- a/gpsd/__init__.py +++ b/gpsd/__init__.py @@ -44,6 +44,9 @@ class GpsResponse(object): :type climb: float :type time: str :type error: dict[str, float] + :type heading: float + :type pitch: float + :type roll: float :var self.mode: Indicates the status of the GPS reception, 0=No value, 1=No fix, 2=2D fix, 3=3D fix :var self.sats: The number of satellites received by the GPS unit @@ -56,6 +59,9 @@ class GpsResponse(object): :var self.climb: Climb (positive) or sink (negative) rate, meters per second :var self.time: Time/date stamp in ISO8601 format, UTC. May have a fractional part of up to .001sec precision. :var self.error: GPSD error margin information + :var self.heading: heading, degrees from true north. + :var self.pitch: pitch in degrees. + :var self.roll: roll in degrees. GPSD error margin information ----------------------------- @@ -83,6 +89,9 @@ def __init__(self): self.climb = 0 self.time = '' self.error = {} + self.heading = 0.0 + self.pitch = 0.0 + self.roll = 0.0 @classmethod def from_json(cls, packet): @@ -96,6 +105,7 @@ def from_json(cls, packet): raise UserWarning('GPS not active') last_tpv = packet['tpv'][-1] last_sky = packet['sky'][-1] + last_att = packet['att'][-1] if 'satellites' in last_sky: result.sats = len(last_sky['satellites']) @@ -128,6 +138,10 @@ def from_json(cls, packet): result.error['c'] = last_tpv['epc'] if 'epc' in last_tpv else 0 result.error['v'] = last_tpv['epv'] if 'epv' in last_tpv else 0 + result.heading = last_att['heading'] + result.pitch = last_att['pitch'] + result.roll = last_att['roll'] + return result def position(self): @@ -228,6 +242,27 @@ def get_time(self, local_time=False): return time + def heading(self): + """ Get the heading in degrees from true north. + + :return: float + """ + return self.heading + + def pitch(self): + """ Get the pitch in degrees. + + :return: float + """ + return self.pitch + + def roll(self): + """ Get the roll in degrees. + + :return: float + """ + return self.roll + def __repr__(self): modes = { 0: 'No mode', From 4a7e4d3951c71010bd0ce8becba899428a8ed6f6 Mon Sep 17 00:00:00 2001 From: Glen Cornell Date: Sun, 19 Jun 2022 00:37:34 -0400 Subject: [PATCH 2/3] adding error checking --- gpsd/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gpsd/__init__.py b/gpsd/__init__.py index 51cf4e0..e03e1af 100644 --- a/gpsd/__init__.py +++ b/gpsd/__init__.py @@ -138,9 +138,9 @@ def from_json(cls, packet): result.error['c'] = last_tpv['epc'] if 'epc' in last_tpv else 0 result.error['v'] = last_tpv['epv'] if 'epv' in last_tpv else 0 - result.heading = last_att['heading'] - result.pitch = last_att['pitch'] - result.roll = last_att['roll'] + result.heading = last_att['heading'] if 'heading' in last_att else 0.0 + result.pitch = last_att['pitch'] if 'pitch' in last_att else 0.0 + result.roll = last_att['roll'] if 'roll' in last_att else 0.0 return result From 667271a5d7cc41e6111e0306972f2ba2286f3836 Mon Sep 17 00:00:00 2001 From: Glen Cornell Date: Wed, 7 Dec 2022 10:29:58 -0500 Subject: [PATCH 3/3] When no attitude is available, return None --- DOCS.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++- gpsd/__init__.py | 26 ++++++++++++++++------ 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/DOCS.md b/DOCS.md index 0edf2fa..ad72306 100644 --- a/DOCS.md +++ b/DOCS.md @@ -55,6 +55,18 @@ Description and information copied from [http://catb.org/gpsd/gpsd_json.html](ht - *Description:* Climb (positive) or sink (negative) rate, meters per second - *Availability:* mode >= 3 - *Data Type:* float +- **heading** + - *Description:* Heading, degrees from true north + - *Availability:* Always *(**NOTE:** None if attitude is unavailable)* + - *Data Type:* float +- **pitch** + - *Description:* Pitch, degrees + - *Availability:* Always *(**NOTE:** None if attitude is unavailable)* + - *Data Type:* float +- **roll** + - *Description:* Roll, degrees + - *Availability:* Always *(**NOTE:** None if attitude is unavailable)* + - *Data Type:* float ### Methods ### - **position** @@ -107,7 +119,21 @@ Description and information copied from [http://catb.org/gpsd/gpsd_json.html](ht - *Availability:* mode >= 3 - *Parameters:* None - *Return Type:* float - +- **heading** + - *Description:* Heading, degrees from true north + - *Availability:* Always *(**NOTE:** None if attitude is unavailable)* + - *Parameters:* None + - *Data Type:* float +- **pitch** + - *Description:* Pitch, degrees + - *Availability:* Always *(**NOTE:** None if attitude is unavailable)* + - *Parameters:* None + - *Data Type:* float +- **roll** + - *Description:* Roll, degrees + - *Availability:* Always *(**NOTE:** None if attitude is unavailable)* + - *Parameters:* None + - *Data Type:* float Exception Information ----- @@ -184,6 +210,21 @@ else: print(" Altitude: NOT AVAILABLE") print(" Climb: NOT AVAILABLE") +if (packet.heading is not None): +print(" Heading: " + str(packet.heading)) +else: +print(" Heading: NOT AVAILABLE") + +if (packet.pitch is not None): +print(" Pitch: " + str(packet.pitch)) +else: +print(" Pitch: NOT AVAILABLE") + +if (packet.roll is not None): +print(" Roll: " + str(packet.roll)) +else: +print(" Roll: NOT AVAILABLE") + print(" ************** METHODS ************** ") if packet.mode >= 2: print(" Location: " + str(packet.position())) @@ -209,6 +250,21 @@ print(" Altitude: NOT AVAILABLE") # print(" Movement: NOT AVAILABLE") # print(" Speed Vertical: NOT AVAILABLE") +if (packet.heading is not None): +print(" Heading: " + str(packet.heading())) +else: +print(" Heading: NOT AVAILABLE") + +if (packet.pitch is not None): +print(" Pitch: " + str(packet.pitch())) +else: +print(" Pitch: NOT AVAILABLE") + +if (packet.roll is not None): +print(" Roll: " + str(packet.roll())) +else: +print(" Roll: NOT AVAILABLE") + print(" ************* FUNCTIONS ************* ") print("Device: " + str(gpsd.device())) ``` diff --git a/gpsd/__init__.py b/gpsd/__init__.py index e03e1af..4075d9d 100644 --- a/gpsd/__init__.py +++ b/gpsd/__init__.py @@ -89,9 +89,9 @@ def __init__(self): self.climb = 0 self.time = '' self.error = {} - self.heading = 0.0 - self.pitch = 0.0 - self.roll = 0.0 + self.heading = None + self.pitch = None + self.roll = None @classmethod def from_json(cls, packet): @@ -138,9 +138,9 @@ def from_json(cls, packet): result.error['c'] = last_tpv['epc'] if 'epc' in last_tpv else 0 result.error['v'] = last_tpv['epv'] if 'epv' in last_tpv else 0 - result.heading = last_att['heading'] if 'heading' in last_att else 0.0 - result.pitch = last_att['pitch'] if 'pitch' in last_att else 0.0 - result.roll = last_att['roll'] if 'roll' in last_att else 0.0 + result.heading = last_att['heading'] if 'heading' in last_att else None + result.pitch = last_att['pitch'] if 'pitch' in last_att else None + result.roll = last_att['roll'] if 'roll' in last_att else None return result @@ -243,7 +243,11 @@ def get_time(self, local_time=False): return time def heading(self): - """ Get the heading in degrees from true north. + """ Get the heading in degrees from true north. + + GPSD provides vehicle attitude reports for selective gyroscope + and digital compass sensors. If the sensor does not support + vehicle attitude reports, then this method will return None. :return: float """ @@ -252,6 +256,10 @@ def heading(self): def pitch(self): """ Get the pitch in degrees. + GPSD provides vehicle attitude reports for selective gyroscope + and digital compass sensors. If the sensor does not support + vehicle attitude reports, then this method will return None. + :return: float """ return self.pitch @@ -259,6 +267,10 @@ def pitch(self): def roll(self): """ Get the roll in degrees. + GPSD provides vehicle attitude reports for selective gyroscope + and digital compass sensors. If the sensor does not support + vehicle attitude reports, then this method will return None. + :return: float """ return self.roll