GPSについて

Sun SPOT についてのご質問はこちら。情報交換などにもご利用ください。

GPSについて

投稿記事by 桐蔭高校科学部 » 2010年8月03日(火) 18:07

今senioさんから頂いた資料でGPSのプログラムを書いています。
GPSモジュールは確かにデータを受信していて、エラーも出ていません。しかし、肝心のそのデータを出力することができません。

今実行しようとしているファイルには3つのプロジェクトが入っています。

①SunSpotAplicationAdapter.java
コード: 全て選択
package org.sunspotworld;

import com.sun.spot.peripheral.*;
import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.io.*;
import com.sun.spot.sensorboard.peripheral.*;
import com.sun.spot.util.*;
import javax.microedition.midlet.*;

public abstract class SunSpotApplicationAdapter extends MIDlet {
    protected ISpot spot = Spot.getInstance();
    protected ISleepManager sleepManager = spot.getSleepManager();
    protected EDemoBoard eDemo = EDemoBoard.getInstance();
    protected ITriColorLED[] leds = eDemo.getLEDs();
    protected IScalarInput[] scalarInputs = eDemo.getScalarInputs();
    protected IIOPin[] ioPins = eDemo.getIOPins();
    protected IOutputPin[] outputPins = eDemo.getOutputPins();
    protected ISwitch[] switches = eDemo.getSwitches();
    protected ITriColorLED led1 = leds[EDemoBoard.LED1];
    protected ITriColorLED led2 = leds[EDemoBoard.LED2];
    protected ITriColorLED led3 = leds[EDemoBoard.LED3];
    protected ITriColorLED led4 = leds[EDemoBoard.LED4];
    protected ITriColorLED led5 = leds[EDemoBoard.LED5];
    protected ITriColorLED led6 = leds[EDemoBoard.LED6];
    protected ITriColorLED led7 = leds[EDemoBoard.LED7];
    protected ITriColorLED led8 = leds[EDemoBoard.LED8];
    protected IScalarInput a0 = scalarInputs[EDemoBoard.A0];
    protected IScalarInput a1 = scalarInputs[EDemoBoard.A1];
    protected IScalarInput a2 = scalarInputs[EDemoBoard.A2];
    protected IScalarInput a3 = scalarInputs[EDemoBoard.A3];
    protected IScalarInput a4 = scalarInputs[EDemoBoard.A4];
    protected IScalarInput a5 = scalarInputs[EDemoBoard.A5];
    protected IIOPin d0 = ioPins[EDemoBoard.D0];
    protected IIOPin d1 = ioPins[EDemoBoard.D1];
    protected IIOPin d2 = ioPins[EDemoBoard.D2];
    protected IIOPin d3 = ioPins[EDemoBoard.D3];
    protected IIOPin d4 = ioPins[EDemoBoard.D4];
    protected IOutputPin h0 = outputPins[EDemoBoard.H0];
    protected IOutputPin h1 = outputPins[EDemoBoard.H1];
    protected IOutputPin h2 = outputPins[EDemoBoard.H2];
    protected IOutputPin h3 = outputPins[EDemoBoard.H3];
    protected ISwitch sw1 = switches[EDemoBoard.SW1];
    protected ISwitch sw2 = switches[EDemoBoard.SW2];

    protected void startApp() throws MIDletStateChangeException {
        new BootloaderListener().start(); // monitor the USB (if connected) and recognize commands from host
   
        try {
            setup();
            while (true) {
                loop();
            }
        } catch (InterruptedException ignore) {
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            cleanup();
        } catch (Exception e) {
            e.printStackTrace();
        }

        notifyDestroyed(); // cause the MIDlet to exit
    }

    protected void setup() throws Exception {
    }

    protected void loop() throws Exception {
        exitLoop();
    }

    protected void exitLoop() throws InterruptedException {
        throw new InterruptedException();
    }

    protected void cleanup() throws Exception {
    }

