View Single Post
  #1   Spotlight this post!  
Unread 30-05-2013, 13:19
ktrobotcreator's Avatar
ktrobotcreator ktrobotcreator is offline
Programmer
FRC #1245 (Shazbots)
Team Role: Programmer
 
Join Date: Jul 2012
Rookie Year: 2007
Location: Colorado
Posts: 38
ktrobotcreator is an unknown quantity at this point
Read a GPS through a Serial Port

Hi Chief Delphi Community!

For a separate robotics competition (The Sparkfun Autonomous Vehicle Competition, if you were wondering) we are using the FRC control system. For the competition we have to autonomously navigate a course and race other robots around a parking lot, and we aim to do so by using GPS. We have a working GPS chip on an Arduino system that can output to a serial port, and so we would like to use the one on the cRIO to get the data. We have verified the chip can output the correct data using other software, but when we try to read it from the code, we get a bunch of nonsense. The baud rate is correct, so we don't know why we are getting this data. Any help is appreciated! Thanks!

-Katy

Code:
 
package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.SerialPort;
import edu.wpi.first.wpilibj.visa.VisaException;

public class RobotTemplate extends IterativeRobot {
    
    SerialPort gps;
    
    int dataCount;
        
    public void robotInit() {
        try {
            gps = new SerialPort(9600);
            this.gps.disableTermination();
        }
        catch (Exception e) {
            System.out.println("something went wrong, " + e.getMessage());
        }
    }
    
    public void autonomousInit() {
        dataCount = 0;
        
        try {
            gps.reset();
        } catch (VisaException ex) {}
    }
    
    public void autonomousPeriodic() {
        
        try {
            System.out.println("DC " + dataCount + " " + gps.readString());
        } catch (VisaException ex) {}
        
        dataCount ++; //this is just to make sure our output is updating
    }   
}
Reply With Quote