-
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.
Added simulator and real rover logic (#1)
This PR splits the code into 3 main categories: - interfaces: an interface for each component that defines what it can do - simulated: a simulated version for each component - rover: the real implementation of each component Using this new structure, this PR also adds unit tests that simulate all but one component at a time. These tests are run for every new PR and commit.
- Loading branch information
1 parent
a6fec0f
commit 9b4bd73
Showing
56 changed files
with
1,876 additions
and
226 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
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# These tell your computer or the rover to fetch from the parent folder and not GitHub | ||
pubspec_overrides.yaml | ||
|
||
# https://dart.dev/guides/libraries/private-files | ||
# Created by `dart pub` | ||
.dart_tool/ | ||
|
||
*.dll | ||
*.dll |
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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import "package:autonomy/autonomy.dart"; | ||
import "package:burt_network/logging.dart"; | ||
import "package:autonomy/rover.dart"; | ||
|
||
void main(List<String> arguments) async { | ||
final tankMode = arguments.contains("--tank"); | ||
if (tankMode) logger.info("Running in tank mode"); | ||
await collection.init(tankMode: arguments.contains("--tank")); | ||
void main() async { | ||
final rover = RoverAutonomy(); | ||
await rover.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// ignore_for_file: avoid_print | ||
|
||
import "package:autonomy/interfaces.dart"; | ||
|
||
const binghamtonLatitude = 42.0877327; | ||
const utahLatitude = 38.406683; | ||
|
||
void printInfo(String name, double latitude) { | ||
GpsInterface.currentLatitude = latitude; | ||
print("At $name:"); | ||
print(" There are ${GpsUtils.metersPerLongitude.toStringAsFixed(2)} meters per 1 degree of longitude"); | ||
print(" Our max error in longitude would be ${GpsUtils.epsilonLongitude} degrees"); | ||
final isWithinRange = GpsInterface.gpsError <= GpsUtils.epsilonLongitude; | ||
print(" Our GPS has ${GpsInterface.gpsError} degrees of error, so this would ${isWithinRange ? 'work' : 'not work'}"); | ||
} | ||
|
||
void main() { | ||
print("There are always ${GpsUtils.metersPerLatitude} meters in 1 degree of latitude"); | ||
print(" So our max error in latitude is always ${GpsUtils.epsilonLatitude} degrees"); | ||
printInfo("the equator", 0); | ||
printInfo("Binghamton", binghamtonLatitude); | ||
printInfo("Utah", utahLatitude); | ||
} |
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,35 @@ | ||
// ignore_for_file: avoid_print | ||
|
||
import "package:autonomy/interfaces.dart"; | ||
import "package:autonomy/src/rover/corrector.dart"; | ||
|
||
const maxError = GpsInterface.gpsError; | ||
const maxSamples = 10; | ||
final epsilon = GpsUtils.epsilonLatitude; // we need to be accurate within 1 meter | ||
const n = 1000; | ||
bool verbose = false; | ||
|
||
bool test() { | ||
final error = RandomError(maxError); | ||
final corrector = ErrorCorrector(maxSamples: maxSamples); | ||
for (var i = 0; i < 10; i++) { | ||
final value = error.value; | ||
corrector.addValue(value); | ||
if (verbose) { | ||
final calibrated = corrector.calibratedValue; | ||
print("Current value: $value, Corrected value: $calibrated"); | ||
print(" Difference: ${calibrated.toStringAsFixed(7)} < ${epsilon.toStringAsFixed(7)}"); | ||
} | ||
} | ||
return corrector.calibratedValue.abs() <= epsilon; | ||
} | ||
|
||
void main(List<String> args) { | ||
if (args.contains("-v") || args.contains("--verbose")) verbose = true; | ||
var count = 0; | ||
for (var i = 0; i < n; i++) { | ||
if (test()) count++; | ||
} | ||
final percentage = (count / n * 100).toStringAsFixed(2); | ||
print("Average performance: %$percentage"); | ||
} |
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,63 @@ | ||
import "package:burt_network/logging.dart"; | ||
import "package:burt_network/generated.dart"; | ||
|
||
import "package:autonomy/simulator.dart"; | ||
import "package:autonomy/rover.dart"; | ||
|
||
void main() async { | ||
Logger.level = LogLevel.debug; | ||
final simulator = AutonomySimulator(); | ||
simulator.drive = SensorlessDrive(collection: simulator, useGps: false, useImu: false); | ||
await simulator.init(); | ||
await simulator.server.waitForConnection(); | ||
|
||
final message = AutonomyData( | ||
destination: GpsCoordinates(latitude: 0, longitude: 0), | ||
state: AutonomyState.DRIVING, | ||
task: AutonomyTask.GPS_ONLY, | ||
obstacles: [], | ||
path: [ | ||
for (double x = 0; x < 3; x++) | ||
for (double y = 0; y < 3; y++) | ||
GpsCoordinates(latitude: y, longitude: x), | ||
], | ||
); | ||
simulator.server.sendMessage(message); | ||
|
||
// "Snakes" around a 3x3 meter box. (0, 0), North | ||
await simulator.drive.goForward(); // (1, 0), North | ||
await simulator.drive.goForward(); // (2, 0), North | ||
await simulator.drive.turnRight(); // (2, 0), East | ||
await simulator.drive.goForward(); // (2, 1), East | ||
await simulator.drive.turnRight(); // (2, 1), South | ||
await simulator.drive.goForward(); // (1, 1), South | ||
await simulator.drive.goForward(); // (0, 1), South | ||
await simulator.drive.turnLeft(); // (0, 1), East | ||
await simulator.drive.goForward(); // (0, 2), East | ||
await simulator.drive.turnLeft(); // (0, 2), North | ||
await simulator.drive.goForward(); // (1, 2), North | ||
await simulator.drive.goForward(); // (2, 2), North | ||
await simulator.drive.turnLeft(); // (2, 2), West | ||
await simulator.drive.goForward(); // (2, 1), West | ||
await simulator.drive.goForward(); // (2, 0), West | ||
await simulator.drive.turnLeft(); // (2, 0), South | ||
await simulator.drive.goForward(); // (1, 0), South | ||
await simulator.drive.goForward(); // (0, 0), South | ||
await simulator.drive.turnLeft(); // (0, 0), East | ||
await simulator.drive.turnLeft(); // (0, 0), North | ||
|
||
final message2 = AutonomyData( | ||
state: AutonomyState.AT_DESTINATION, | ||
task: AutonomyTask.AUTONOMY_TASK_UNDEFINED, | ||
obstacles: [], | ||
path: [ | ||
for (double x = 0; x < 3; x++) | ||
for (double y = 0; y < 3; y++) | ||
GpsCoordinates(latitude: y, longitude: x), | ||
], | ||
); | ||
simulator.server.sendMessage(message2); | ||
simulator.server.sendMessage(message2); | ||
|
||
await simulator.dispose(); | ||
} |
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,24 @@ | ||
import "package:autonomy/interfaces.dart"; | ||
import "package:autonomy/simulator.dart"; | ||
import "package:autonomy/rover.dart"; | ||
import "package:burt_network/logging.dart"; | ||
|
||
final chair = (2, 0).toGps(); | ||
final obstacles = <SimulatedObstacle>[ | ||
SimulatedObstacle(coordinates: (2, 0).toGps(), radius: 3), | ||
SimulatedObstacle(coordinates: (6, -1).toGps(), radius: 3), | ||
SimulatedObstacle(coordinates: (6, 1).toGps(), radius: 3), | ||
]; | ||
// Enter in the Dashboard: Destination = (lat=7, long=0); | ||
|
||
void main() async { | ||
Logger.level = LogLevel.all; | ||
final simulator = AutonomySimulator(); | ||
final detector = DetectorSimulator(collection: simulator, obstacles: obstacles); | ||
simulator.detector = detector; | ||
simulator.pathfinder = RoverPathfinder(collection: simulator); | ||
simulator.orchestrator = RoverOrchestrator(collection: simulator); | ||
simulator.drive = DriveSimulator(collection: simulator, shouldDelay: true); | ||
await simulator.init(); | ||
await simulator.server.waitForConnection(); | ||
} |
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
export "src/interfaces/a_star.dart"; | ||
export "src/interfaces/autonomy.dart"; | ||
export "src/interfaces/detector.dart"; | ||
export "src/interfaces/drive.dart"; | ||
export "src/interfaces/error.dart"; | ||
export "src/interfaces/gps.dart"; | ||
export "src/interfaces/imu.dart"; | ||
export "src/interfaces/pathfinding.dart"; | ||
export "src/interfaces/server.dart"; | ||
export "src/interfaces/realsense.dart"; | ||
export "src/interfaces/reporter.dart"; | ||
export "src/interfaces/service.dart"; | ||
export "src/interfaces/orchestrator.dart"; |
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,30 @@ | ||
export "src/rover/drive.dart"; | ||
export "src/rover/pathfinding.dart"; | ||
export "src/rover/orchestrator.dart"; | ||
export "src/rover/sensorless.dart"; | ||
|
||
import "package:autonomy/interfaces.dart"; | ||
import "package:autonomy/simulator.dart"; | ||
import "package:burt_network/logging.dart"; | ||
|
||
import "src/rover/pathfinding.dart"; | ||
import "src/rover/server.dart"; | ||
import "src/rover/drive.dart"; | ||
import "src/rover/gps.dart"; | ||
import "src/rover/imu.dart"; | ||
import "src/rover/orchestrator.dart"; | ||
|
||
/// A collection of all the different services used by the autonomy program. | ||
class RoverAutonomy extends AutonomyInterface { | ||
/// A server to communicate with the dashboard and receive data from the subsystems. | ||
@override late final AutonomyServer server = AutonomyServer(collection: this); | ||
/// A helper class to handle driving the rover. | ||
@override late final drive = RoverDrive(collection: this); | ||
@override late final gps = RoverGps(collection: this); | ||
@override late final imu = RoverImu(collection: this); | ||
@override late final logger = BurtLogger(socket: server); | ||
@override late final pathfinder = RoverPathfinder(collection: this); | ||
@override late final detector = DetectorSimulator(collection: this, obstacles: []); | ||
@override late final realsense = RealSenseSimulator(collection: this); | ||
@override late final orchestrator = RoverOrchestrator(collection: this); | ||
} |
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,38 @@ | ||
export "src/simulator/detector.dart"; | ||
export "src/simulator/drive.dart"; | ||
export "src/simulator/gps.dart"; | ||
export "src/simulator/imu.dart"; | ||
export "src/simulator/realsense.dart"; | ||
export "src/simulator/server.dart"; | ||
|
||
import "package:autonomy/interfaces.dart"; | ||
import "package:autonomy/src/simulator/orchestrator.dart"; | ||
import "package:burt_network/logging.dart"; | ||
|
||
import "src/simulator/detector.dart"; | ||
import "src/simulator/drive.dart"; | ||
import "src/simulator/gps.dart"; | ||
import "src/simulator/imu.dart"; | ||
import "src/simulator/pathfinding.dart"; | ||
import "src/simulator/realsense.dart"; | ||
import "src/simulator/server.dart"; | ||
|
||
class AutonomySimulator extends AutonomyInterface { | ||
@override late final logger = BurtLogger(socket: server); | ||
@override late ServerInterface server = SimulatorServer(collection: this); | ||
@override late GpsInterface gps = GpsSimulator(collection: this); | ||
@override late ImuInterface imu = ImuSimulator(collection: this); | ||
@override late DriveInterface drive = DriveSimulator(collection: this); | ||
@override late PathfindingInterface pathfinder = PathfindingSimulator(collection: this); | ||
@override late DetectorInterface detector = DetectorSimulator(collection: this, obstacles: []); | ||
@override late RealSenseInterface realsense = RealSenseSimulator(collection: this); | ||
@override late OrchestratorInterface orchestrator = OrchestratorSimulator(collection: this); | ||
|
||
bool isInitialized = false; | ||
|
||
@override | ||
Future<bool> init() { isInitialized = true; return super.init(); } | ||
|
||
@override | ||
Future<void> dispose() { isInitialized = false; return super.dispose(); } | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.