Erkennen des Fahrzustands mit dem Core Motion Framework – Probleme mit der AutomobilgenauigkeitIOS

Programmierung für iOS
Anonymous
 Erkennen des Fahrzustands mit dem Core Motion Framework – Probleme mit der Automobilgenauigkeit

Post by Anonymous »

Ich arbeite an einer iOS-App, bei der ich mithilfe des Apple Core Motion-Frameworks erkennen muss, wann ein Benutzer das Fahren startet und stoppt. Ich habe die folgende MotionActivityManager-Klasse implementiert, um Aktivitätsaktualisierungen zu verarbeiten und die erkannten Zustände in einer SwiftUI-Ansicht anzuzeigen.
Während ich die Zustände „Stationär“ und „Gehen“ genau erkennen kann, erkenne ich die „ Der Zustand „Fahren“ (Automobil) war unzuverlässig. Die Genauigkeit lässt oft nach und das Framework klassifiziert das Fahren häufig fälschlicherweise als andere Zustände wie „Unbekannt“ oder „Gehen“.
Hier ist die Implementierung:

Code: Select all

import SwiftUI
import CoreMotion

class MotionActivityManager: ObservableObject {
private let motionActivityManager = CMMotionActivityManager()
private let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
return formatter
}()

@Published var motionStates: [MotionState] = []
@Published var startDate: String = ""
@Published var confidence: String = ""

init() {
setupDefaultStates()
startActivityUpdates()
}

private func setupDefaultStates() {
motionStates = [
MotionState(label: "Stationary", value: false),
MotionState(label: "Walking", value: false),
MotionState(label: "Running", value: false),
MotionState(label: "Automotive", value: false),
MotionState(label: "Cycling", value: false),
MotionState(label: "Unknown", value: false)
]
}

func startActivityUpdates() {
guard CMMotionActivityManager.isActivityAvailable() else {
print("Motion activity is not available.")
return
}

motionActivityManager.startActivityUpdates(to: .main) { [weak self] motion in
guard let self = self, let motion = motion else { return }
DispatchQueue.main.async {
self.updateProperties(with: motion)
}
}
}

private func updateProperties(with motion: CMMotionActivity) {
motionStates = [
MotionState(label: "Stationary", value: motion.stationary),
MotionState(label: "Walking", value: motion.walking),
MotionState(label: "Running", value: motion.running),
MotionState(label: "Automotive", value: motion.automotive),
MotionState(label: "Cycling", value: motion.cycling),
MotionState(label: "Unknown", value: motion.unknown)
]
startDate = dateFormatter.string(from: motion.startDate)

switch motion.confidence {
case .low:
confidence = "Low"
case .medium:
confidence = "Medium"
case .high:
confidence = "High"
@unknown default:
confidence = "Unknown"
}
}
}

struct MotionState: Identifiable {
let id = UUID()
let label: String
let value: Bool
}

struct ContentView: View {
@StateObject private var motionManager = MotionActivityManager()

var body: some View {
ScrollView {
VStack(spacing: 16) {
ForEach(motionManager.motionStates) { state in
LabelView(label: state.label, value: state.value ? "True" : "False")
}
LabelView(label: "Confidence", value: motionManager.confidence)
}
.padding()
}
.onAppear {
UIApplication.shared.isIdleTimerDisabled = true
motionManager.startActivityUpdates()
}
.navigationTitle("Motion Activity")
}
}
Probleme:
Der Zustand „motion.automotive“ wird oft nicht genau erkannt.
Das Konfidenzniveau bleibt selbst für den Zustand „Automotive“ niedrig wenn sich das Gerät eindeutig in einem Auto befindet.
Wie kann ich die Erkennungsgenauigkeit des Status „Fahren“ mithilfe des Core Motion-Frameworks verbessern?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post