1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Raspberry Pi PicoでGPSを解析! 応用

Posted at

前回の続き

環境

Raspberry Pi Pico 2
pygps2 ライブラリ

リポジトリ

目的

備忘録

  • 自分のライブラリの詳細のため
  • 詳細なところなどなど

モジュールとの接続

無題のプレゼンテーション.jpg

プログラム

main.py
from machine import UART, Pin
import pygps2
import time
gps = UART(0, baudrate=115200, tx=Pin(0), rx=Pin(1))
while True:
    raw = gps.read(8192)
    if raw is not None:
        try:
            raw = raw.replace(b'\r', b'').replace(b'\n', b'')
            raw = raw.replace(b'/', b'')
            data = raw.decode("utf-8", "ignore")
        except Exception as e:
            print(f"error: {e}")
            print(raw)
            continue
        sentences = data.split('$')
        sentences = ['$' + sentence for sentence in sentences if sentence]
        data = '\r\n'.join(sentences) + '\r\n'
        parsed_data = pygps2.parse_nmea_sentences(data)
        analyzed_data = pygps2.analyze_nmea_data(parsed_data)
        print(analyzed_data)
    time.sleep(0.01)

ここまでは前回と同じ
ここから前回とは別の話題

データの型について

analyze_dataを処理するための参考 pygps2はいろいろなデータ型で値を返す。

analyzed_dataは上記のプログラムで返したデータ

GGA

データ

[{'timestamp': '220927.00', 'latitude': '0.0', 'longitude': '0.0', 'gps_quality': '1', 'num_satellites': '12', 'hdop': '2.2', 'altitude': '40.01', 'altitude_units': 'M', 'geoid_height': '36.37', 'geoid_units': 'M', 'dgps_age': '', 'dgps_station_id': ''}]

構成

analyzed_data["GGA"][0] ここに各データがある。
アクセスしたいデータにアクセスするには["GGA"][0]["timestamp"]のように指定する。

Type

  • timestamp str型
  • latitude str型(float型に戻して演算を行うと丸め処理により不正確な値になる。)
  • longitude str型(上と同じく)
  • gps_quality str型
  • num_satellites str型
  • hdop str型
  • altitude str型
  • altitude_units str型
  • geoid_height str型
  • geoid_units str型
  • dgps_age str型
  • dgps_station_id str型

GLL

データ

[{'latitude': '0.0', 'longitude': '0.0', 'timestamp': '220927.00', 'status': 'A', 'mode_indicator': 'A'}]

構成

analyzed_data["GLL"][0] ここに各データがある。

Type

  • latitude str型(float型に戻して演算を行うと丸め処理により不正確な値になる。)
  • longitude str型(上と同じく)
  • timestamp str型
  • status str型
  • mode_indicator str型

RMC

データ

[{'timestamp': '220927.00', 'status': 'A', 'latitude': '0.0', 'longitude': '0.0', 'speed_over_ground': '0.29', 'course_over_ground': '0.0', 'date': '200325', 'magnetic_variation': '0.0', 'mag_var_direction': '', 'mode_indicator': 'A', 'utc_datetime': '2025-03-20 22:09:27', 'local_datetime': '2025-03-21 07:09:27'}]

構成

analyzed_data["RMC"][0] ここに各データがある。

Type

  • timestamp str型
  • status str型
  • latitude str型(float型に戻して演算を行うと丸め処理により不正確な値になる。)
  • longitude str型(上と同じく)
  • speed_over_ground str型
  • course_over_ground str型
  • date str型(生データで解析されていない)

VTG

データ

[{'course_over_ground_t': '0.0', 'reference_t': 'T', 'course_over_ground_m': '0.0', 'reference_m': 'M', 'speed_knots': '0.29', 'units_knots': 'N', 'speed_kmh': '0.53', 'units_kmh': 'K', 'mode_indicator': 'A'}]

構成

analyzed_data["VTG"][0] ここに各データがある。

Type

  • course_over_ground_t str型
  • reference_t str型
  • course_over_ground_m str型
  • reference_m str型
  • speed_knots str型
  • units_knots str型
  • speed_kmh str型
  • units_kmh str型
  • mode_indicator str型

GST

データ

[{'timestamp': '220927.00', 'rms': '2.6', 'std_lat': '5.8', 'std_lon': '5.9', 'std_alt': '6.0'}]

構成

analyzed_data["GST"][0] ここに各データがある。

Type

  • timestamp str型
  • rms str型
  • std_lat str型
  • std_lon str型
  • std_alt str型

DHV

データ

[{'timestamp': '220927.00', '3d_speed': '0.60', 'ecef_x_speed': '0.466', 'ecef_y_speed': '-0.272', 'ecef_z_speed': '-0.264', 'horizontal_ground_speed': None}]

構成

analyzed_data["DHV"][0] ここに各データがある。

Type

  • timestamp str型
  • 3d_speed str型
  • ecef_x_speed str型
  • ecef_y_speed str型
  • ecef_z_speed str型
  • horizontal_ground_speed str型 か None

ZDA

データ

[{'timestamp': '220927.00', 'day': '20', 'month': '03', 'year': '2025', 'timezone_offset_hour': '00', 'timezone_offset_minute': '00'}]

構成

analyzed_data["ZDA"][0] ここに各データがある。

Type

  • timestamp str型
  • day str型
  • month str型
  • year str型
  • timezone_offset_hour str型
  • timezone_offset_minute str型

TXT

データ 複数にわたって出力

[{'several_lines': '01', 'free': '01', 'type': '02', 'text': None}, {'several_lines': '01', 'free': '01', 'type': '01', 'text': 'ANTENNA OPEN'}, {'several_lines': '01', 'free': '01', 'type': '02', 'text': None}]

構成

analyzed_data["TXT"][n] ここに各データがある。 nには参照したいリストにの番号を入力する。

Type

すべてGPSモジュールによって異なるため変換は一切行わない。よってすべてstr型である。例外として存在しないデータの場合はNoneになる。

GSA

データ

[{'fix_select': 'A', 'fix_status': '3', 'satellites_used': ['25', '28', '29', '32', '87', '09', '26', '35', '40', '44', '02', '04'], 'pdop': '2.9', 'hdop': '2.2', 'vdop': '1.8'}]

構成

analyzed_data["GSA"][0] ここに各データがある。

Type

  • fix_select str型
  • fix_status str型
  • satellites_used リスト型 内部はstr型で構成
  • pdop str型
  • hdop str型
  • vdop str型

GSV

データ

[{'num_messages': '8', 'message_num': '1', 'num_satellites': '7', 'satellites_info': [{'prn': '32', 'type': 'GP', 'elevation': '33', 'azimuth': '179', 'snr': '37'}, {'prn': '87', 'type': 'GL', 'elevation': '29', 'azimuth': '058', 'snr': '30'}, {'prn': '14', 'type': 'GA', 'elevation': '0.0', 'azimuth': '0.0', 'snr': '34'}, {'prn': '44', 'type': 'BD', 'elevation': '42', 'azimuth': '117', 'snr': '33'}, {'prn': '02', 'type': 'GQ', 'elevation': '79', 'azimuth': '190', 'snr': '27'}]}]

構成

analyzed_data["GSV"][0] ここに各データがある。

Type

  • num_messages str型
  • message_num str型
  • num_satellites str型
  • satellites_info リスト型
    →辞書型のデータが入っているため、指定して取り出すには以下のようにする。nには度のデータを取り出すかを指定。返されたデータは辞書型になる。
analyzed_data["GSV"][0]["satellites_info"][n]

こちらのデータもすべてstr型(prn, type, elvevation, azimuth, snr)

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?