Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

Commit

Permalink
api v1.1.0 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
scaryghost committed Sep 15, 2018
1 parent f13cf75 commit b525720
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 22 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*.pfx
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

Expand Down
2 changes: 1 addition & 1 deletion MetaWear.Test/DataProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using MbientLab.MetaWear.Data;

namespace MbientLab.MetaWear.Test {
class DataProcessorTest : UnitTestBase {
abstract class DataProcessorTest : UnitTestBase {
public DataProcessorTest() : base(typeof(ISwitch), typeof(ILed), typeof(IAccelerometerBmi160),
typeof(IBarometerBmp280), typeof(IGpio), typeof(ILogging), typeof(IDataProcessor), typeof(ITemperature)) { }
}
Expand Down
57 changes: 50 additions & 7 deletions MetaWear.Test/SensorFusionBoschTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,11 @@ public static IEnumerable InterpretDataTestCases {
}
}

[Parallelizable]
[TestFixture]
class SensorFusionBoschTest : UnitTestBase {
private ISensorFusionBosch sensorFusion;
abstract class SensorFusionBoschBaseTest : UnitTestBase {
protected ISensorFusionBosch sensorFusion;

public SensorFusionBoschTest() : base(typeof(IAccelerometerBmi160), typeof(IGyroBmi160), typeof(IMagnetometerBmm150), typeof(ISensorFusionBosch)) { }
public SensorFusionBoschBaseTest() : base(typeof(IAccelerometerBmi160), typeof(IGyroBmi160), typeof(IMagnetometerBmm150), typeof(ISensorFusionBosch)) {
}

[SetUp]
public async override Task SetUp() {
Expand All @@ -177,7 +176,7 @@ public async override Task SetUp() {
[TestCaseSource(typeof(SensorFusionBoschTestDataClass), "ConfigureTestCases")]
public void Configure(Mode mode, AccRange acc, GyroRange gyr, Sensor.AccelerometerBmi160.FilterMode accFilter, FilterMode gyroFilter) {
byte[][] expected = null;
byte[] configGyro100Hz = new byte[] {0x13, 0x03, (byte) (((int) gyroFilter << 4 ) | GyroBmi160Test.ODR_BITMASK[(int) OutputDataRate._100Hz]), GyroBmi160Test.RANGE_BITMASK[(int) gyr]};
byte[] configGyro100Hz = new byte[] { 0x13, 0x03, (byte)(((int)gyroFilter << 4) | GyroBmi160Test.ODR_BITMASK[(int)OutputDataRate._100Hz]), GyroBmi160Test.RANGE_BITMASK[(int)gyr] };

switch (mode) {
case Mode.Ndof:
Expand Down Expand Up @@ -213,7 +212,7 @@ public void Configure(Mode mode, AccRange acc, GyroRange gyr, Sensor.Acceleromet
};
break;
}
expected[1][2] |= (byte)((int) accFilter << 4);
expected[1][2] |= (byte)((int)accFilter << 4);

sensorFusion.Configure(mode, acc, gyr, accExtra: new Object[] { accFilter }, gyroExtra: new object[] { gyroFilter });

Expand Down Expand Up @@ -263,4 +262,48 @@ await producer.AddRouteAsync(source => source.Stream(data => {
Assert.That(actual, Is.EqualTo(expected));
}
}

[Parallelizable]
[TestFixture]
class SensorFusionBoschTest : SensorFusionBoschBaseTest {
public SensorFusionBoschTest() : base() {

}

[Test]
public void ReadCalibration() {
Assert.ThrowsAsync<InvalidOperationException>(async () => {
await sensorFusion.ReadCalibrationStateAsync();
});
}
}

[Parallelizable]
[TestFixture]
class SensorFusionBoschRev1Test : SensorFusionBoschBaseTest {
public SensorFusionBoschRev1Test() : base() {
platform.initResponse.moduleResponses[0x19][3] = 0x1;
}

[SetUp]
public async override Task SetUp() {
await base.SetUp();

platform.customResponses.Add(new byte[] { 0x19, 0x8b },
new byte[] { 0x19, 0x8b, 0x00, 0x01, 0x02 });
}

[Test]
public async Task ReadCalibration() {
byte[][] expected = new byte[][] {
new byte[] { 0x19, 0x8b }
};
ImuCalibrationState expectedState = new ImuCalibrationState(CalibrationAccuracy.Unreliable, CalibrationAccuracy.LowAccuracy, CalibrationAccuracy.MediumAccuracy);

var actual = await sensorFusion.ReadCalibrationStateAsync();

Assert.That(actual, Is.EqualTo(expectedState));
Assert.That(platform.GetCommands(), Is.EqualTo(expected));
}
}
}
48 changes: 48 additions & 0 deletions MetaWear/Core/ISensorFusionBosch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,47 @@ public override int GetHashCode() {
return result;
}
}
/// <summary>
/// Container class holding the calibration state of the IMU sensors
/// </summary>
public struct ImuCalibrationState {
/// <summary>
/// Current calibration accuracy values for the accelerometer, gyroscope, and magnetometer respectively
/// </summary>
public readonly CalibrationAccuracy accelerometer, gyroscope, magnetometer;

public ImuCalibrationState(CalibrationAccuracy accelerometer, CalibrationAccuracy gyroscope, CalibrationAccuracy magnetometer) {
this.accelerometer = accelerometer;
this.gyroscope = gyroscope;
this.magnetometer = magnetometer;
}

public override bool Equals(object obj) {
if (!(obj is ImuCalibrationState)) {
return false;
}

var state = (ImuCalibrationState)obj;
return accelerometer == state.accelerometer &&
gyroscope == state.gyroscope &&
magnetometer == state.magnetometer;
}

public override int GetHashCode() {
var hashCode = -56290531;
hashCode = hashCode * -1521134295 + accelerometer.GetHashCode();
hashCode = hashCode * -1521134295 + gyroscope.GetHashCode();
hashCode = hashCode * -1521134295 + magnetometer.GetHashCode();
return hashCode;
}

public override string ToString() {
return string.Format("{{accelerometer: {0}, gyroscope: {1}, magnetometer: {2}{3}",
Enum.GetName(typeof(CalibrationAccuracy), accelerometer),
Enum.GetName(typeof(CalibrationAccuracy), gyroscope),
Enum.GetName(typeof(CalibrationAccuracy), magnetometer), "}");
}
}
}
/// <summary>
/// Bosch algorithm combining accelerometer, gyroscope, and magnetometer data for Bosch sensors.
Expand Down Expand Up @@ -212,5 +253,12 @@ void Configure(Mode mode = Mode.Ndof, AccRange ar = AccRange._16g, GyroRange gr
/// </summary>
/// <returns>Task that is completed when the settings are received</returns>
Task PullConfigAsync();
/// <summary>
/// Reads the current calibration state from the sensor fusion algorithm. This function cannot be
/// called until the sensor fusion algorithm is running and is only available on firmware v1.4.1+
/// </summary>
/// <returns>Current calibrartion state</returns>
/// <exception cref="InvalidOperationException">If device is not using min required firmware</exception>
Task<ImuCalibrationState> ReadCalibrationStateAsync();
}
}
22 changes: 17 additions & 5 deletions MetaWear/Impl/SensorFusionBosch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ internal static string createIdentifier(DataTypeBase dataType) {

private const byte ENABLE = 1, MODE = 2, OUTPUT_ENABLE = 3,
CORRECTED_ACC = 4, CORRECTED_ROT = 5, CORRECTED_MAG = 6,
QUATERNION = 7, EULER_ANGLES = 8, GRAVITY_VECTOR = 9, LINEAR_ACC = 0xa;
QUATERNION = 7, EULER_ANGLES = 8, GRAVITY_VECTOR = 9, LINEAR_ACC = 0xa,
CALIBRATION_STATUS = 0xb;
private const byte CALIBRATION_STATE_REV = 1;

[DataContract]
private class QuaternionDataType : DataTypeBase {
Expand Down Expand Up @@ -262,7 +264,7 @@ public override void Stop() {
[DataMember] private byte dataEnableMask;
[DataMember] private DataTypeBase corrAccType, corrAngVelType, corrBFieldType, quaternionType, eulerAnglesType, gravityType, linAccType;

private TimedTask<byte[]> readConfigTask;
private TimedTask<byte[]> readValueTask;

private IAsyncDataProducer correctedAcc = null, correctedAngularVel = null, correctedMag = null,
quaternion = null, eulerAngles = null,
Expand Down Expand Up @@ -346,8 +348,9 @@ internal override void aggregateDataType(ICollection<DataTypeBase> collection) {
}

protected override void init() {
readConfigTask = new TimedTask<byte[]>();
bridge.addRegisterResponseHandler(Tuple.Create((byte)SENSOR_FUSION, Util.setRead(MODE)), response => readConfigTask.SetResult(response));
readValueTask = new TimedTask<byte[]>();
bridge.addRegisterResponseHandler(Tuple.Create((byte)SENSOR_FUSION, Util.setRead(MODE)), response => readValueTask.SetResult(response));
bridge.addRegisterResponseHandler(Tuple.Create((byte)SENSOR_FUSION, Util.setRead(CALIBRATION_STATUS)), response => readValueTask.SetResult(response));
}

public void Configure(Mode mode = Mode.Ndof, AccRange ar = AccRange._16g, GyroRange gr = GyroRange._2000dps,
Expand Down Expand Up @@ -494,9 +497,18 @@ public void Stop() {
}

public async Task PullConfigAsync() {
var response = await readConfigTask.Execute("Did not receive sensor fusion config within {0}ms", bridge.TimeForResponse,
var response = await readValueTask.Execute("Did not receive sensor fusion config within {0}ms", bridge.TimeForResponse,
() => bridge.sendCommand(new byte[] { (byte)SENSOR_FUSION, Util.setRead(MODE) }));
mode = (Mode)response[2];
}

public async Task<ImuCalibrationState> ReadCalibrationStateAsync() {
if (bridge.lookupModuleInfo(SENSOR_FUSION).revision >= CALIBRATION_STATE_REV) {
var response = await readValueTask.Execute("Did not received calibration state within {0}ms", bridge.TimeForResponse,
() => bridge.sendCommand(new byte[] { (byte)SENSOR_FUSION, Util.setRead(CALIBRATION_STATUS) }));
return new ImuCalibrationState((CalibrationAccuracy)response[2], (CalibrationAccuracy)response[3], (CalibrationAccuracy)response[4]);
}
throw new InvalidOperationException(string.Format("Minimun firmware v1.4.1 required to use this function (current is {0})", bridge.getFirmware().ToString()));
}
}
}
2 changes: 1 addition & 1 deletion MetaWear/MetaWear.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<DelaySign>false</DelaySign>
<AssemblyName>MbientLab.MetaWear</AssemblyName>
<RootNamespace>MbientLab.MetaWear</RootNamespace>
<Version>1.0.15</Version>
<Version>1.1.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
15 changes: 8 additions & 7 deletions nuget/MetaWear.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@
<metadata minClientVersion="4.1">
<id>MetaWear.CSharp</id>
<title>MetaWear C# SDK</title>
<version>1.0.15</version>
<version>1.1.0</version>
<authors>MbientLab</authors>
<owners>MbientLab</owners>
<licenseUrl>https://raw.githubusercontent.com/mbientlab/MetaWear-SDK-CSharp/master/LICENSE.md</licenseUrl>
<projectUrl>https://github.com/mbientlab/MetaWear-SDK-CSharp</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright 2014 - 2018(c). MbientLab Inc</copyright>
<summary>Platform agnostic C# SDK for MbientLab's sensor platform</summary>
<releaseNotes>https://github.com/mbientlab/MetaWear-SDK-CSharp/releases/tag/1.0.15</releaseNotes>
<summary>.NET Standard 2.0 MetaMotion / MetaWear C# SDK</summary>
<releaseNotes>https://github.com/mbientlab/MetaWear-SDK-CSharp/releases/tag/1.1.0</releaseNotes>
<description>
Platform agnostic, .NET Standard 2.0 library for commuicating with MbientLab's sensor platform.
Platform agnostic, .NET Standard 2.0 library for communicating with MetaMotion / MetaWear boards.

Due to its platform agnostic nature, this package is only an API for the boards' BLE communication protocol;
Due to its platform agnostic nature, this package is only an API for the BLE communication protocol;
users of this package will need to plugin their own BLE stack and file i/o code.

Check out the MetaWear.Win10 package for Windows 10 specific BLE and file plugs.
Check out the MetaWear.Win10 and MetaWear.NetStandard packages for Windows 10 and NetStandard 2.0 specific
plugins for this project.
</description>
<tags>metawear metamotion metatracker sensors netstandard2.0</tags>
</metadata>
<files>
<file src="..\MetaWear\bin\Release\netstandard2.0\MbientLab.MetaWear.dll" target="lib\netstandard2.0" />
<file src="..\MetaWear\bin\Release\netstandard2.0\MbientLab.MetaWear.xml" target="lib\netstandard2.0" />
<file src="..\MetaWear\bin\Release\netstandar d2.0\MbientLab.MetaWear.xml" target="lib\netstandard2.0" />
</files>
</package>

0 comments on commit b525720

Please sign in to comment.