Skip to content

Commit

Permalink
IMU Code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bing-Rover committed Nov 2, 2023
1 parent 06e96d0 commit 26ca1a6
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 9 deletions.
39 changes: 30 additions & 9 deletions bin/serial.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
import "dart:convert";

import 'package:osc/osc.dart';
import "dart:typed_data";
import "package:subsystems/subsystems.dart";
import "package:burt_network/logging.dart";

const port = "COM11";
const port = "/dev/ttyACM0";

// void printXYZ(List<int> data) {
// data = data.sublist(20);
// String message = utf8.decode(data, allowMalformed: true);
// logger.info("Received: $data");
// print("Message: ${message}");
// try {
// final message = OSCMessage.fromBytes(data);
// print (message);
// } catch (error) {
// print("Invalid message. Got error: $error");
// }
// }

// void main() async {
// final device = SerialDevice(
// portName: port,
// readInterval: const Duration(milliseconds: 500),
// );
// device.open();
// device.stream.listen(printXYZ);
// // device.write(Uint8List.fromList([1, 2, 3]));
// }

void main() async {
final device = SerialDevice(
portName: port,
readInterval: const Duration(milliseconds: 100),
);
device.open();
device.stream.listen((data) => logger.info("Received: $data"));
device.write(Uint8List.fromList([1, 2, 3]));
void main() {
reader = ImuReader(stdin);
reader.init();
}
49 changes: 49 additions & 0 deletions lib/src/serial/imu.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import "dart:convert";

import 'package:osc/osc.dart';
import "dart:typed_data";
import "package:subsystems/subsystems.dart";
import "package:burt_network/logging.dart";

const port = "/dev/ttyACM0";

class ImuReader {
final String port;

ImuReader(this.port);

void printXYZ(List <int> data){

data = data.sublist(20);
String message = utf8.decode(data, allowMalformed: true);

logger.info("Received: $data");

print("Message: ${message}");

try {

final message = OSCMessage.fromBytes(data);
print (message);

} catch (error) {

print("Invalid message. Got error: $error");

}
}

void init() {
final Stream<List<int>> inputStream;
ImuReader(this.inputStream);

void intit() {
inputStream.listen(printXYZ);
}
}
void dispose() {
ImuReader.dispose();
logger.info("ImuReader disposed");

}
}
2 changes: 2 additions & 0 deletions lib/subsystems.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "package:subsystems/can.dart";
import "src/server.dart";

export "src/server.dart";
export "src/serial/imu.dart";
export "src/serial/serial.dart";

/// Contains all the resources needed by the subsystems program.
Expand All @@ -15,6 +16,7 @@ class SubsystemsCollection {

/// Initializes all the resources needed by the subsystems.
Future<void> init() async {
BurtLogger.level = LogLevel.debug;
logger.debug("Running in debug mode...");
can.init();
await server.init();
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.2"
osc:
dependency: "direct main"
description:
name: osc
sha256: "5252beff07c0ecb1e94af5cd5e2b1fefe80c10367c5d49fadfef2c9986e9969b"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
package_config:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
git: https://github.com/BinghamtonRover/Networking.git
ffi: ^2.0.2
libserialport: ^0.3.0+1
osc: ^1.0.0

dev_dependencies:
ffigen: ^9.0.1
Expand Down

0 comments on commit 26ca1a6

Please sign in to comment.