Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

flutter - Movesense Sensor Data Logging

I work with Flutter and want to log and store the collected Data of the Sensor Model: OP174. I'm using the Accelorometer, Gyroscope, Magnetometer and Temperatur.

I see in the Movesense.swift that there is a Logbook_path and a Datalogger_config_path but I can't figure out how to get it to save the collected Data, it tried another soloution that i post below.

How can i store this Data in a CSV File and will be the Timestamp automaticly included?

Getting the Gyroscope Data

int _gyroSubscription;
  String _gyroscopeData = "";
  String get gyroscopeData => _gyroscopeData;
  bool get gyroscopeSubscribed => _gyroSubscription != null;

void subscribeToGyroscope() {
    _gyroscopeData = "";
    _gyroSubscription = Mds.subscribe(
        Mds.createSubscriptionUri(_serial, "/Meas/Gyro/104"),
        "{}",
        (d, c) => {},
        (e, c) => {},
        (data) => _onNewGyroscopeData(data),
        (e, c) => {});
    notifyListeners();
  }

  void _onNewGyroscopeData(String data) {
    Map<String, dynamic> gyroData = jsonDecode(data);
    Map<String, dynamic> body = gyroData["Body"];
    List<dynamic> gyroArry = body["ArrayGyro"];
    dynamic gyro = gyroArry.last;
    _gyroscopeData = "x: " +
        gyro["x"].toStringAsFixed(2) +
        "
y: " +
        gyro["y"].toStringAsFixed(2) +
        "
z: " +
        gyro["z"].toStringAsFixed(2);
    notifyListeners();
  }

Trying to save the Data

Future<String> getFilePath() async {
    Directory appDocumentsDirectory = await getExternalStorageDirectory();
    List<FileSystemEntity> directory = appDocumentsDirectory.listSync();
    directory.forEach((x) => debugPrint(x.path));
    String appDocumentsPath = appDocumentsDirectory.path;
    String filePath = '$appDocumentsPath/recording.csv';

    return filePath;
  }

  void saveFile(DeviceModel deviceModel) async {
    File file = File(await getFilePath());
    file.writeAsString(deviceModel.gyroscopeData);
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For working with the DataLogger & Logbook, please see the Android example "DataLoggerSample" as well as the related API-documentation.

In short:

  1. PUT /Mem/DataLogger/Config that lists paths that you want to log. In your case they would be /Meas/IMU9/104 and /Meas/Temp.
  2. PUT /Mem/DataLogger/State to 3 (=LOGGING) -- you can disconnect here --
  3. Do you thing that you want to measure
  4. Re-connect to sensor
  5. PUT /Mem/DataLogger/State to 2 (=READY). This stops the recording.
  6. GET "suunto:/MDS/Logbook/{serial}/Entries" on mobile to have a list of entries on the sensors datamemory. The one with biggest LogID is the one you just recorded
  7. GET "suunto:/MDS/Logbook/{serial}/byId/{LogId}/Data" on mobile to get the recording as JSON.

NOTE: The paths you want to record fill up the data memory quite fast (< 100 seconds). Current sensor treats data mem as ring buffer and stores over the old data if it gets full so you'll get the last ~90s of data.

Full Disclosure: I work for the Movesense team


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...