|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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
}
}
|
|
#2
|
||||||
|
||||||
|
Re: Read a GPS through a Serial Port
Is the console out switch on the cRIO off? Make sure the cRIO isn't imaged with the serial CAN plugin.
What serial levels does the arduino serial port use? Many microcontrollers use TTL levels, which violate the RS-232 spec. You'd need a level converter like the MAX232 to use it with the cRIO. If you post the gibberish and an example of what the GPS sends, someone might be to make sense of it. |
|
#3
|
||||
|
||||
|
Re: Read a GPS through a Serial Port
Yea it's most likely that you need a logic level converter as stated above, because its working on a arduino which uses TTL.
|
|
#4
|
||||
|
||||
|
Re: Read a GPS through a Serial Port
The console out switch is off. I don't have the data with me now but the next time we meet I can try posting some output. You're probably right about the TTL thing, thanks! I will look into that.
|
|
#5
|
||||
|
||||
|
Re: Read a GPS through a Serial Port
BTW, most GPS modules output in serial in NEMA format anyway so using an arduino seems kind of unnecessary.
|
|
#6
|
|||
|
|||
|
Re: Read a GPS through a Serial Port
This bug report suggests that the Serial port in Java is broken:
http://firstforge.wpi.edu/sf/go/artf...3699545405 50 |
|
#7
|
||||
|
||||
|
Re: Read a GPS through a Serial Port
Quote:
|
|
#8
|
||||
|
||||
|
Re: Read a GPS through a Serial Port
I know there have definitely been updates since January 20, but I don't remember seeing anything about Serial Ports. If that's the case then this may all be a lost cause, even with a converter...
|
|
#9
|
||||
|
||||
|
Re: Read a GPS through a Serial Port
Alternatively you can read the GPS data via the arduino's serial port, then send that data over I2C to the digital sidecar.
|
|
#10
|
||||
|
||||
|
Re: Read a GPS through a Serial Port
Hmmm... Thanks for the suggestion, we can check that out next time we meet.
|
|
#11
|
|||
|
|||
|
Re: Read a GPS through a Serial Port
Quote:
Mike |
|
#12
|
||||
|
||||
|
Re: Read a GPS through a Serial Port
No problem.
|
|
#13
|
||||
|
||||
|
Re: Read a GPS through a Serial Port
Quote:
Not being able to clear the read buffer makes the serial port quite useless. Any imput data just continues to stack up. So every time you read you get a complete history of the past data. I tihnk you could recompile the source locally to fix the problem. I didn't have a lot of data to send, I just used a bunch of relay channels for the signals I needed to send. It would be really nice to have a useable RS232 port though in the future. |
|
#14
|
||||||
|
||||||
|
Re: Read a GPS through a Serial Port
Updated serial port files were just attached to the bug report in FIRST Forge.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|