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 135cb2f..4075d9d 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 = None + self.pitch = None + self.roll = None @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'] 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 def position(self): @@ -228,6 +242,39 @@ def get_time(self, local_time=False): return time + def heading(self): + """ 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 + """ + return self.heading + + 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 + + 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 + def __repr__(self): modes = { 0: 'No mode',