Fuse , gyro + magnetometer + accelerometer

edited November 21 in C#

Hello ,

I am trying to fuse 3 gyro + magnetometer + accelerometer,

it is possible to fuse all 3 of it , if yes is the below code works .

        IAccelerometerBosch accelerometer = metawear.GetModule<IAccelerometerBosch>();
        IGyroBmi160 gyro = metawear.GetModule<IGyroBmi160>();
        IMagnetometerBmm150 magnetometer = metawear.GetModule<IMagnetometerBmm150>();

        gyro.Configure(OutputDataRate._100Hz);
        magnetometer.Configure(Preset.EnhancedRegular);
        accelerometer.Configure(odr: 100f, range: 2f);

        await gyro.AngularVelocity.AddRouteAsync(source => source.Buffer().Name("Acc-Gyro-Data"));
        await magnetometer.MagneticField.AddRouteAsync(x => x.Buffer().Name("Acc-Ang-Data"));
        await accelerometer.Acceleration.AddRouteAsync(source => source.Fuse("Acc-Ang-Data", "Acc-Gyro-Data").Stream(DataEventHandler));


         private void DataEventHandler(IData obj)
                {

                    try
                    {

                // data receive here is 17 bytes ,  I thing we are expecting 18 bytes and so it will crash 
                        var dataArray = obj.Value<IData[]>(); // crash here ,                

                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);

                    }         
                }

Error Log
System.ArgumentException: Source array was not long enough. Check srcIndex and length, and the array's lower bounds.
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
at MbientLab.MetaWear.Impl.FusedData.ValueT
at xxx.DataEventHandler(IData obj)

Sign In or Register to comment.