-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Binghamton University Rover Team <[email protected]> Co-authored-by: Levi Lesches <[email protected]>
- Loading branch information
1 parent
26ca1a6
commit 879b036
Showing
13 changed files
with
140 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import "package:subsystems/subsystems.dart"; | ||
|
||
void main() async { | ||
final reader = GpsReader(); | ||
await reader.init(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import "package:subsystems/subsystems.dart"; | ||
import "package:burt_network/logging.dart"; | ||
|
||
void main() async { | ||
BurtLogger.level = LogLevel.debug; | ||
await collection.init(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import "dart:convert"; | ||
import "dart:io"; | ||
|
||
import "package:burt_network/burt_network.dart"; | ||
import "package:subsystems/subsystems.dart"; | ||
|
||
/// The port/device file to listen to the GPS on. | ||
const serialPort = "/dev/ttyACM0"; | ||
|
||
/// Listens to the GPS and sends its output to the Dashboard. | ||
/// | ||
/// Call [init] to start listening and [dispose] to stop. | ||
class GpsReader { | ||
/// Parses an NMEA sentence into a [GpsCoordinates] object. | ||
/// | ||
/// See https://shadyelectronics.com/gps-nmea-sentence-structure. | ||
static GpsCoordinates? parseNMEA(String nmeaSentence) { | ||
final parts = nmeaSentence.split(","); | ||
final tag = parts.first; | ||
if (tag.endsWith("GGA")) { | ||
return GpsCoordinates( | ||
latitude: _nmeaToDecimal(double.tryParse(parts[2]) ?? 0.0), | ||
longitude: _nmeaToDecimal(double.tryParse(parts[4]) ?? 0.0), | ||
altitude: double.tryParse(parts[9]) ?? 0.0, | ||
); | ||
} else if (tag.endsWith("RMC")) { | ||
return GpsCoordinates( | ||
latitude: _nmeaToDecimal(double.tryParse(parts[3]) ?? 0.0), | ||
longitude: _nmeaToDecimal(double.tryParse(parts[5]) ?? 0.0), | ||
); | ||
} else if (tag.endsWith("GLL")) { | ||
return GpsCoordinates( | ||
latitude: _nmeaToDecimal(double.tryParse(parts[1]) ?? 0.0), | ||
longitude: _nmeaToDecimal(double.tryParse(parts[3]) ?? 0.0), | ||
); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
static double _nmeaToDecimal(double nmeaValue) { | ||
final degrees = nmeaValue ~/ 100; | ||
final minutes = nmeaValue % 100; | ||
return degrees + minutes / 60.0; | ||
} | ||
|
||
/// The `cat` process that's reading from the GPS. | ||
Process? cat; | ||
|
||
/// Parses a line of NMEA output and sends the GPS coordinates to the dashboard. | ||
void handleLine(String line) { | ||
final coordinates = parseNMEA(line); | ||
if (coordinates == null) return; | ||
logger.debug("GPS Read: $coordinates"); | ||
final roverPosition = RoverPosition(gps: coordinates); | ||
collection.server.sendMessage(roverPosition); | ||
} | ||
|
||
/// Starts reading the GPS (on [serialPort]) through the `cat` Linux program. | ||
Future<void> init() async { | ||
logger.info("Reading GPS on port $serialPort"); | ||
cat = await Process.start("cat", [serialPort]); | ||
cat!.stdout.transform(utf8.decoder).transform(const LineSplitter()).listen(handleLine); | ||
} | ||
|
||
/// Closes the [cat] process to stop listening to the GPS. | ||
void dispose() => cat?.kill(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters