Swiift SDK v3 Docs

This discussion was created from comments split from: Firmware v1.4.1.

Comments

  • Docs for iOS v3.1.6 seems incomplete on website online since the new firmware is available, and I feel worried as a part of my code is still in objc...
    Will there be a new MetaWearApiTest project soon available for this new SDK.
    Before upgrading it could be very usefull to check major differences.
    Thanks!

  • edited August 4

    What is incomplete about the documentation?

    Refer to the Swift Starter Project for a working app.

  • Starter Projetc is really to minimalist to get a good idea of how to write an optimized code with iOS and it is quite discouraging.

    As provided before, to get the possibility to use a complete example of functions was great and the best way to do as you want (https://github.com/mbientlab/MetaWear-SampleApp-iOS) ! Could it be possible to get an update version of this full app (last commit is 22 dec 2017 ; not so far...)

    If you really want us to use your last optimized API why letting us guess how to do from C++ ? Until now, I was really so happy to get support on iOS... Is it a voluntary change of strategy to leave iOS ? is MetaBase supposed to be the only "true" app ?

    Regarding a working app, mines are already online on the app store just waiting for an activation code to connect three metamotion-r.
    Functionally it is working well and only bluetooth 5 will be able to help for a better connectivity (particularly outdoors).
    I even took time to send you a long email about my complete project...

    And as you know, since march, I am working on my business plan and a first order of one thousand sensors ; but with this new firmware It seems compromised for september. I just do hope that this firmware will lead soon to the possibility to get bluetooth 5 which will be a real new feature...

    Thanks for your help and attention

  • The iOS v3 documentation clearly states:

    This is a thin wrapper around the MetaWear C++ API so you will find the C++ documentation and API reference useful

    Have you reviewed the C++ documentation? If not, then of course the start project is going to feel foreign and unhelpful as the api has completely changed. If so, then post what is unclear about the C++ sdk, and we can address them.

    If you are uncomfortable with using the v3 release, then stick with v2, however, new features most likely will not be back-ported so you should update your code when appropriate or convenient.

  • Thanks Eric for your answer but yes, unfortunately, I had already read the new v3 documentation before posting, but I feel completely lost with the thin wrapper C++ and I understand that there is no more support for "pure" iOS...

    Regarding these two old iOS functions which were so simples to get gyro rotations values, I am now unable to find how to do in Swift (i.e. just start and stop gyro).

        let gyroBMI160 = self.device.gyro as! MBLGyroBMI160
        gyroBMI160.fullScaleRange = .range2000
        gyroBMI160.sampleFrequency = 100
        device.gyro!.packedDataReadyEvent?.startNotificationsAsync { (obj, error) in
            if let obj = obj {
            //and here, juste code to affect obj.x, obj.y and obj.z values to local variables.
                           }
        }
    

    I just read and read again the docs for c++ (https://mbientlab.com/cppdocs/latest/gyro.html) and I feel completely desperate...
    The code look like Swift but impossible to use it "like that" and clearly I understand nothing to the way to declare "rot_handler" and "rot_rate" in Swift...

    Here is the code I try to insert in the startup project ; for configuring it seems ok, but for sampling I do not understand how to convert C++ code to Swift.

        mbl_mw_gyro_bmi160_set_odr(self.device.board, MBL_MW_GYRO_BMI160_ODR_100Hz);
        mbl_mw_gyro_bmi160_set_range(self.device.board, MBL_MW_GYRO_BMI160_RANGE_2000dps);
        mbl_mw_gyro_bmi160_write_config(self.device.board);
    

    _** static auto rot_handler = [](void* context, const MblMwData* data) {
    // Cast value to MblMwCartesianFloat*
    auto rot_rate = (MblMwCartesianFloat*)data->value;
    printf("(%.3fdps, %.3fdps, %.3fdps)\n", rot_rate->x, rot_rate->y, rot_rate->z);
    };
    auto state_signal = mbl_mw_gyro_bmi160_get_rotation_data_signal(self.device.board);
    mbl_mw_datasignal_subscribe(state_signal, nullptr, rot_handler);**_

        mbl_mw_gyro_bmi160_enable_rotation_sampling(self.device.board);
        mbl_mw_gyro_bmi160_start(self.device.board);
    

    Could it be possible to get the correct syntaxe for Swift regarding the declaration of rot_handler, state_signal for a correct use with mbl_mw_datasignal_subscribe.

    Thanks in advance

  • Wrap your code with code tags so it renders correctly on the forum.

    See how this unit test sets up an accelerometer stream:
    https://github.com/mbientlab/MetaWear-SDK-iOS-macOS-tvOS/blob/560f4f98b77a07c31f011b9aa6b2e79388933c8c/MetaWear/Tests/Integration/Tests.swift#L106-#L110

  • Great !!!
    Many thanks for the link ! I was really not far, but I believe that I would have turn around for hours without your help as I am really not friend with wrapper, bridge and pointers...
    Thanks again !

  • HI Eric,

    I think that some code is missing in MetaWearData.swift regarding MblMwCalibrationState.

    case MBL_MW_DT_ID_CALIBRATION_STATE:
            assert(T.self == MblMwCalibrationState.self)
    

    Regarding this new functionnality coming with new firmware 1.4.1, could it be possible to get more details to how its works exactly as I guess that it is supposed to help against yaw drift.

    I succeed to get the values 3 for accelerometer and gyroscope (that I guess always calibrated) and 0 or 3 for magnetometer.
    So i guess that 3 means OK, and 0 "KO" but could be nice to be sure of it.

    Thanks
    Patrice

  • Yes, the data parsing function is missing an entry for calibration state. Thanks for bring it up.

    There is no "new functionality". All that specific signal does is provide visibility into the current accuracy states of the 3 IMUs, which should improve when you do the motions described in the accompanying YouTube video.

    Check the bindings file for relevant SDK constants:
    https://github.com/mbientlab/MetaWear-SDK-Cpp/blob/0.16.0/bindings/swift/cbindings.swift

Sign In or Register to comment.