RSDMotionRecord

public struct RSDMotionRecord : RSDSampleRecord, RSDDelimiterSeparatedEncodable

A RSDMotionRecord is a Codable implementation of RSDSampleRecord that can be used to record a sample from one of the core motion sensors or calculated vectors of the CMDeviceMotion data object.

  • example:
    // Example json for a codable record.
       func testMotionRecord_Attitude() {
           let json = """
               {
                   "timestamp" : 1.2498140833340585,
                   "stepPath" : "Cardio Stair Step/heartRate.after/heartRate",
                   "sensorType" : "attitude",
                   "referenceCoordinate" : "North-West-Up",
                   "heading" : 270.25,
                   "eventAccuracy" : 4,
                   "x" : 0.064788818359375,
                   "y" : -0.1324615478515625,
                   "z" : -0.9501953125,
                   "w" : 1
               }
               """.data(using: .utf8)! // our data in native (JSON) format

Seealso

CodableMotionRecorderTests.swift unit tests for additional examples.
  • System clock time.

    Declaration

    Swift

    public let uptime: TimeInterval?
  • Time that the system has been awake since last reboot.

    Declaration

    Swift

    public let timestamp: TimeInterval?
  • An identifier marking the current step.

    Declaration

    Swift

    public let stepPath: String
  • The date timestamp when the measurement was taken (if available).

    Declaration

    Swift

    public let timestampDate: Date?
  • The sensor type for this record sample.

    Note

    If nil then this is a decoded log file marker used to mark step transitions.

    Declaration

    Swift

    public let sensorType: RSDMotionRecorderType?
  • A number marking the sensor accuracy of the magnetic field sensor.

    Declaration

    Swift

    public let eventAccuracy: Int?
  • Used for an attitude record type to describe the reference frame.

    Declaration

    Swift

    public let referenceCoordinate: RSDAttitudeReferenceFrame?
  • The heading angle in the range [0,360) degrees with respect to the CMAttitude reference frame. A negative value is returned for CMAttitudeReferenceFrame.xArbitraryZVertical and CMAttitudeReferenceFrame.xArbitraryCorrectedZVertical reference coordinates.

    Declaration

    Swift

    public let heading: Double?
  • x

    The x component of the vector measurement for this sensor sample.

    Declaration

    Swift

    public let x: Double?
  • y

    The y component of the vector measurement for this sensor sample.

    Declaration

    Swift

    public let y: Double?
  • z

    The z component of the vector measurement for this sensor sample.

    Declaration

    Swift

    public let z: Double?
  • w

    The w component of the vector measurement for this sensor sample. Used by the attitude quaternion.

    Declaration

    Swift

    public let w: Double?
  • Initialize from a raw sensor data point.

    Declaration

    Swift

    public init(stepPath: String, data: RSDVectorData, referenceClock: RSDClock? = nil)

    Parameters

    startUptime

    System clock uptime when the recorder was started.

    stepPath

    The current step path.

    data

    The raw sensor data to record.

  • Initialize from a CMDeviceMotion for a given sensor type or calculated vector.

    Declaration

    Swift

    public init?(stepPath: String, data: CMDeviceMotion, referenceFrame: CMAttitudeReferenceFrame, sensorType: RSDMotionRecorderType, referenceClock: RSDClock? = nil)

    Parameters

    startUptime

    System clock uptime when the recorder was started.

    stepPath

    The current step path.

    data

    The CMDeviceMotion data sample from which to record information.

    referenceFrame

    The CMAttitudeReferenceFrame for this recording.

    sensorType

    The recorder type for which to record the vector.

  • Declaration

    Swift

    public static func codingKeys() -> [CodingKey]