LoginSignup
4
3

More than 5 years have passed since last update.

gpsdでGPSモジュールの測定周期を10Hzに変更する

Last updated at Posted at 2017-03-21

GPS10Hz化計画ですが、gpsdの起動後にgpsctlで10Hz化することに成功しました。
gpsdのソース書き換えと再コンパイルが必要になります。

まずgitでソースを取ってきます。aptを使った方法は前回の記事@mt08さんのコメントを御覧ください。(@mt08さんありがとうございました)

$ git clone https://git.savannah.gnu.org/git/gpsd.git

drivers.cを書き換えます。ifdef部分のコードを変更しています。

drivers.c
static bool mtk3301_rate_switcher(struct gps_device_t *session, double rate)
{
    char buf[78];

    unsigned int milliseconds = (unsigned int)(1000 * rate);
    if (rate > 1)
    milliseconds = 1000;

#ifdef MTK3339_ENABLE
    else if (rate < 0.1)
       milliseconds = 100;
#else
    else if (rate < 0.2)
    milliseconds = 200;
#endif /* MTK3339_ENABLE */

    (void)snprintf(buf, sizeof(buf), "$PMTK300,%u,0,0,0,0", milliseconds);
    (void)nmea_send(session, buf);  /* Fix interval */
    return true;
}

もう一箇所

drivers.c
const struct gps_type_t driver_mtk3301 = {
.
.
.
#ifdef MTK3339_ENABLE
    .min_cycle      = 0.1,      /* max 10Hz */
#else
    .min_cycle      = 0.2,      /* max 5Hz */
#endif /* MTK3339_ENABLE */
.
.
.

SConstructのMTK3301の下辺りにMTK3339を追加します。

SConstruct
.
.
.
     ("itrax",         True,  "iTrax hardware support"),
     ("mtk3301",       True,  "MTK-3301 support"),
     ("mtk3339",       True,  "MTK-3339 support"),
     ("navcom",        True,  "Navcom NCT support"),
.
.
.

コンパイルします。

$ scons

「systemctl stop gpsd」した後、作ったgpsdを元のgpsdコマンドと置き換え、「systemctl start gpsd」します。その後、

$ gpsctl -c 0.1

で10Hzで動かすことができました。

余談
調べていると、「GPSなんて5Hzもあれば十分」のような議論(?)が所々で見られました。物理、数学的に5Hz以上は意味が無いのでしょうか?
そうでなければ今後GPSが高精度化するに従って、10Hzどころか100Hz~の需要も出てくると思うのですが。
2018年には次世代GPS(GPSという名前が受け継がれるか不明)が運用開始され、位置情報誤差が数cmとなるようなので、使い方が広がりますね。

4
3
1

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
4
3