Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console log updates #24

Merged
merged 12 commits into from
Jul 17, 2024
15 changes: 15 additions & 0 deletions flutter_app/.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions flutter_app/lib/modules/change_drone_mode.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
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';

const String moduleName = "Change Drone Mode";

/// Define the MavMode constants and their string representations.
const Map<int, String> 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;
Expand All @@ -15,5 +33,7 @@ class ChangeDroneMode {
var frame = setMode(comm.sequence, systemID, componentID, baseMode);
comm.sequence++;
comm.write(frame);

log('[$moduleName]: ${mavModes[baseMode]} mode set.');
}
}
18 changes: 16 additions & 2 deletions flutter_app/lib/modules/mavlink_communication.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
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';
import 'package:dart_mavlink/dialects/common.dart';

const String moduleName = "Mavlink Communication";

enum MavlinkCommunicationType {
tcp,
serial,
Expand Down Expand Up @@ -50,9 +53,11 @@ class MavlinkCommunication {
_connectionType = connectionType {
switch (_connectionType) {
case MavlinkCommunicationType.tcp:
log('[$moduleName] Trying to start TCP connection');
_startupTcpPort(connectionAddress, tcpPort);
BalajiLeninrajan marked this conversation as resolved.
Show resolved Hide resolved
break;
case MavlinkCommunicationType.serial:
log('[$moduleName] Trying to start Serial connection');
_startupSerialPort(connectionAddress);
break;
}
Expand All @@ -66,12 +71,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
print(error);
log('[$moduleName] ERROR: $error');
_tcpSocket.destroy();
});

_tcpSocketInitializationFlag.complete();
log('[$moduleName] TCP Port successfully initialized!');
}

_startupSerialPort(String connectionAddress) {
Expand All @@ -81,15 +86,24 @@ class MavlinkCommunication {
_stream = serialPortReader.stream;
_stream.listen((Uint8List data) {
_parser.parse(data);
}, onError: (error) {
log('[$moduleName] ERROR: $error');
_serialPort.dispose();
});

log('[$moduleName] Serial Port successfully initialized!');
}

_writeToTcpPort(MavlinkFrame frame) {
_tcpSocket.write(frame.serialize());
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('[$moduleName] Wrote a message to Serial Port. Frame ID: ${frame.componentId}');
log('[$moduleName] Message: ${frame.message}');
}

_parseMavlinkMessage() {
Expand Down
8 changes: 8 additions & 0 deletions flutter_app/lib/modules/queue_waypoints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ 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';

const String moduleName = "Queue Waypoints";

class QueueWaypoints {
final MavlinkCommunication comm;
Expand All @@ -23,6 +26,8 @@ class QueueWaypoints {
newWaypoint.targetComponent, newWaypoint);
comm.sequence++;
comm.write(frame);

log('[$moduleName] Added a waypoint at (Latitude: $latitude, Longitude: $longitude, Altitude: $altitude).');
}

BalajiLeninrajan marked this conversation as resolved.
Show resolved Hide resolved
/// Queues a waypoint to be sent.
Expand All @@ -33,6 +38,8 @@ class QueueWaypoints {
comm.sequence, systemID, componentID, latitude, longitude, altitude);
comm.sequence++;
waypointQueue.add(newWaypoint);

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
Expand All @@ -46,6 +53,7 @@ class QueueWaypoints {
var frame = MavlinkFrame.v2(waypoint.seq, waypoint.targetSystem,
waypoint.targetComponent, waypoint);
comm.write(frame);
log('[$moduleName] Sent waypoint to the drone from the queue (Latitude: ${waypoint.x}, Longitude: ${waypoint.y}, Altitude: ${waypoint.z}).');
}
}
}
28 changes: 10 additions & 18 deletions flutter_app/lib/widgets/change_mode_widget.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import 'dart:developer';

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<int, String> 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 widgetName = "Change Drone Mode Widget";

/// Widget to change the mode of a drone using MAVLink communication.
///
Expand Down Expand Up @@ -63,11 +52,14 @@ class DroneModeChangerState extends State<DroneModeChanger> {
widget.componentId,
_selectedMode!,
);
setState(() {
_confirmedMode = _selectedMode;
});
setState(
() {
_confirmedMode = _selectedMode;
},
);
log("[$widgetName] ${mavModes[_selectedMode]} mode selected.");
} else {
print('No mode selected');
log('[$widgetName] ERROR: No mode selected.');
}
}

Expand Down
4 changes: 2 additions & 2 deletions flutter_app/lib/widgets/drone_information_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down