From a5ce6ed9b04b6f4623ded4a59a540d4e46f53f12 Mon Sep 17 00:00:00 2001 From: TheFJcurve Date: Mon, 8 Jul 2024 11:59:05 -0400 Subject: [PATCH 01/11] started work on logging --- flutter_app/lib/modules/mavlink_communication.dart | 3 ++- flutter_app/lib/screens/home_screen.dart | 7 +++++++ flutter_app/lib/widgets/change_mode_widget.dart | 4 +++- flutter_app/lib/widgets/drone_information_widget.dart | 4 ++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/flutter_app/lib/modules/mavlink_communication.dart b/flutter_app/lib/modules/mavlink_communication.dart index 4404a20..e1589af 100644 --- a/flutter_app/lib/modules/mavlink_communication.dart +++ b/flutter_app/lib/modules/mavlink_communication.dart @@ -1,5 +1,6 @@ import 'dart:typed_data'; import 'dart:io'; +import 'dart:developer'; import 'dart:async'; import 'package:flutter_libserialport/flutter_libserialport.dart'; import 'package:dart_mavlink/mavlink.dart'; @@ -67,7 +68,7 @@ class MavlinkCommunication { _parser.parse(data); }, onError: (error) { // print if log does not work, I can't really test it, just avoid the warning - print(error); + log(error); _tcpSocket.destroy(); }); diff --git a/flutter_app/lib/screens/home_screen.dart b/flutter_app/lib/screens/home_screen.dart index 93f369c..d93fb89 100644 --- a/flutter_app/lib/screens/home_screen.dart +++ b/flutter_app/lib/screens/home_screen.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; +import 'package:imacs/modules/change_drone_mode.dart'; import 'package:imacs/modules/mavlink_communication.dart'; import 'package:imacs/modules/get_drone_information.dart'; +import 'package:imacs/widgets/change_mode_widget.dart'; import 'package:imacs/widgets/drone_information_widget.dart'; class HomePage extends StatelessWidget { @@ -21,6 +23,11 @@ class HomePage extends StatelessWidget { DroneInformation( getDroneInformation: GetDroneInformation(comm: comm), ), + DroneModeChanger( + systemId: 1, + componentId: 1, + changeDroneMode: ChangeDroneMode(comm: comm), + ) ], ), ); diff --git a/flutter_app/lib/widgets/change_mode_widget.dart b/flutter_app/lib/widgets/change_mode_widget.dart index c8de4b0..476f385 100644 --- a/flutter_app/lib/widgets/change_mode_widget.dart +++ b/flutter_app/lib/widgets/change_mode_widget.dart @@ -1,3 +1,4 @@ +import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:dart_mavlink/dialects/common.dart'; import 'package:imacs/modules/change_drone_mode.dart'; @@ -66,8 +67,9 @@ class DroneModeChangerState extends State { setState(() { _confirmedMode = _selectedMode; }); + log("${mavModes[_selectedMode]} mode selected."); } else { - print('No mode selected'); + log('No mode selected.'); } } diff --git a/flutter_app/lib/widgets/drone_information_widget.dart b/flutter_app/lib/widgets/drone_information_widget.dart index ab9b895..063cf4f 100644 --- a/flutter_app/lib/widgets/drone_information_widget.dart +++ b/flutter_app/lib/widgets/drone_information_widget.dart @@ -24,8 +24,8 @@ class DroneInformation extends StatelessWidget { @override Widget build(BuildContext context) { return Container( - height: 500, - width: 400, + height: 400, + width: 500, decoration: BoxDecoration( border: Border.all( color: Colors.black, From ba5e24b5894c537873f166c6d9549829ff2431ce Mon Sep 17 00:00:00 2001 From: TheFJcurve Date: Mon, 8 Jul 2024 13:42:19 -0400 Subject: [PATCH 02/11] added custom log function to show drone mode --- .../lib/modules/custom_log_functions.dart | 9 +++++++++ flutter_app/lib/screens/home_screen.dart | 8 ++++---- flutter_app/lib/widgets/change_mode_widget.dart | 17 ++++++++++------- 3 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 flutter_app/lib/modules/custom_log_functions.dart diff --git a/flutter_app/lib/modules/custom_log_functions.dart b/flutter_app/lib/modules/custom_log_functions.dart new file mode 100644 index 0000000..0e09379 --- /dev/null +++ b/flutter_app/lib/modules/custom_log_functions.dart @@ -0,0 +1,9 @@ +import 'dart:developer'; + +void logDroneMode(int? currentMode, String? currentModeName) { + if (currentMode != null) { + log("$currentModeName mode selected."); + } else { + log('No mode selected.'); + } +} diff --git a/flutter_app/lib/screens/home_screen.dart b/flutter_app/lib/screens/home_screen.dart index d93fb89..1a4b7e5 100644 --- a/flutter_app/lib/screens/home_screen.dart +++ b/flutter_app/lib/screens/home_screen.dart @@ -20,14 +20,14 @@ class HomePage extends StatelessWidget { ), body: Column( children: [ - DroneInformation( - getDroneInformation: GetDroneInformation(comm: comm), - ), DroneModeChanger( systemId: 1, componentId: 1, changeDroneMode: ChangeDroneMode(comm: comm), - ) + ), + DroneInformation( + getDroneInformation: GetDroneInformation(comm: comm), + ), ], ), ); diff --git a/flutter_app/lib/widgets/change_mode_widget.dart b/flutter_app/lib/widgets/change_mode_widget.dart index 476f385..a45a74a 100644 --- a/flutter_app/lib/widgets/change_mode_widget.dart +++ b/flutter_app/lib/widgets/change_mode_widget.dart @@ -1,7 +1,7 @@ -import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:dart_mavlink/dialects/common.dart'; import 'package:imacs/modules/change_drone_mode.dart'; +import 'package:imacs/modules/custom_log_functions.dart'; /// Define the MavMode constants and their string representations. const Map mavModes = { @@ -64,13 +64,16 @@ class DroneModeChangerState extends State { widget.componentId, _selectedMode!, ); - setState(() { - _confirmedMode = _selectedMode; - }); - log("${mavModes[_selectedMode]} mode selected."); - } else { - log('No mode selected.'); + setState( + () { + _confirmedMode = _selectedMode; + }, + ); } + logDroneMode( + _selectedMode, + _selectedMode != null ? mavModes[_selectedMode] : null, + ); } @override From cb6a8557a6400f24eb2b36ca3611c4cd14a783c7 Mon Sep 17 00:00:00 2001 From: TheFJcurve Date: Tue, 9 Jul 2024 11:27:57 -0400 Subject: [PATCH 03/11] removed extra file --- flutter_app/lib/modules/custom_log_functions.dart | 9 --------- flutter_app/lib/widgets/change_mode_widget.dart | 10 +++++----- 2 files changed, 5 insertions(+), 14 deletions(-) delete mode 100644 flutter_app/lib/modules/custom_log_functions.dart diff --git a/flutter_app/lib/modules/custom_log_functions.dart b/flutter_app/lib/modules/custom_log_functions.dart deleted file mode 100644 index 0e09379..0000000 --- a/flutter_app/lib/modules/custom_log_functions.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'dart:developer'; - -void logDroneMode(int? currentMode, String? currentModeName) { - if (currentMode != null) { - log("$currentModeName mode selected."); - } else { - log('No mode selected.'); - } -} diff --git a/flutter_app/lib/widgets/change_mode_widget.dart b/flutter_app/lib/widgets/change_mode_widget.dart index a45a74a..d3f3974 100644 --- a/flutter_app/lib/widgets/change_mode_widget.dart +++ b/flutter_app/lib/widgets/change_mode_widget.dart @@ -1,7 +1,8 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; import 'package:dart_mavlink/dialects/common.dart'; import 'package:imacs/modules/change_drone_mode.dart'; -import 'package:imacs/modules/custom_log_functions.dart'; /// Define the MavMode constants and their string representations. const Map mavModes = { @@ -69,11 +70,10 @@ class DroneModeChangerState extends State { _confirmedMode = _selectedMode; }, ); + log("${mavModes[_selectedMode]} mode selected."); + } else { + log('No mode selected.'); } - logDroneMode( - _selectedMode, - _selectedMode != null ? mavModes[_selectedMode] : null, - ); } @override From e14ff667d7f539c41be6c675c49668d06b872053 Mon Sep 17 00:00:00 2001 From: TheFJcurve Date: Tue, 9 Jul 2024 11:33:40 -0400 Subject: [PATCH 04/11] added a log when a new waypoint is created --- .../lib/command_constructors/create_waypoint_constructor.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flutter_app/lib/command_constructors/create_waypoint_constructor.dart b/flutter_app/lib/command_constructors/create_waypoint_constructor.dart index 9b90ea6..1b31ae0 100644 --- a/flutter_app/lib/command_constructors/create_waypoint_constructor.dart +++ b/flutter_app/lib/command_constructors/create_waypoint_constructor.dart @@ -1,4 +1,5 @@ import 'package:dart_mavlink/dialects/common.dart'; +import 'dart:developer'; /// Constructs a MissionItem command to create a new waypoint using MAV_CMD_NAV_WAYPOINT (16). /// @@ -38,5 +39,7 @@ MissionItem createWaypoint(int sequence, int systemID, int componentID, missionType: mavMissionTypeMission, ); + log('Created a waypoint at ($latitude, $longitude)'); + return missionItem; } From 2d21600ba36c712fa39106ee955f2e8f45e2e36c Mon Sep 17 00:00:00 2001 From: TheFJcurve Date: Tue, 9 Jul 2024 11:41:30 -0400 Subject: [PATCH 05/11] added log for drone information and drone mode --- flutter_app/lib/widgets/change_mode_widget.dart | 6 ++++++ flutter_app/lib/widgets/drone_information_widget.dart | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/flutter_app/lib/widgets/change_mode_widget.dart b/flutter_app/lib/widgets/change_mode_widget.dart index d3f3974..3899964 100644 --- a/flutter_app/lib/widgets/change_mode_widget.dart +++ b/flutter_app/lib/widgets/change_mode_widget.dart @@ -78,6 +78,12 @@ class DroneModeChangerState extends State { @override Widget build(BuildContext context) { + // This method will be executed after widget will be completed. + Future.delayed(Duration.zero, () { + log('Change Drone Mode Widget rendered completely!'); + }); + + // return of the build method return Column( children: [ DropdownMenu( diff --git a/flutter_app/lib/widgets/drone_information_widget.dart b/flutter_app/lib/widgets/drone_information_widget.dart index 063cf4f..6bffeb0 100644 --- a/flutter_app/lib/widgets/drone_information_widget.dart +++ b/flutter_app/lib/widgets/drone_information_widget.dart @@ -1,4 +1,5 @@ import 'dart:math'; +import 'dart:developer' as developer; import 'package:flutter/material.dart'; import 'package:imacs/modules/get_drone_information.dart'; import 'package:imacs/widgets/data_field_widget.dart'; @@ -23,6 +24,12 @@ class DroneInformation extends StatelessWidget { @override Widget build(BuildContext context) { + // This method will be executed after widget will be completed. + Future.delayed(Duration.zero, () { + developer.log('Drone Information Widget rendered completely!'); + }); + + // return of the build method return Container( height: 400, width: 500, From 065848e7b86c101c8f227d2a62a70b7112bb9319 Mon Sep 17 00:00:00 2001 From: TheFJcurve Date: Tue, 9 Jul 2024 14:23:41 -0400 Subject: [PATCH 06/11] added logs for object creation --- .../lib/widgets/change_mode_widget.dart | 12 +++---- .../lib/widgets/drone_information_widget.dart | 31 +++++++++++-------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/flutter_app/lib/widgets/change_mode_widget.dart b/flutter_app/lib/widgets/change_mode_widget.dart index 3899964..6e9936a 100644 --- a/flutter_app/lib/widgets/change_mode_widget.dart +++ b/flutter_app/lib/widgets/change_mode_widget.dart @@ -77,13 +77,13 @@ class DroneModeChangerState extends State { } @override - Widget build(BuildContext context) { - // This method will be executed after widget will be completed. - Future.delayed(Duration.zero, () { - log('Change Drone Mode Widget rendered completely!'); - }); + void initState() { + log('Change Drone Mode Widget rendered completely!'); + super.initState(); + } - // return of the build method + @override + Widget build(BuildContext context) { return Column( children: [ DropdownMenu( diff --git a/flutter_app/lib/widgets/drone_information_widget.dart b/flutter_app/lib/widgets/drone_information_widget.dart index 6bffeb0..43e818d 100644 --- a/flutter_app/lib/widgets/drone_information_widget.dart +++ b/flutter_app/lib/widgets/drone_information_widget.dart @@ -9,7 +9,7 @@ import 'package:imacs/widgets/data_field_widget.dart'; /// This widget selective data made available by MavlinkgetDroneInformationunication. /// Arranges the data in a grid with two columns and applies a border. /// -class DroneInformation extends StatelessWidget { +class DroneInformation extends StatefulWidget { /// @brief Constructs a DroneInformation widget. /// /// @param getDroneInformation The communication channel (MAVLink) where to get @@ -23,13 +23,18 @@ class DroneInformation extends StatelessWidget { final GetDroneInformation getDroneInformation; @override - Widget build(BuildContext context) { - // This method will be executed after widget will be completed. - Future.delayed(Duration.zero, () { - developer.log('Drone Information Widget rendered completely!'); - }); + State createState() => _DroneInformationState(); +} - // return of the build method +class _DroneInformationState extends State { + @override + void initState() { + developer.log('Drone Information Widget rendered completely!'); + super.initState(); + } + + @override + Widget build(BuildContext context) { return Container( height: 400, width: 500, @@ -48,36 +53,36 @@ class DroneInformation extends StatelessWidget { children: [ DataField( name: 'Yaw (deg)', - value: getDroneInformation.getYawStream(), + value: widget.getDroneInformation.getYawStream(), formatter: (double value) => (value / pi * 180.0).toStringAsFixed(2), ), DataField( name: 'Pitch (deg)', - value: getDroneInformation.getPitchStream(), + value: widget.getDroneInformation.getPitchStream(), formatter: (double value) => (value / pi * 180.0).toStringAsFixed(2), ), DataField( name: 'Roll (deg)', - value: getDroneInformation.getRollStream(), + value: widget.getDroneInformation.getRollStream(), formatter: (double value) => (value / pi * 180.0).toStringAsFixed(2), ), // global position DataField( name: 'Latitude', - value: getDroneInformation.getLatStream(), + value: widget.getDroneInformation.getLatStream(), formatter: (int value) => (value / 1e7).toStringAsFixed(2), ), DataField( name: 'Longitude', - value: getDroneInformation.getLonStream(), + value: widget.getDroneInformation.getLonStream(), formatter: (int value) => (value / 1e7).toStringAsFixed(2), ), DataField( name: 'Altitude (m)', - value: getDroneInformation.getAltStream(), + value: widget.getDroneInformation.getAltStream(), formatter: (int value) => (value / 1e3).toStringAsFixed(2), ), ], From c67371f0df91b553a14b2b5e6e15854e63d4fdcf Mon Sep 17 00:00:00 2001 From: TheFJcurve Date: Wed, 10 Jul 2024 10:42:25 -0400 Subject: [PATCH 07/11] moved over logs to modules, added logs for comm --- flutter_app/.metadata | 15 +++++++++++++++ .../create_waypoint_constructor.dart | 3 --- .../lib/modules/mavlink_communication.dart | 13 +++++++++++-- flutter_app/lib/modules/queue_waypoints.dart | 3 +++ flutter_app/lib/widgets/change_mode_widget.dart | 2 +- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/flutter_app/.metadata b/flutter_app/.metadata index 5d1ebe4..0122ae4 100644 --- a/flutter_app/.metadata +++ b/flutter_app/.metadata @@ -15,9 +15,24 @@ migration: - platform: root create_revision: 34ab5378801b427adf2224f23d488961e7dd746f base_revision: 34ab5378801b427adf2224f23d488961e7dd746f + - platform: android + create_revision: 34ab5378801b427adf2224f23d488961e7dd746f + base_revision: 34ab5378801b427adf2224f23d488961e7dd746f + - platform: ios + create_revision: 34ab5378801b427adf2224f23d488961e7dd746f + base_revision: 34ab5378801b427adf2224f23d488961e7dd746f + - platform: linux + create_revision: 34ab5378801b427adf2224f23d488961e7dd746f + base_revision: 34ab5378801b427adf2224f23d488961e7dd746f - platform: macos create_revision: 34ab5378801b427adf2224f23d488961e7dd746f base_revision: 34ab5378801b427adf2224f23d488961e7dd746f + - platform: web + create_revision: 34ab5378801b427adf2224f23d488961e7dd746f + base_revision: 34ab5378801b427adf2224f23d488961e7dd746f + - platform: windows + create_revision: 34ab5378801b427adf2224f23d488961e7dd746f + base_revision: 34ab5378801b427adf2224f23d488961e7dd746f # User provided section diff --git a/flutter_app/lib/command_constructors/create_waypoint_constructor.dart b/flutter_app/lib/command_constructors/create_waypoint_constructor.dart index 1b31ae0..9b90ea6 100644 --- a/flutter_app/lib/command_constructors/create_waypoint_constructor.dart +++ b/flutter_app/lib/command_constructors/create_waypoint_constructor.dart @@ -1,5 +1,4 @@ import 'package:dart_mavlink/dialects/common.dart'; -import 'dart:developer'; /// Constructs a MissionItem command to create a new waypoint using MAV_CMD_NAV_WAYPOINT (16). /// @@ -39,7 +38,5 @@ MissionItem createWaypoint(int sequence, int systemID, int componentID, missionType: mavMissionTypeMission, ); - log('Created a waypoint at ($latitude, $longitude)'); - return missionItem; } diff --git a/flutter_app/lib/modules/mavlink_communication.dart b/flutter_app/lib/modules/mavlink_communication.dart index e1589af..3dfef80 100644 --- a/flutter_app/lib/modules/mavlink_communication.dart +++ b/flutter_app/lib/modules/mavlink_communication.dart @@ -52,9 +52,11 @@ class MavlinkCommunication { switch (_connectionType) { case MavlinkCommunicationType.tcp: _startupTcpPort(connectionAddress, tcpPort); + log('Started listening for a TCP connection'); break; case MavlinkCommunicationType.serial: _startupSerialPort(connectionAddress); + log('Started listening for a Serial connection'); break; } @@ -67,12 +69,12 @@ class MavlinkCommunication { _tcpSocket.listen((Uint8List data) { _parser.parse(data); }, onError: (error) { - // print if log does not work, I can't really test it, just avoid the warning - log(error); + log('ERROR: $error'); _tcpSocket.destroy(); }); _tcpSocketInitializationFlag.complete(); + log('TCP Port successfully initialized!'); } _startupSerialPort(String connectionAddress) { @@ -82,15 +84,22 @@ class MavlinkCommunication { _stream = serialPortReader.stream; _stream.listen((Uint8List data) { _parser.parse(data); + }, onError: (error) { + log('ERROR: $error'); + _serialPort.dispose(); }); + + log('Serial Port successfully initialized!'); } _writeToTcpPort(MavlinkFrame frame) { _tcpSocket.write(frame.serialize()); + log('Wrote a message to TCP Port'); } _writeToSerialPort(MavlinkFrame frame) { _serialPort.write(frame.serialize()); + log('Wrote a message to Serial Port'); } _parseMavlinkMessage() { diff --git a/flutter_app/lib/modules/queue_waypoints.dart b/flutter_app/lib/modules/queue_waypoints.dart index 241956b..89a1341 100644 --- a/flutter_app/lib/modules/queue_waypoints.dart +++ b/flutter_app/lib/modules/queue_waypoints.dart @@ -2,6 +2,7 @@ import 'package:dart_mavlink/mavlink.dart'; import 'package:imacs/modules/mavlink_communication.dart'; import 'package:imacs/command_constructors/create_waypoint_constructor.dart'; import 'package:dart_mavlink/dialects/common.dart'; +import 'dart:developer'; class QueueWaypoints { final MavlinkCommunication comm; @@ -23,6 +24,8 @@ class QueueWaypoints { newWaypoint.targetComponent, newWaypoint); comm.sequence++; comm.write(frame); + + log('Created a waypoint at ($latitude, $longitude)'); } /// Queues a waypoint to be sent. diff --git a/flutter_app/lib/widgets/change_mode_widget.dart b/flutter_app/lib/widgets/change_mode_widget.dart index 6e9936a..9d25c6b 100644 --- a/flutter_app/lib/widgets/change_mode_widget.dart +++ b/flutter_app/lib/widgets/change_mode_widget.dart @@ -72,7 +72,7 @@ class DroneModeChangerState extends State { ); log("${mavModes[_selectedMode]} mode selected."); } else { - log('No mode selected.'); + log('ERROR: No mode selected.'); } } From f97ed7bfcab8d1eef284498d7fdb7152a923fd4e Mon Sep 17 00:00:00 2001 From: TheFJcurve Date: Mon, 15 Jul 2024 11:19:51 -0400 Subject: [PATCH 08/11] log changes --- .../lib/modules/change_drone_mode.dart | 5 ++++ .../lib/modules/mavlink_communication.dart | 10 ++++--- flutter_app/lib/modules/queue_waypoints.dart | 5 +++- .../lib/widgets/change_mode_widget.dart | 6 ----- .../lib/widgets/drone_information_widget.dart | 26 +++++-------------- 5 files changed, 22 insertions(+), 30 deletions(-) diff --git a/flutter_app/lib/modules/change_drone_mode.dart b/flutter_app/lib/modules/change_drone_mode.dart index eda400b..ffd3a40 100644 --- a/flutter_app/lib/modules/change_drone_mode.dart +++ b/flutter_app/lib/modules/change_drone_mode.dart @@ -1,6 +1,9 @@ import 'package:dart_mavlink/dialects/common.dart'; import 'package:imacs/modules/mavlink_communication.dart'; import 'package:imacs/command_constructors/set_mode_constructor.dart'; +import 'dart:developer'; + +import 'package:imacs/widgets/change_mode_widget.dart'; class ChangeDroneMode { final MavlinkCommunication comm; @@ -15,5 +18,7 @@ class ChangeDroneMode { var frame = setMode(comm.sequence, systemID, componentID, baseMode); comm.sequence++; comm.write(frame); + + log('${mavModes[baseMode]} mode set.'); } } diff --git a/flutter_app/lib/modules/mavlink_communication.dart b/flutter_app/lib/modules/mavlink_communication.dart index 3dfef80..74370cc 100644 --- a/flutter_app/lib/modules/mavlink_communication.dart +++ b/flutter_app/lib/modules/mavlink_communication.dart @@ -51,12 +51,12 @@ class MavlinkCommunication { _connectionType = connectionType { switch (_connectionType) { case MavlinkCommunicationType.tcp: + // Trying to start TCP connection _startupTcpPort(connectionAddress, tcpPort); - log('Started listening for a TCP connection'); break; case MavlinkCommunicationType.serial: + // Trying to start Serial connection _startupSerialPort(connectionAddress); - log('Started listening for a Serial connection'); break; } @@ -94,12 +94,14 @@ class MavlinkCommunication { _writeToTcpPort(MavlinkFrame frame) { _tcpSocket.write(frame.serialize()); - log('Wrote a message to TCP Port'); + log('Wrote a message to TCP Port. Frame ID: ${frame.componentId}'); + log('Message: ${frame.message}'); } _writeToSerialPort(MavlinkFrame frame) { _serialPort.write(frame.serialize()); - log('Wrote a message to Serial Port'); + log('Wrote a message to Serial Port. Frame ID: ${frame.componentId}'); + log('Message: ${frame.message}'); } _parseMavlinkMessage() { diff --git a/flutter_app/lib/modules/queue_waypoints.dart b/flutter_app/lib/modules/queue_waypoints.dart index 89a1341..ab10420 100644 --- a/flutter_app/lib/modules/queue_waypoints.dart +++ b/flutter_app/lib/modules/queue_waypoints.dart @@ -25,7 +25,7 @@ class QueueWaypoints { comm.sequence++; comm.write(frame); - log('Created a waypoint at ($latitude, $longitude)'); + log('Added a waypoint at (Latitude: $latitude, Longitude: $longitude, Altitude: $altitude).'); } /// Queues a waypoint to be sent. @@ -36,6 +36,8 @@ class QueueWaypoints { comm.sequence, systemID, componentID, latitude, longitude, altitude); comm.sequence++; waypointQueue.add(newWaypoint); + + log('Queued a waypoint to be sent at (Latitude: $latitude, Longitude: $longitude, Altitude: $altitude).'); } /// Takes first waypoint in the queue and send its to the drone @@ -49,6 +51,7 @@ class QueueWaypoints { var frame = MavlinkFrame.v2(waypoint.seq, waypoint.targetSystem, waypoint.targetComponent, waypoint); comm.write(frame); + log('Sent waypoint to the drone from the queue (Latitude: ${waypoint.x}, Longitude: ${waypoint.y}, Altitude: ${waypoint.z}).'); } } } diff --git a/flutter_app/lib/widgets/change_mode_widget.dart b/flutter_app/lib/widgets/change_mode_widget.dart index 9d25c6b..e336c0d 100644 --- a/flutter_app/lib/widgets/change_mode_widget.dart +++ b/flutter_app/lib/widgets/change_mode_widget.dart @@ -76,12 +76,6 @@ class DroneModeChangerState extends State { } } - @override - void initState() { - log('Change Drone Mode Widget rendered completely!'); - super.initState(); - } - @override Widget build(BuildContext context) { return Column( diff --git a/flutter_app/lib/widgets/drone_information_widget.dart b/flutter_app/lib/widgets/drone_information_widget.dart index 43e818d..063cf4f 100644 --- a/flutter_app/lib/widgets/drone_information_widget.dart +++ b/flutter_app/lib/widgets/drone_information_widget.dart @@ -1,5 +1,4 @@ import 'dart:math'; -import 'dart:developer' as developer; import 'package:flutter/material.dart'; import 'package:imacs/modules/get_drone_information.dart'; import 'package:imacs/widgets/data_field_widget.dart'; @@ -9,7 +8,7 @@ import 'package:imacs/widgets/data_field_widget.dart'; /// This widget selective data made available by MavlinkgetDroneInformationunication. /// Arranges the data in a grid with two columns and applies a border. /// -class DroneInformation extends StatefulWidget { +class DroneInformation extends StatelessWidget { /// @brief Constructs a DroneInformation widget. /// /// @param getDroneInformation The communication channel (MAVLink) where to get @@ -22,17 +21,6 @@ class DroneInformation extends StatefulWidget { final GetDroneInformation getDroneInformation; - @override - State createState() => _DroneInformationState(); -} - -class _DroneInformationState extends State { - @override - void initState() { - developer.log('Drone Information Widget rendered completely!'); - super.initState(); - } - @override Widget build(BuildContext context) { return Container( @@ -53,36 +41,36 @@ class _DroneInformationState extends State { children: [ DataField( name: 'Yaw (deg)', - value: widget.getDroneInformation.getYawStream(), + value: getDroneInformation.getYawStream(), formatter: (double value) => (value / pi * 180.0).toStringAsFixed(2), ), DataField( name: 'Pitch (deg)', - value: widget.getDroneInformation.getPitchStream(), + value: getDroneInformation.getPitchStream(), formatter: (double value) => (value / pi * 180.0).toStringAsFixed(2), ), DataField( name: 'Roll (deg)', - value: widget.getDroneInformation.getRollStream(), + value: getDroneInformation.getRollStream(), formatter: (double value) => (value / pi * 180.0).toStringAsFixed(2), ), // global position DataField( name: 'Latitude', - value: widget.getDroneInformation.getLatStream(), + value: getDroneInformation.getLatStream(), formatter: (int value) => (value / 1e7).toStringAsFixed(2), ), DataField( name: 'Longitude', - value: widget.getDroneInformation.getLonStream(), + value: getDroneInformation.getLonStream(), formatter: (int value) => (value / 1e7).toStringAsFixed(2), ), DataField( name: 'Altitude (m)', - value: widget.getDroneInformation.getAltStream(), + value: getDroneInformation.getAltStream(), formatter: (int value) => (value / 1e3).toStringAsFixed(2), ), ], From 900e773fcf60844077bf35fb53f987f92bdfe7e6 Mon Sep 17 00:00:00 2001 From: TheFJcurve Date: Tue, 16 Jul 2024 16:30:29 -0400 Subject: [PATCH 09/11] made pr changes --- .../lib/modules/change_drone_mode.dart | 19 ++++++++++++++-- .../lib/modules/mavlink_communication.dart | 22 ++++++++++--------- flutter_app/lib/modules/queue_waypoints.dart | 8 ++++--- .../lib/widgets/change_mode_widget.dart | 19 +++------------- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/flutter_app/lib/modules/change_drone_mode.dart b/flutter_app/lib/modules/change_drone_mode.dart index ffd3a40..633bb39 100644 --- a/flutter_app/lib/modules/change_drone_mode.dart +++ b/flutter_app/lib/modules/change_drone_mode.dart @@ -3,7 +3,22 @@ import 'package:imacs/modules/mavlink_communication.dart'; import 'package:imacs/command_constructors/set_mode_constructor.dart'; import 'dart:developer'; -import 'package:imacs/widgets/change_mode_widget.dart'; +const String moduleName = "Change Drone Mode"; + +/// Define the MavMode constants and their string representations. +const Map mavModes = { + mavModePreflight: "Preflight", + mavModeManualDisarmed: "Manual Disarmed", + mavModeTestDisarmed: "Test Disarmed", + mavModeStabilizeDisarmed: "Stabilize Disarmed", + mavModeGuidedDisarmed: "Guided Disarmed", + mavModeAutoDisarmed: "Auto Disarmed", + mavModeManualArmed: "Manual Armed", + mavModeTestArmed: "Test Armed", + mavModeStabilizeArmed: "Stabilize Armed", + mavModeGuidedArmed: "Guided Armed", + mavModeAutoArmed: "Auto Armed", +}; class ChangeDroneMode { final MavlinkCommunication comm; @@ -19,6 +34,6 @@ class ChangeDroneMode { comm.sequence++; comm.write(frame); - log('${mavModes[baseMode]} mode set.'); + log('[$moduleName]: ${mavModes[baseMode]} mode set.'); } } diff --git a/flutter_app/lib/modules/mavlink_communication.dart b/flutter_app/lib/modules/mavlink_communication.dart index 74370cc..abb6aba 100644 --- a/flutter_app/lib/modules/mavlink_communication.dart +++ b/flutter_app/lib/modules/mavlink_communication.dart @@ -6,6 +6,8 @@ import 'package:flutter_libserialport/flutter_libserialport.dart'; import 'package:dart_mavlink/mavlink.dart'; import 'package:dart_mavlink/dialects/common.dart'; +const String moduleName = "Mavlink Communication"; + enum MavlinkCommunicationType { tcp, serial, @@ -51,11 +53,11 @@ class MavlinkCommunication { _connectionType = connectionType { switch (_connectionType) { case MavlinkCommunicationType.tcp: - // Trying to start TCP connection + log('[$moduleName] Trying to start TCP connection'); _startupTcpPort(connectionAddress, tcpPort); break; case MavlinkCommunicationType.serial: - // Trying to start Serial connection + log('[$moduleName] Trying to start Serial connection'); _startupSerialPort(connectionAddress); break; } @@ -69,12 +71,12 @@ class MavlinkCommunication { _tcpSocket.listen((Uint8List data) { _parser.parse(data); }, onError: (error) { - log('ERROR: $error'); + log('[$moduleName] ERROR: $error'); _tcpSocket.destroy(); }); _tcpSocketInitializationFlag.complete(); - log('TCP Port successfully initialized!'); + log('[$moduleName] TCP Port successfully initialized!'); } _startupSerialPort(String connectionAddress) { @@ -85,23 +87,23 @@ class MavlinkCommunication { _stream.listen((Uint8List data) { _parser.parse(data); }, onError: (error) { - log('ERROR: $error'); + log('[$moduleName] ERROR: $error'); _serialPort.dispose(); }); - log('Serial Port successfully initialized!'); + log('[$moduleName] Serial Port successfully initialized!'); } _writeToTcpPort(MavlinkFrame frame) { _tcpSocket.write(frame.serialize()); - log('Wrote a message to TCP Port. Frame ID: ${frame.componentId}'); - log('Message: ${frame.message}'); + log('[$moduleName] Wrote a message to TCP Port. Frame ID: ${frame.componentId}'); + log('[$moduleName] Message: ${frame.message}'); } _writeToSerialPort(MavlinkFrame frame) { _serialPort.write(frame.serialize()); - log('Wrote a message to Serial Port. Frame ID: ${frame.componentId}'); - log('Message: ${frame.message}'); + log('[$moduleName] Wrote a message to Serial Port. Frame ID: ${frame.componentId}'); + log('[$moduleName] Message: ${frame.message}'); } _parseMavlinkMessage() { diff --git a/flutter_app/lib/modules/queue_waypoints.dart b/flutter_app/lib/modules/queue_waypoints.dart index ab10420..75f1dc5 100644 --- a/flutter_app/lib/modules/queue_waypoints.dart +++ b/flutter_app/lib/modules/queue_waypoints.dart @@ -4,6 +4,8 @@ import 'package:imacs/command_constructors/create_waypoint_constructor.dart'; import 'package:dart_mavlink/dialects/common.dart'; import 'dart:developer'; +const String moduleName = "Queue Waypoints"; + class QueueWaypoints { final MavlinkCommunication comm; @@ -25,7 +27,7 @@ class QueueWaypoints { comm.sequence++; comm.write(frame); - log('Added a waypoint at (Latitude: $latitude, Longitude: $longitude, Altitude: $altitude).'); + log('[$moduleName] Added a waypoint at (Latitude: $latitude, Longitude: $longitude, Altitude: $altitude).'); } /// Queues a waypoint to be sent. @@ -37,7 +39,7 @@ class QueueWaypoints { comm.sequence++; waypointQueue.add(newWaypoint); - log('Queued a waypoint to be sent at (Latitude: $latitude, Longitude: $longitude, Altitude: $altitude).'); + log('[$moduleName] Queued a waypoint to be sent at (Latitude: $latitude, Longitude: $longitude, Altitude: $altitude).'); } /// Takes first waypoint in the queue and send its to the drone @@ -51,7 +53,7 @@ class QueueWaypoints { var frame = MavlinkFrame.v2(waypoint.seq, waypoint.targetSystem, waypoint.targetComponent, waypoint); comm.write(frame); - log('Sent waypoint to the drone from the queue (Latitude: ${waypoint.x}, Longitude: ${waypoint.y}, Altitude: ${waypoint.z}).'); + log('[$moduleName] Sent waypoint to the drone from the queue (Latitude: ${waypoint.x}, Longitude: ${waypoint.y}, Altitude: ${waypoint.z}).'); } } } diff --git a/flutter_app/lib/widgets/change_mode_widget.dart b/flutter_app/lib/widgets/change_mode_widget.dart index e336c0d..b7fb619 100644 --- a/flutter_app/lib/widgets/change_mode_widget.dart +++ b/flutter_app/lib/widgets/change_mode_widget.dart @@ -4,20 +4,7 @@ import 'package:flutter/material.dart'; import 'package:dart_mavlink/dialects/common.dart'; import 'package:imacs/modules/change_drone_mode.dart'; -/// Define the MavMode constants and their string representations. -const Map mavModes = { - mavModePreflight: "Preflight", - mavModeManualDisarmed: "Manual Disarmed", - mavModeTestDisarmed: "Test Disarmed", - mavModeStabilizeDisarmed: "Stabilize Disarmed", - mavModeGuidedDisarmed: "Guided Disarmed", - mavModeAutoDisarmed: "Auto Disarmed", - mavModeManualArmed: "Manual Armed", - mavModeTestArmed: "Test Armed", - mavModeStabilizeArmed: "Stabilize Armed", - mavModeGuidedArmed: "Guided Armed", - mavModeAutoArmed: "Auto Armed", -}; +const String moduleName = "Change Drone Mode Widget"; /// Widget to change the mode of a drone using MAVLink communication. /// @@ -70,9 +57,9 @@ class DroneModeChangerState extends State { _confirmedMode = _selectedMode; }, ); - log("${mavModes[_selectedMode]} mode selected."); + log("[$moduleName] ${mavModes[_selectedMode]} mode selected."); } else { - log('ERROR: No mode selected.'); + log('[$moduleName] ERROR: No mode selected.'); } } From 5fbd4b68500aac027034c04a9aed849877209214 Mon Sep 17 00:00:00 2001 From: TheFJcurve Date: Tue, 16 Jul 2024 16:31:06 -0400 Subject: [PATCH 10/11] restored home screen --- flutter_app/lib/screens/home_screen.dart | 7 ------- 1 file changed, 7 deletions(-) diff --git a/flutter_app/lib/screens/home_screen.dart b/flutter_app/lib/screens/home_screen.dart index 1a4b7e5..93f369c 100644 --- a/flutter_app/lib/screens/home_screen.dart +++ b/flutter_app/lib/screens/home_screen.dart @@ -1,8 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:imacs/modules/change_drone_mode.dart'; import 'package:imacs/modules/mavlink_communication.dart'; import 'package:imacs/modules/get_drone_information.dart'; -import 'package:imacs/widgets/change_mode_widget.dart'; import 'package:imacs/widgets/drone_information_widget.dart'; class HomePage extends StatelessWidget { @@ -20,11 +18,6 @@ class HomePage extends StatelessWidget { ), body: Column( children: [ - DroneModeChanger( - systemId: 1, - componentId: 1, - changeDroneMode: ChangeDroneMode(comm: comm), - ), DroneInformation( getDroneInformation: GetDroneInformation(comm: comm), ), From a99975a5464795a7ba65ea557f7af874099ea611 Mon Sep 17 00:00:00 2001 From: TheFJcurve Date: Tue, 16 Jul 2024 22:42:07 -0400 Subject: [PATCH 11/11] mega big huge change --- flutter_app/lib/widgets/change_mode_widget.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flutter_app/lib/widgets/change_mode_widget.dart b/flutter_app/lib/widgets/change_mode_widget.dart index b7fb619..6dfc43c 100644 --- a/flutter_app/lib/widgets/change_mode_widget.dart +++ b/flutter_app/lib/widgets/change_mode_widget.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; import 'package:dart_mavlink/dialects/common.dart'; import 'package:imacs/modules/change_drone_mode.dart'; -const String moduleName = "Change Drone Mode Widget"; +const String widgetName = "Change Drone Mode Widget"; /// Widget to change the mode of a drone using MAVLink communication. /// @@ -57,9 +57,9 @@ class DroneModeChangerState extends State { _confirmedMode = _selectedMode; }, ); - log("[$moduleName] ${mavModes[_selectedMode]} mode selected."); + log("[$widgetName] ${mavModes[_selectedMode]} mode selected."); } else { - log('[$moduleName] ERROR: No mode selected.'); + log('[$widgetName] ERROR: No mode selected.'); } }