    protected void pauseApp() {
    }

   
    protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
        if (unconditional) {
            try {
                cleanup();
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            throw new MIDletStateChangeException();
        }
    }

    protected static void sleep(long milliseconds) {
        Utils.sleep(milliseconds);
    }
}


②SunSpotGPS.java
コード: 全て選択
package org.sunspotworld;

import com.sun.squawk.io.BufferedReader;
import java.io.InputStreamReader;

public class SunSpotGPS extends SunSpotApplicationAdapter {
    BufferedReader in;

    protected void setup() throws Exception {
        System.out.println("setup");
        in = new BufferedReader(new InputStreamReader(new UARTInputStream(9600)));
    }

    protected void loop() throws Exception {
        String sentence = in.readLine();
        System.out.println(sentence);
        if (sw1.isClosed()) {
            exitLoop();
        }
    }

    protected void cleanup() throws Exception {
        System.out.println("cleanup");
        in.close();
    }
}


③UARTInputStream.java
コード: 全て選択
package org.sunspotworld;

import com.sun.spot.sensorboard.EDemoBoard;
import java.io.IOException;
import java.io.InputStream;

public class UARTInputStream extends InputStream {
    private EDemoBoard eDemo;
    private long timeout;

    public UARTInputStream(int baud) {
        this(baud, false, 0);
    }

    public UARTInputStream(int baud, boolean twoStopBit) {
        this(baud, twoStopBit, 0);
    }

    public UARTInputStream(int baud, boolean twoStopBit, long timeout) {
        this.timeout = timeout;
        eDemo = EDemoBoard.getInstance();
        eDemo.initUART(baud, twoStopBit);
    }

    public int available() throws IOException {
        return timeout > 0 ? (int) eDemo.readUART(timeout) : (int) eDemo.readUART();
    }

    public int read() throws IOException {
        return timeout > 0 ? (int) eDemo.readUART(timeout) : (int) eDemo.readUART();
    }

    public int read(byte[] b, int off, int len) throws IOException {
        return timeout > 0 ? super.read(b, off, len) : eDemo.readUART(b, off, len);
    }
}


配線は資料の通りです。

どうして出力できないのでしょうか?
僕たちは恐らく足りない部分があるのだと思っています。
どこが足りないのでしょうか?
よろしくお願いします。
桐蔭高校科学部
 
記事: 40
登録日時: 2010年7月23日(金) 09:06

Re: GPSについて

投稿記事by yamaguch » 2010年8月04日(水) 10:41

こんにちは、

掲示板には、状況をできるだけ具体的に書いてください。

桐蔭高校科学部 さんが書きました:配線は資料の通りです。

使っている GPS は秋月の GT-720F ですか。
接続は具体的に何をどこにどう繋いでいますか。

桐蔭高校科学部 さんが書きました:GPSモジュールは確かにデータを受信していて

これは、どうやって確認したのですか。

(1) GPS のLEDが点灯している
(2) データは受信しているが、SunSPOT に届いていない
(3) Sun SPOT には届いているが、BufferedReader の readLine() で止まっている
(4) その他

山口
yamaguch
 
記事: 482
登録日時: 2010年7月06日(火) 17:37

Re: GPSについて

投稿記事by 桐蔭高校科学部 » 2010年8月04日(水) 20:20

機種は秋月の GT-720F です。

配線は
GPSモジュール                       SunSPOT
   1ピンーーーーーーーーーーーーーーーーーー¬
   2ピンーー(+)電源4.5V(1.5V電池3本)(-)ー⊥ーーGND
   6ピンーーーーーーーーーーーーーーーーーーーーーーD0



マックで実行してみると、データを受信しました。 :D
これからはデータを保存できるように頑張ります!
ありがとうございました!
桐蔭高校科学部
 
記事: 40
登録日時: 2010年7月23日(金) 09:06


Return to Sun SPOT 質問箱

cron