Skip to content

Commit

Permalink
Fixed IMU and added pubspec.lock to the .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Bing-Rover committed Mar 15, 2024
1 parent dada601 commit 898ad39
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 496 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
# The rover has its own cache and SDK that conflicts with pub.dev
pubspec.lock

# C/C++ build files
build/
Expand Down
5 changes: 3 additions & 2 deletions lib/src/devices/imu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "package:burt_network/burt_network.dart";
const imuPort = "/dev/rover-imu";

extension on double {
bool isZero([double epsilon = 0.001]) => abs() < epsilon;
bool isZero([double epsilon = 0.01]) => abs() < epsilon;
}

/// A service to read orientation data from the connected IMU.
Expand All @@ -28,13 +28,14 @@ class ImuReader extends Service {
void _handleOsc(List<int> data) {
try {
final message = OSCMessage.fromBytes(data.sublist(20));
if (message.address != "/euler") return;
final orientation = Orientation(
x: message.arguments[0] as double,
y: message.arguments[1] as double,
z: message.arguments[2] as double,
);
if (orientation.x.isZero() || orientation.y.isZero() || orientation.z.isZero()) return;
if (orientation.x > 360 || orientation.y > 360 || orientation.z > 360) return;
if (orientation.x.abs() > 360 || orientation.y.abs() > 360 || orientation.z.abs() > 360) return;
final position = RoverPosition(orientation: orientation);
collection.server.sendMessage(position);
} catch (error) { /* Ignore corrupt data */ }
Expand Down
Loading

0 comments on commit 898ad39

Please sign in to comment.