From aa15d342be3582baf629e81a875a4a494656ae19 Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Thu, 4 Apr 2024 18:48:44 -0400 Subject: [PATCH 01/10] Start --- lib/src/data/metrics/arm.dart | 9 ++++++--- lib/src/data/metrics/metrics.dart | 16 +++++++++++++++- lib/src/widgets/navigation/sidebar.dart | 11 ++++++++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/lib/src/data/metrics/arm.dart b/lib/src/data/metrics/arm.dart index de8829b143..cc2035e9f8 100644 --- a/lib/src/data/metrics/arm.dart +++ b/lib/src/data/metrics/arm.dart @@ -18,9 +18,12 @@ class ArmMetrics extends Metrics { ]; @override - List get allMetrics => [ - "IK: ", - " Current: ${data.currentPosition.prettyPrint}", + List get allMetrics => [ + MetricLine("IK: "), + MetricLine( + " Current: ${data.currentPosition.prettyPrint}", + severity: data.currentPosition < 0 ? Severity.warning : Severity.info, + ), " Target: ${data.targetPosition.prettyPrint}", "------------------------------", "Swivel: ", ...getMotorData(data.base), diff --git a/lib/src/data/metrics/metrics.dart b/lib/src/data/metrics/metrics.dart index 401722ab48..710e4000ea 100644 --- a/lib/src/data/metrics/metrics.dart +++ b/lib/src/data/metrics/metrics.dart @@ -1,8 +1,16 @@ +import "package:math"; + import "package:flutter/foundation.dart"; import "package:rover_dashboard/data.dart"; import "package:rover_dashboard/services.dart"; +class MetricLine { + final Severity severity; + final String text; + MetricLine(this.text, {this.severity = Severity.info}); +} + /// A readout of metrics reported by one of the rover's subsystems. /// /// To use this class, create a subclass that extends this class with [T] as the generated @@ -24,7 +32,13 @@ abstract class Metrics with ChangeNotifier { /// /// Be sure to store the actual values as fields. This property should be a list of one /// user-friendly explanation per metric. - List get allMetrics; + List get allMetrics; + + Severity get overallSeverity { + final indexes = [for (final metric in allMetrics) metric.severity.index]; + final index = indexes.reduce(max); + return Severity.values[index]; + } /// Updates [data] with new data. void update(T value) { diff --git a/lib/src/widgets/navigation/sidebar.dart b/lib/src/widgets/navigation/sidebar.dart index 899d8547fe..2fecbaf961 100644 --- a/lib/src/widgets/navigation/sidebar.dart +++ b/lib/src/widgets/navigation/sidebar.dart @@ -45,7 +45,16 @@ class MetricsList extends ReusableReactiveWidget { style: Theme.of(context).textTheme.headlineSmall, ), children: [ - for (final String metric in model.allMetrics) Text(metric), + for (final MetricLine metric in model.allMetrics) Text( + metric.text, + style: TextStyle( + color: switch (metric.severity) { + Severity.info => null, + Severity.warning => Colors.orange, + Severity.critical => Colors.red, + }, + ), + ), const SizedBox(height: 4), ], ); From b5d83a38dc9a321d4d5879e3236c4b154de188d4 Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 8 Apr 2024 13:36:28 -0400 Subject: [PATCH 02/10] modifying arm.dart file --- lib/src/data/metrics/arm.dart | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/src/data/metrics/arm.dart b/lib/src/data/metrics/arm.dart index cc2035e9f8..45d333ab8d 100644 --- a/lib/src/data/metrics/arm.dart +++ b/lib/src/data/metrics/arm.dart @@ -1,4 +1,5 @@ import "package:rover_dashboard/data.dart"; +import "package:rover_dashboard/src/data/metrics/metrics.dart"; /// Metrics reported by the HREI subsystem about the arm. Does not include the gripper. class ArmMetrics extends Metrics { @@ -9,27 +10,28 @@ class ArmMetrics extends Metrics { String get name => "Arm Base"; /// Returns a description of a [MotorData]. - List getMotorData(MotorData motor) => [ - " Is moving? ${motor.isMoving}", - " Limit? ${motor.isLimitSwitchPressed}", - " Direction: ${motor.direction.humanName}", - " Steps: ${motor.currentStep} --> ${motor.targetStep}", - " Angle: ${motor.angle}", + List getMotorData(MotorData motor, String part) => [ + MetricLine("$part: Is moving? ${motor.isMoving}", severity: Severity.critical), + MetricLine("$part: Limit? ${motor.isLimitSwitchPressed}", severity: Severity.critical), + MetricLine("$part: Direction: ${motor.direction.humanName}", severity: Severity.critical), + MetricLine("$part: Steps: ${motor.currentStep} --> ${motor.targetStep}", severity: Severity.critical), + MetricLine("$part: Angle: ${motor.angle}", severity: Severity.critical), ]; + /// Ask about what variable we need to put for data.targetPosition.? + /// Change severity of MotorData + @override List get allMetrics => [ MetricLine("IK: "), MetricLine( " Current: ${data.currentPosition.prettyPrint}", - severity: data.currentPosition < 0 ? Severity.warning : Severity.info, + severity: data.currentPosition.x < 0 ? Severity.warning : Severity.info, ), - " Target: ${data.targetPosition.prettyPrint}", - "------------------------------", - "Swivel: ", ...getMotorData(data.base), - "------------------------------", - "Shoulder: ", ...getMotorData(data.shoulder), - "------------------------------", - "Elbow: ", ...getMotorData(data.elbow), + MetricLine(" Target: ${data.targetPosition.prettyPrint}", + severity: data.targetPosition.x < 0 ? Severity.warning : Severity.info,), + ...getMotorData(data.base, "Swivel"), + ...getMotorData(data.shoulder, "Shoulder"), + ...getMotorData(data.elbow, "Elbow"), ]; } From c9b60587ed5f98cc824f718b3669e49ff3d22ccf Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 9 Apr 2024 16:00:38 -0400 Subject: [PATCH 03/10] modifying List to List in the files --- lib/src/data/metrics/arm.dart | 2 ++ lib/src/data/metrics/drive.dart | 14 ++++++++------ lib/src/data/metrics/electrical.dart | 8 ++++---- lib/src/data/metrics/gripper.dart | 24 ++++++++++++------------ lib/src/data/metrics/mars.dart | 16 ++++++++-------- lib/src/data/metrics/metrics.dart | 9 +++++++-- lib/src/data/metrics/science.dart | 16 ++++++++++------ 7 files changed, 51 insertions(+), 38 deletions(-) diff --git a/lib/src/data/metrics/arm.dart b/lib/src/data/metrics/arm.dart index 45d333ab8d..5d727cf96e 100644 --- a/lib/src/data/metrics/arm.dart +++ b/lib/src/data/metrics/arm.dart @@ -31,7 +31,9 @@ class ArmMetrics extends Metrics { MetricLine(" Target: ${data.targetPosition.prettyPrint}", severity: data.targetPosition.x < 0 ? Severity.warning : Severity.info,), ...getMotorData(data.base, "Swivel"), + MetricLine("------------------------------",), ...getMotorData(data.shoulder, "Shoulder"), + MetricLine("------------------------------",), ...getMotorData(data.elbow, "Elbow"), ]; } diff --git a/lib/src/data/metrics/drive.dart b/lib/src/data/metrics/drive.dart index 309a519b52..8975ebf77c 100644 --- a/lib/src/data/metrics/drive.dart +++ b/lib/src/data/metrics/drive.dart @@ -14,12 +14,14 @@ class DriveMetrics extends Metrics { String get name => "Drive"; @override - List get allMetrics => [ - "Throttle: ${data.throttle.toStringAsFixed(2)}", - "Left: ${data.left.toStringAsFixed(2)}", - "Right: ${data.right.toStringAsFixed(2)}", - "Left sensor: ${data.leftSensorValue.toStringAsFixed(2)}", - "Right sensor: ${data.rightSensorValue.toStringAsFixed(2)}", + List get allMetrics => [ + MetricLine("Throttle: ${data.throttle.toStringAsFixed(2)}", severity: Severity.critical), + MetricLine("Left: ${data.left.toStringAsFixed(2)}", + severity: Severity.critical), + MetricLine("Right: ${data.right.toStringAsFixed(2)}", + severity: Severity.critical,), + MetricLine("Left sensor: ${data.leftSensorValue.toStringAsFixed(2)}",severity: Severity.critical), + MetricLine("Right sensor: ${data.rightSensorValue.toStringAsFixed(2)}", severity: Severity.critical), ]; @override diff --git a/lib/src/data/metrics/electrical.dart b/lib/src/data/metrics/electrical.dart index d2e45d2316..41291f19fc 100644 --- a/lib/src/data/metrics/electrical.dart +++ b/lib/src/data/metrics/electrical.dart @@ -13,10 +13,10 @@ class ElectricalMetrics extends Metrics { String get name => "Electrical"; @override - List get allMetrics => [ - "Battery: ${data.batteryVoltage}V, ${data.batteryCurrent}A, ${data.batteryTemperature}°F", - "12V supply: ${data.v12Voltage}V, ${data.v12Current}A, ${data.v12Temperature}°F", - "5V supply: ${data.v5Voltage}V, ${data.v5Current}A, ${data.v5Temperature}°F", + List get allMetrics => [ + MetricLine("Battery: ${data.batteryVoltage}V, ${data.batteryCurrent}A, ${data.batteryTemperature}°F", severity: Severity.error,), + MetricLine("12V supply: ${data.v12Voltage}V, ${data.v12Current}A, ${data.v12Temperature}°F", severity: Severity.error,), + MetricLine("5V supply: ${data.v5Voltage}V, ${data.v5Current}A, ${data.v5Temperature}°F", severity: Severity.error,), ]; /// Shorthand for accessing the battery. diff --git a/lib/src/data/metrics/gripper.dart b/lib/src/data/metrics/gripper.dart index 70f0aa4860..dc14ccf9c8 100644 --- a/lib/src/data/metrics/gripper.dart +++ b/lib/src/data/metrics/gripper.dart @@ -9,20 +9,20 @@ class GripperMetrics extends Metrics { String get name => "Gripper"; /// Returns a human-readable description of a [MotorData]. - List getMotorData(MotorData motor) => [ - " Is moving? ${motor.isMoving}", - " Limit? ${motor.isLimitSwitchPressed}", - " Direction: ${motor.direction.humanName}", - " Steps: ${motor.currentStep} --> ${motor.targetStep}", - " Angle: ${motor.angle}", + List getMotorData(MotorData motor, String functionality) => [ + MetricLine("$functionality Is moving? ${motor.isMoving}", severity: Severity.error,), + MetricLine("$functionality Limit? ${motor.isLimitSwitchPressed}", severity: Severity.error,), + MetricLine("$functionality Direction: ${motor.direction.humanName}", severity: Severity.error,), + MetricLine("$functionality Steps: ${motor.currentStep} --> ${motor.targetStep}", severity: Severity.error,), + MetricLine("$functionality Angle: ${motor.angle}",), ]; @override - List get allMetrics => [ - "Lift: ", ...getMotorData(data.lift), - "------------------------------", - "Rotate: ", ...getMotorData(data.rotate), - "------------------------------", - "Pinch: ", ...getMotorData(data.pinch), + List get allMetrics => [ + ...getMotorData(data.lift, "Lift",), + MetricLine("------------------------------",), + ...getMotorData(data.rotate, "Rotate"), + MetricLine("------------------------------",), + ...getMotorData(data.pinch, "Pinch"), ]; } diff --git a/lib/src/data/metrics/mars.dart b/lib/src/data/metrics/mars.dart index 0026b1f948..24c5a09154 100644 --- a/lib/src/data/metrics/mars.dart +++ b/lib/src/data/metrics/mars.dart @@ -14,14 +14,14 @@ class MarsMetrics extends Metrics { String get name => "MARS"; @override - List get allMetrics => [ - "Swivel: ${data.swivel}", - "Tilt: ${data.tilt}", - "Teensy: ${data.status.humanName}", - "GPS:", - " Latitude: ${data.coordinates.latitude}", - " Longitude: ${data.coordinates.longitude}", - " Altitude: ${data.coordinates.altitude}", + List get allMetrics => [ + MetricLine("Swivel: ${data.swivel}", severity: Severity.error,), + MetricLine("Tilt: ${data.tilt}", severity: Severity.error,), + MetricLine("Teensy: ${data.status.humanName}", severity: Severity.error,), + // "GPS:", + MetricLine(" Latitude: ${data.coordinates.latitude}", severity: Severity.error,), + MetricLine(" Longitude: ${data.coordinates.longitude}", severity: Severity.error,), + MetricLine(" Altitude: ${data.coordinates.altitude}", severity: Severity.error,), ]; /// Clears [MarsData.status], because the Teensy cannot be observed when the Pi is disconnected. diff --git a/lib/src/data/metrics/metrics.dart b/lib/src/data/metrics/metrics.dart index 710e4000ea..f7006878d2 100644 --- a/lib/src/data/metrics/metrics.dart +++ b/lib/src/data/metrics/metrics.dart @@ -1,13 +1,17 @@ -import "package:math"; +// import "package:math"; import "package:flutter/foundation.dart"; import "package:rover_dashboard/data.dart"; import "package:rover_dashboard/services.dart"; +/// Class to construct a Metric class MetricLine { + /// Severity of the Metric final Severity severity; + /// Message for the Metric final String text; + /// Constructor for the MetricLine class MetricLine(this.text, {this.severity = Severity.info}); } @@ -34,9 +38,10 @@ abstract class Metrics with ChangeNotifier { /// user-friendly explanation per metric. List get allMetrics; + /// Fetch the overall Security Severity get overallSeverity { final indexes = [for (final metric in allMetrics) metric.severity.index]; - final index = indexes.reduce(max); + final index = indexes.reduce((max, current) => current > max ? current : max); return Severity.values[index]; } diff --git a/lib/src/data/metrics/science.dart b/lib/src/data/metrics/science.dart index 29d36cc0bb..82b7675847 100644 --- a/lib/src/data/metrics/science.dart +++ b/lib/src/data/metrics/science.dart @@ -12,12 +12,16 @@ class ScienceMetrics extends Metrics { String get name => "Science"; @override - List get allMetrics => [ - "Methane: ${data.methane.toStringAsFixed(3)}", - "CO2: ${data.co2.toStringAsFixed(3)}", - "Temperature: ${data.temperature.toStringAsFixed(3)}", - "Humidity: ${data.humidity.toStringAsFixed(3)}", - "pH: ${data.pH.toStringAsFixed(3)}", + List get allMetrics => [ + MetricLine("Methane: ${data.methane.toStringAsFixed(3)}", + severity: Severity.error,), + MetricLine("CO2: ${data.co2.toStringAsFixed(3)}", + severity: Severity.error,), + MetricLine("Temperature: ${data.temperature.toStringAsFixed(3)}", severity: Severity.error,), + MetricLine("Humidity: ${data.humidity.toStringAsFixed(3)}", + severity: Severity.error,), + MetricLine("pH: ${data.pH.toStringAsFixed(3)}", + severity: Severity.error,), ]; @override From f4a8fa6de094877faa9b08fc61e8bdd4aa77bcbc Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 9 Apr 2024 20:16:36 -0400 Subject: [PATCH 04/10] modifying Severity color and trailing commas --- lib/src/data/metrics/arm.dart | 1 - lib/src/data/metrics/drive.dart | 2 +- lib/src/widgets/navigation/sidebar.dart | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/data/metrics/arm.dart b/lib/src/data/metrics/arm.dart index 5d727cf96e..68ac23d7ee 100644 --- a/lib/src/data/metrics/arm.dart +++ b/lib/src/data/metrics/arm.dart @@ -1,5 +1,4 @@ import "package:rover_dashboard/data.dart"; -import "package:rover_dashboard/src/data/metrics/metrics.dart"; /// Metrics reported by the HREI subsystem about the arm. Does not include the gripper. class ArmMetrics extends Metrics { diff --git a/lib/src/data/metrics/drive.dart b/lib/src/data/metrics/drive.dart index 8975ebf77c..c6a3c2e19c 100644 --- a/lib/src/data/metrics/drive.dart +++ b/lib/src/data/metrics/drive.dart @@ -17,7 +17,7 @@ class DriveMetrics extends Metrics { List get allMetrics => [ MetricLine("Throttle: ${data.throttle.toStringAsFixed(2)}", severity: Severity.critical), MetricLine("Left: ${data.left.toStringAsFixed(2)}", - severity: Severity.critical), + severity: Severity.critical,), MetricLine("Right: ${data.right.toStringAsFixed(2)}", severity: Severity.critical,), MetricLine("Left sensor: ${data.leftSensorValue.toStringAsFixed(2)}",severity: Severity.critical), diff --git a/lib/src/widgets/navigation/sidebar.dart b/lib/src/widgets/navigation/sidebar.dart index 2fecbaf961..2f9097409b 100644 --- a/lib/src/widgets/navigation/sidebar.dart +++ b/lib/src/widgets/navigation/sidebar.dart @@ -50,6 +50,7 @@ class MetricsList extends ReusableReactiveWidget { style: TextStyle( color: switch (metric.severity) { Severity.info => null, + Severity.error => Colors.yellow, Severity.warning => Colors.orange, Severity.critical => Colors.red, }, From d2c92acf120fc634735fd4b44ddf97add56bca57 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 11 Apr 2024 18:47:03 -0400 Subject: [PATCH 05/10] updating string to MetricLine in position.dart --- lib/src/data/metrics/position.dart | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/src/data/metrics/position.dart b/lib/src/data/metrics/position.dart index 88160787ab..944a6de48f 100644 --- a/lib/src/data/metrics/position.dart +++ b/lib/src/data/metrics/position.dart @@ -23,16 +23,16 @@ class PositionMetrics extends Metrics { } @override - List get allMetrics => [ - "GPS: ", - " Latitude: ${data.gps.latitude.toStringAsFixed(6)}°", - " Longitude: ${data.gps.longitude.toStringAsFixed(6)}°", - " Altitude: ${data.gps.altitude.toStringAsFixed(2)} m", - "Orientation:", - " X: ${data.orientation.x.toStringAsFixed(2)}°", - " Y: ${data.orientation.y.toStringAsFixed(2)}°", - " Z: ${data.orientation.z.toStringAsFixed(2)}°", - "Distance: ${data.gps.distanceTo(baseStation).toStringAsFixed(2)} m", + List get allMetrics => [ + MetricLine("GPS: "), + MetricLine(" Latitude: ${data.gps.latitude.toStringAsFixed(6)}°",), + MetricLine(" Longitude: ${data.gps.longitude.toStringAsFixed(6)}°",), + MetricLine(" Altitude: ${data.gps.altitude.toStringAsFixed(2)} m"), + MetricLine("Orientation:",), + MetricLine(" X: ${data.orientation.x.toStringAsFixed(2)}°",), + MetricLine(" Y: ${data.orientation.y.toStringAsFixed(2)}°",), + MetricLine(" Z: ${data.orientation.z.toStringAsFixed(2)}°",), + MetricLine("Distance: ${data.gps.distanceTo(baseStation).toStringAsFixed(2)} m",), ]; @override From 578fc551792f516aced06146c4d546fe1acadb5c Mon Sep 17 00:00:00 2001 From: = Date: Thu, 11 Apr 2024 19:11:54 -0400 Subject: [PATCH 06/10] changing the color of the name of the metric --- lib/src/widgets/navigation/sidebar.dart | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/src/widgets/navigation/sidebar.dart b/lib/src/widgets/navigation/sidebar.dart index 2f9097409b..4603754029 100644 --- a/lib/src/widgets/navigation/sidebar.dart +++ b/lib/src/widgets/navigation/sidebar.dart @@ -42,18 +42,15 @@ class MetricsList extends ReusableReactiveWidget { childrenPadding: const EdgeInsets.symmetric(horizontal: 16), title: Text( model.name, - style: Theme.of(context).textTheme.headlineSmall, + style: Theme.of(context).textTheme.headlineSmall?.copyWith( + color: model.overallSeverity.color, + ), ), children: [ for (final MetricLine metric in model.allMetrics) Text( metric.text, style: TextStyle( - color: switch (metric.severity) { - Severity.info => null, - Severity.error => Colors.yellow, - Severity.warning => Colors.orange, - Severity.critical => Colors.red, - }, + color: metric.severity.color, ), ), const SizedBox(height: 4), @@ -61,6 +58,17 @@ class MetricsList extends ReusableReactiveWidget { ); } +/// Extension for COlors on Severity +extension SeverityUtil on Severity { + /// Fetch the color based on the severity + Color? get color => switch (this) { + Severity.info => null, + Severity.error => Colors.yellow, + Severity.warning => Colors.orange, + Severity.critical => Colors.red, + }; +} + /// Displays controls for the given [Controller]. class ControlsDisplay extends ReusableReactiveWidget { /// The number gamepad being used. From b10280f65f5825b5a7f014e7e99a25933b8f837b Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Thu, 18 Apr 2024 01:06:44 -0400 Subject: [PATCH 07/10] Removed MARS metrics --- lib/data.dart | 1 - lib/models.dart | 1 - lib/src/data/metrics/mars.dart | 38 ----------------------- lib/src/models/rover/metrics.dart | 10 +------ lib/src/models/view/mars.dart | 50 ------------------------------- 5 files changed, 1 insertion(+), 99 deletions(-) delete mode 100644 lib/src/data/metrics/mars.dart delete mode 100644 lib/src/models/view/mars.dart diff --git a/lib/data.dart b/lib/data.dart index e458de7a73..3653503d3b 100644 --- a/lib/data.dart +++ b/lib/data.dart @@ -16,7 +16,6 @@ export "src/data/metrics/arm.dart"; export "src/data/metrics/drive.dart"; export "src/data/metrics/gripper.dart"; export "src/data/metrics/position.dart"; -export "src/data/metrics/mars.dart"; export "src/data/metrics/metrics.dart"; export "src/data/metrics/science.dart"; diff --git a/lib/models.dart b/lib/models.dart index 5647eff8d1..f44e718b52 100644 --- a/lib/models.dart +++ b/lib/models.dart @@ -41,7 +41,6 @@ export "src/models/rover/rover.dart"; // View models export "src/models/view/map.dart"; export "src/models/view/logs.dart"; -export "src/models/view/mars.dart"; export "src/models/view/science.dart"; export "src/models/view/timer.dart"; diff --git a/lib/src/data/metrics/mars.dart b/lib/src/data/metrics/mars.dart deleted file mode 100644 index 24c5a09154..0000000000 --- a/lib/src/data/metrics/mars.dart +++ /dev/null @@ -1,38 +0,0 @@ -import "package:rover_dashboard/data.dart"; -import "package:rover_dashboard/models.dart"; - -/// Metrics reported by the MARS subsystem. -/// -/// The MARS subsystem tracks the rover's position and orients the unidirectional antenna to face -/// the rover for a better signal. These metrics are used to track the subsystem's accuracy and -/// visualize its movements. -class MarsMetrics extends Metrics { - /// A collection of metrics relevant for monitoring the MARS subsystem. - MarsMetrics() : super(MarsData()); - - @override - String get name => "MARS"; - - @override - List get allMetrics => [ - MetricLine("Swivel: ${data.swivel}", severity: Severity.error,), - MetricLine("Tilt: ${data.tilt}", severity: Severity.error,), - MetricLine("Teensy: ${data.status.humanName}", severity: Severity.error,), - // "GPS:", - MetricLine(" Latitude: ${data.coordinates.latitude}", severity: Severity.error,), - MetricLine(" Longitude: ${data.coordinates.longitude}", severity: Severity.error,), - MetricLine(" Altitude: ${data.coordinates.altitude}", severity: Severity.error,), - ]; - - /// Clears [MarsData.status], because the Teensy cannot be observed when the Pi is disconnected. - void clearStatus() { - data.clearStatus(); - notifyListeners(); - } - - @override - void update(MarsData value) { - super.update(value); - models.rover.metrics.position.baseStation = data.coordinates; - } -} diff --git a/lib/src/models/rover/metrics.dart b/lib/src/models/rover/metrics.dart index a71628c86a..d59b7f2db7 100644 --- a/lib/src/models/rover/metrics.dart +++ b/lib/src/models/rover/metrics.dart @@ -13,9 +13,6 @@ class RoverMetrics extends Model { /// Data from the drive subsystem. final drive = DriveMetrics(); - /// Data from the MARS subsystem. - final mars = MarsMetrics(); - /// Data from the HREI subsystem about the arm base. final arm = ArmMetrics(); @@ -26,7 +23,7 @@ class RoverMetrics extends Model { /// /// NOTE: Keep this as a getter, NOT a field. If this is made a field, then it won't update /// when new data is received. As a getter, every time it is called it will use new data. - List get allMetrics => [position, mars, drive, science, arm, gripper]; + List get allMetrics => [position, drive, science, arm, gripper]; @override Future init() async { @@ -45,11 +42,6 @@ class RoverMetrics extends Model { decoder: RoverPosition.fromBuffer, handler: position.update, ); - models.messages.registerHandler( - name: MarsData().messageName, - decoder: MarsData.fromBuffer, - handler: mars.update, - ); models.messages.registerHandler( name: ArmData().messageName, decoder: ArmData.fromBuffer, diff --git a/lib/src/models/view/mars.dart b/lib/src/models/view/mars.dart deleted file mode 100644 index 601c6f7f00..0000000000 --- a/lib/src/models/view/mars.dart +++ /dev/null @@ -1,50 +0,0 @@ -import "dart:math"; -import "dart:ui"; -import "package:flutter/foundation.dart"; - -import "package:rover_dashboard/models.dart"; - -/// A view model for the MARS page. -/// -/// This model tracks the rover's position on-screen and the orientation of the MARS antenna. This -/// view model gets its data from [RoverMetrics.mars] and [RoverMetrics.position]. -class MarsModel with ChangeNotifier { - /// A shorthand for accessing [Rover.metrics]. - RoverMetrics get metrics => models.rover.metrics; - - /// Listens for updates to the rover's position or the MARS antenna's orientation. - MarsModel() { - metrics.position.addListener(update); - metrics.mars.addListener(update); - } - - @override - void dispose() { - metrics.mars.removeListener(update); - metrics.position.removeListener(update); - super.dispose(); - } - - /// The position of the rover on-screen. - Offset roverOffset = Offset.zero; - - /// The position of the base station on-screen. - Offset actualOffset = Offset.zero; - - /// Updates [roverOffset] and [actualOffset] based on new data. - void update() { - final rover = metrics.position.data.gps; - final baseStation = metrics.mars.data.coordinates; - final x = rover.longitude - baseStation.longitude; - final y = rover.latitude - baseStation.latitude; - final maxDistance = max(x.abs(), y.abs()); - if (maxDistance == 0) return; - roverOffset = Offset(x / maxDistance.abs(), y / maxDistance.abs()); - - // Update [actualX] and [actualY] - final angle = metrics.mars.data.swivel; - actualOffset = Offset(cos(angle), -sin(angle)); - - notifyListeners(); - } -} From cb0eac0f7e1b573e8a7202c447915d3f89f9ebc9 Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Thu, 18 Apr 2024 01:08:28 -0400 Subject: [PATCH 08/10] Removed placeholder severity --- lib/src/data/metrics/arm.dart | 21 +++++++-------------- lib/src/data/metrics/drive.dart | 1 - lib/src/data/metrics/gripper.dart | 10 +++++----- lib/src/data/metrics/science.dart | 14 +++++--------- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/lib/src/data/metrics/arm.dart b/lib/src/data/metrics/arm.dart index 68ac23d7ee..aeca311c2a 100644 --- a/lib/src/data/metrics/arm.dart +++ b/lib/src/data/metrics/arm.dart @@ -10,25 +10,18 @@ class ArmMetrics extends Metrics { /// Returns a description of a [MotorData]. List getMotorData(MotorData motor, String part) => [ - MetricLine("$part: Is moving? ${motor.isMoving}", severity: Severity.critical), - MetricLine("$part: Limit? ${motor.isLimitSwitchPressed}", severity: Severity.critical), - MetricLine("$part: Direction: ${motor.direction.humanName}", severity: Severity.critical), - MetricLine("$part: Steps: ${motor.currentStep} --> ${motor.targetStep}", severity: Severity.critical), - MetricLine("$part: Angle: ${motor.angle}", severity: Severity.critical), + MetricLine("$part: Is moving? ${motor.isMoving}"), + MetricLine("$part: Limit? ${motor.isLimitSwitchPressed}"), + MetricLine("$part: Direction: ${motor.direction.humanName}"), + MetricLine("$part: Steps: ${motor.currentStep} --> ${motor.targetStep}"), + MetricLine("$part: Angle: ${motor.angle}"), ]; - /// Ask about what variable we need to put for data.targetPosition.? - /// Change severity of MotorData - @override List get allMetrics => [ MetricLine("IK: "), - MetricLine( - " Current: ${data.currentPosition.prettyPrint}", - severity: data.currentPosition.x < 0 ? Severity.warning : Severity.info, - ), - MetricLine(" Target: ${data.targetPosition.prettyPrint}", - severity: data.targetPosition.x < 0 ? Severity.warning : Severity.info,), + MetricLine(" Current: ${data.currentPosition.prettyPrint}"), + MetricLine(" Target: ${data.targetPosition.prettyPrint}"), ...getMotorData(data.base, "Swivel"), MetricLine("------------------------------",), ...getMotorData(data.shoulder, "Shoulder"), diff --git a/lib/src/data/metrics/drive.dart b/lib/src/data/metrics/drive.dart index de375ae0d6..048ea22660 100644 --- a/lib/src/data/metrics/drive.dart +++ b/lib/src/data/metrics/drive.dart @@ -19,7 +19,6 @@ class DriveMetrics extends Metrics { MetricLine("Left: ${data.left.toStringAsFixed(2)}"), MetricLine("Right: ${data.right.toStringAsFixed(2)}"), MetricLine("Battery: ${data.batteryVoltage.toStringAsFixed(2)}V, ${data.batteryCurrent.toStringAsFixed(2)}A, ${data.batteryTemperature.toStringAsFixed(2)}°F"), - ]; @override diff --git a/lib/src/data/metrics/gripper.dart b/lib/src/data/metrics/gripper.dart index dc14ccf9c8..9448db2ded 100644 --- a/lib/src/data/metrics/gripper.dart +++ b/lib/src/data/metrics/gripper.dart @@ -10,11 +10,11 @@ class GripperMetrics extends Metrics { /// Returns a human-readable description of a [MotorData]. List getMotorData(MotorData motor, String functionality) => [ - MetricLine("$functionality Is moving? ${motor.isMoving}", severity: Severity.error,), - MetricLine("$functionality Limit? ${motor.isLimitSwitchPressed}", severity: Severity.error,), - MetricLine("$functionality Direction: ${motor.direction.humanName}", severity: Severity.error,), - MetricLine("$functionality Steps: ${motor.currentStep} --> ${motor.targetStep}", severity: Severity.error,), - MetricLine("$functionality Angle: ${motor.angle}",), + MetricLine("$functionality Is moving? ${motor.isMoving}"), + MetricLine("$functionality Limit? ${motor.isLimitSwitchPressed}"), + MetricLine("$functionality Direction: ${motor.direction.humanName}"), + MetricLine("$functionality Steps: ${motor.currentStep} --> ${motor.targetStep}"), + MetricLine("$functionality Angle: ${motor.angle}"), ]; @override diff --git a/lib/src/data/metrics/science.dart b/lib/src/data/metrics/science.dart index 82b7675847..17cb938d62 100644 --- a/lib/src/data/metrics/science.dart +++ b/lib/src/data/metrics/science.dart @@ -13,15 +13,11 @@ class ScienceMetrics extends Metrics { @override List get allMetrics => [ - MetricLine("Methane: ${data.methane.toStringAsFixed(3)}", - severity: Severity.error,), - MetricLine("CO2: ${data.co2.toStringAsFixed(3)}", - severity: Severity.error,), - MetricLine("Temperature: ${data.temperature.toStringAsFixed(3)}", severity: Severity.error,), - MetricLine("Humidity: ${data.humidity.toStringAsFixed(3)}", - severity: Severity.error,), - MetricLine("pH: ${data.pH.toStringAsFixed(3)}", - severity: Severity.error,), + MetricLine("Methane: ${data.methane.toStringAsFixed(3)}"), + MetricLine("CO2: ${data.co2.toStringAsFixed(3)}"), + MetricLine("Temperature: ${data.temperature.toStringAsFixed(3)}"), + MetricLine("Humidity: ${data.humidity.toStringAsFixed(3)}"), + MetricLine("pH: ${data.pH.toStringAsFixed(3)}"), ]; @override From dd9a90cc933d4477fd2fbdcff0fc800687a2334c Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Thu, 18 Apr 2024 01:15:14 -0400 Subject: [PATCH 09/10] Made default severity null --- lib/src/data/metrics/arm.dart | 4 ++-- lib/src/data/metrics/metrics.dart | 13 ++++++++----- lib/src/widgets/navigation/sidebar.dart | 10 +++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/src/data/metrics/arm.dart b/lib/src/data/metrics/arm.dart index aeca311c2a..5b9a829903 100644 --- a/lib/src/data/metrics/arm.dart +++ b/lib/src/data/metrics/arm.dart @@ -10,8 +10,8 @@ class ArmMetrics extends Metrics { /// Returns a description of a [MotorData]. List getMotorData(MotorData motor, String part) => [ - MetricLine("$part: Is moving? ${motor.isMoving}"), - MetricLine("$part: Limit? ${motor.isLimitSwitchPressed}"), + MetricLine("$part: Is moving? ${motor.isMoving}", severity: motor.isMoving ? Severity.info : null), + MetricLine("$part: Limit? ${motor.isLimitSwitchPressed}", severity: motor.isLimitSwitchPressed ? Severity.warning : null), MetricLine("$part: Direction: ${motor.direction.humanName}"), MetricLine("$part: Steps: ${motor.currentStep} --> ${motor.targetStep}"), MetricLine("$part: Angle: ${motor.angle}"), diff --git a/lib/src/data/metrics/metrics.dart b/lib/src/data/metrics/metrics.dart index f7006878d2..64a4838f74 100644 --- a/lib/src/data/metrics/metrics.dart +++ b/lib/src/data/metrics/metrics.dart @@ -1,5 +1,7 @@ // import "package:math"; +import "dart:math"; + import "package:flutter/foundation.dart"; import "package:rover_dashboard/data.dart"; @@ -8,11 +10,11 @@ import "package:rover_dashboard/services.dart"; /// Class to construct a Metric class MetricLine { /// Severity of the Metric - final Severity severity; + final Severity? severity; /// Message for the Metric final String text; /// Constructor for the MetricLine class - MetricLine(this.text, {this.severity = Severity.info}); + MetricLine(this.text, {this.severity}); } /// A readout of metrics reported by one of the rover's subsystems. @@ -39,9 +41,10 @@ abstract class Metrics with ChangeNotifier { List get allMetrics; /// Fetch the overall Security - Severity get overallSeverity { - final indexes = [for (final metric in allMetrics) metric.severity.index]; - final index = indexes.reduce((max, current) => current > max ? current : max); + Severity? get overallSeverity { + final indexes = [for (final metric in allMetrics) metric.severity?.index ?? -1]; + final index = indexes.reduce(max); + if (index == -1) return null; return Severity.values[index]; } diff --git a/lib/src/widgets/navigation/sidebar.dart b/lib/src/widgets/navigation/sidebar.dart index 4603754029..9148915e54 100644 --- a/lib/src/widgets/navigation/sidebar.dart +++ b/lib/src/widgets/navigation/sidebar.dart @@ -43,14 +43,14 @@ class MetricsList extends ReusableReactiveWidget { title: Text( model.name, style: Theme.of(context).textTheme.headlineSmall?.copyWith( - color: model.overallSeverity.color, + color: model.overallSeverity?.color, ), ), children: [ for (final MetricLine metric in model.allMetrics) Text( metric.text, style: TextStyle( - color: metric.severity.color, + color: metric.severity?.color, ), ), const SizedBox(height: 4), @@ -62,10 +62,10 @@ class MetricsList extends ReusableReactiveWidget { extension SeverityUtil on Severity { /// Fetch the color based on the severity Color? get color => switch (this) { - Severity.info => null, - Severity.error => Colors.yellow, + Severity.info => Colors.blueGrey, Severity.warning => Colors.orange, - Severity.critical => Colors.red, + Severity.error => Colors.red, + Severity.critical => Colors.red.shade900, }; } From 9f26d5f8319a344c3dd8e41b1de61104722595de Mon Sep 17 00:00:00 2001 From: Levi Lesches Date: Thu, 18 Apr 2024 01:33:12 -0400 Subject: [PATCH 10/10] Reviewed severity for all metrics --- lib/src/data/metrics/drive.dart | 29 +++++++++++++++++++++++++++-- lib/src/data/metrics/gripper.dart | 4 ++-- lib/src/data/metrics/position.dart | 20 +++++++++++++++++--- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/lib/src/data/metrics/drive.dart b/lib/src/data/metrics/drive.dart index 048ea22660..2f24e13469 100644 --- a/lib/src/data/metrics/drive.dart +++ b/lib/src/data/metrics/drive.dart @@ -13,12 +13,37 @@ class DriveMetrics extends Metrics { @override String get name => "Drive"; + /// The severity based on the throttle speed. + Severity? get throttleSeverity { + if (data.throttle == 0) { + return null; + } else if (data.throttle <= 0.3) { + return Severity.info; + } else if (data.throttle <= 0.75) { + return Severity.warning; + } else { + return Severity.critical; + } + } + + /// The severity for the electrical metrics. + Severity? get electricalSeverity { + if (data.batteryVoltage == 0) return null; + if (data.batteryVoltage <= 25) { + return Severity.critical; + } else if (data.batteryVoltage <= 26) { + return Severity.warning; + } else { + return null; + } + } + @override List get allMetrics => [ - MetricLine("Throttle: ${data.throttle.toStringAsFixed(2)}"), + MetricLine("Throttle: ${data.throttle.toStringAsFixed(2)}", severity: throttleSeverity), MetricLine("Left: ${data.left.toStringAsFixed(2)}"), MetricLine("Right: ${data.right.toStringAsFixed(2)}"), - MetricLine("Battery: ${data.batteryVoltage.toStringAsFixed(2)}V, ${data.batteryCurrent.toStringAsFixed(2)}A, ${data.batteryTemperature.toStringAsFixed(2)}°F"), + MetricLine("Battery: ${data.batteryVoltage.toStringAsFixed(2)}V,${data.batteryCurrent.toStringAsFixed(2)}A, ${data.batteryTemperature.toStringAsFixed(2)}°F", severity: electricalSeverity), ]; @override diff --git a/lib/src/data/metrics/gripper.dart b/lib/src/data/metrics/gripper.dart index 9448db2ded..3c6f33763d 100644 --- a/lib/src/data/metrics/gripper.dart +++ b/lib/src/data/metrics/gripper.dart @@ -10,8 +10,8 @@ class GripperMetrics extends Metrics { /// Returns a human-readable description of a [MotorData]. List getMotorData(MotorData motor, String functionality) => [ - MetricLine("$functionality Is moving? ${motor.isMoving}"), - MetricLine("$functionality Limit? ${motor.isLimitSwitchPressed}"), + MetricLine("$functionality Is moving? ${motor.isMoving}", severity: motor.isMoving ? Severity.info : null), + MetricLine("$functionality Limit? ${motor.isLimitSwitchPressed}", severity: motor.isLimitSwitchPressed ? Severity.warning : null), MetricLine("$functionality Direction: ${motor.direction.humanName}"), MetricLine("$functionality Steps: ${motor.currentStep} --> ${motor.targetStep}"), MetricLine("$functionality Angle: ${motor.angle}"), diff --git a/lib/src/data/metrics/position.dart b/lib/src/data/metrics/position.dart index 944a6de48f..01846fe917 100644 --- a/lib/src/data/metrics/position.dart +++ b/lib/src/data/metrics/position.dart @@ -22,6 +22,20 @@ class PositionMetrics extends Metrics { notifyListeners(); } + /// Gets the severity of the rover's orientation for both pitch and roll. + Severity? getRotationSeverity(double orientation) { + final abs = orientation.abs(); + if (abs >= 30) { + return Severity.critical; + } else if (abs >= 15) { + return Severity.warning; + } else if (abs >= 10) { + return Severity.info; + } else { + return null; + } + } + @override List get allMetrics => [ MetricLine("GPS: "), @@ -29,9 +43,9 @@ class PositionMetrics extends Metrics { MetricLine(" Longitude: ${data.gps.longitude.toStringAsFixed(6)}°",), MetricLine(" Altitude: ${data.gps.altitude.toStringAsFixed(2)} m"), MetricLine("Orientation:",), - MetricLine(" X: ${data.orientation.x.toStringAsFixed(2)}°",), - MetricLine(" Y: ${data.orientation.y.toStringAsFixed(2)}°",), - MetricLine(" Z: ${data.orientation.z.toStringAsFixed(2)}°",), + MetricLine(" X: ${data.orientation.x.toStringAsFixed(2)}°", severity: getRotationSeverity(data.orientation.x)), + MetricLine(" Y: ${data.orientation.y.toStringAsFixed(2)}°", severity: getRotationSeverity(data.orientation.y)), + MetricLine(" Z: ${data.orientation.z.toStringAsFixed(2)}°"), MetricLine("Distance: ${data.gps.distanceTo(baseStation).toStringAsFixed(2)} m",), ];