Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Balance Board: zero point calibration #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions WiimoteCS/WiimoteLib/DataTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ public struct BalanceBoardState
[DataMember]
public BalanceBoardSensorsF SensorValuesLb;
/// <summary>
/// Zero Point / tare values
/// </summary>
[DataMember]
public ZeroPoint ZeroPoint;
/// <summary>
/// Total kilograms on the Balance Board
/// </summary>
[DataMember]
Expand Down Expand Up @@ -636,6 +641,30 @@ public struct BalanceBoardSensorsF
public float BottomLeft;
}

/// /// <summary>
/// Zero Point / tare values
/// </summary>
[Serializable]
[DataContract]
public struct ZeroPoint
{
/// <summary>
/// Kilograms per sensor
/// </summary>
[DataMember]
public BalanceBoardSensorsF SensorValuesKg;
/// <summary>
/// Has Zero Point been set?
/// </summary>
[DataMember]
public Boolean IsSet;
/// <summary>
/// Set the zero point
/// </summary>
[DataMember]
public Boolean Reset;
}

/// <summary>
/// Current state of a single IR sensor
/// </summary>
Expand Down
27 changes: 23 additions & 4 deletions WiimoteCS/WiimoteLib/Wiimote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -862,13 +862,32 @@ private void ParseExtension(byte[] buff, int offset)
mWiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft = GetBalanceBoardSensorValue(mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomLeft, mWiimoteState.BalanceBoardState.CalibrationInfo.Kg0.BottomLeft, mWiimoteState.BalanceBoardState.CalibrationInfo.Kg17.BottomLeft, mWiimoteState.BalanceBoardState.CalibrationInfo.Kg34.BottomLeft);
mWiimoteState.BalanceBoardState.SensorValuesKg.BottomRight = GetBalanceBoardSensorValue(mWiimoteState.BalanceBoardState.SensorValuesRaw.BottomRight, mWiimoteState.BalanceBoardState.CalibrationInfo.Kg0.BottomRight, mWiimoteState.BalanceBoardState.CalibrationInfo.Kg17.BottomRight, mWiimoteState.BalanceBoardState.CalibrationInfo.Kg34.BottomRight);

if (mWiimoteState.BalanceBoardState.ZeroPoint.Reset)
{
mWiimoteState.BalanceBoardState.ZeroPoint.SensorValuesKg.TopLeft = mWiimoteState.BalanceBoardState.SensorValuesKg.TopLeft;
mWiimoteState.BalanceBoardState.ZeroPoint.SensorValuesKg.TopRight = mWiimoteState.BalanceBoardState.SensorValuesKg.TopRight;
mWiimoteState.BalanceBoardState.ZeroPoint.SensorValuesKg.BottomLeft = mWiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft;
mWiimoteState.BalanceBoardState.ZeroPoint.SensorValuesKg.BottomRight = mWiimoteState.BalanceBoardState.SensorValuesKg.BottomRight;
mWiimoteState.BalanceBoardState.ZeroPoint.IsSet = true;
mWiimoteState.BalanceBoardState.ZeroPoint.Reset = false;
// todo: average over 2 seconds of readings, if values are not stable, reset failed.
}

if (mWiimoteState.BalanceBoardState.ZeroPoint.IsSet)
{
mWiimoteState.BalanceBoardState.SensorValuesKg.TopLeft -= mWiimoteState.BalanceBoardState.ZeroPoint.SensorValuesKg.TopLeft;
mWiimoteState.BalanceBoardState.SensorValuesKg.TopRight -= mWiimoteState.BalanceBoardState.ZeroPoint.SensorValuesKg.TopRight;
mWiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft -= mWiimoteState.BalanceBoardState.ZeroPoint.SensorValuesKg.BottomLeft;
mWiimoteState.BalanceBoardState.SensorValuesKg.BottomRight -= mWiimoteState.BalanceBoardState.ZeroPoint.SensorValuesKg.BottomRight;
}

mWiimoteState.BalanceBoardState.SensorValuesLb.TopLeft = (mWiimoteState.BalanceBoardState.SensorValuesKg.TopLeft * KG2LB);
mWiimoteState.BalanceBoardState.SensorValuesLb.TopRight = (mWiimoteState.BalanceBoardState.SensorValuesKg.TopRight * KG2LB);
mWiimoteState.BalanceBoardState.SensorValuesLb.BottomLeft = (mWiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft * KG2LB);
mWiimoteState.BalanceBoardState.SensorValuesLb.BottomRight = (mWiimoteState.BalanceBoardState.SensorValuesKg.BottomRight * KG2LB);

mWiimoteState.BalanceBoardState.WeightKg = (mWiimoteState.BalanceBoardState.SensorValuesKg.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesKg.TopRight + mWiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft + mWiimoteState.BalanceBoardState.SensorValuesKg.BottomRight) / 4.0f;
mWiimoteState.BalanceBoardState.WeightLb = (mWiimoteState.BalanceBoardState.SensorValuesLb.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesLb.TopRight + mWiimoteState.BalanceBoardState.SensorValuesLb.BottomLeft + mWiimoteState.BalanceBoardState.SensorValuesLb.BottomRight) / 4.0f;
mWiimoteState.BalanceBoardState.WeightKg = (mWiimoteState.BalanceBoardState.SensorValuesKg.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesKg.TopRight + mWiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft + mWiimoteState.BalanceBoardState.SensorValuesKg.BottomRight);
mWiimoteState.BalanceBoardState.WeightLb = (mWiimoteState.BalanceBoardState.SensorValuesLb.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesLb.TopRight + mWiimoteState.BalanceBoardState.SensorValuesLb.BottomLeft + mWiimoteState.BalanceBoardState.SensorValuesLb.BottomRight);

float Kx = (mWiimoteState.BalanceBoardState.SensorValuesKg.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft) / (mWiimoteState.BalanceBoardState.SensorValuesKg.TopRight + mWiimoteState.BalanceBoardState.SensorValuesKg.BottomRight);
float Ky = (mWiimoteState.BalanceBoardState.SensorValuesKg.TopLeft + mWiimoteState.BalanceBoardState.SensorValuesKg.TopRight) / (mWiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft + mWiimoteState.BalanceBoardState.SensorValuesKg.BottomRight);
Expand All @@ -885,9 +904,9 @@ private float GetBalanceBoardSensorValue(short sensor, short min, short mid, sho
return 0;

if(sensor < mid)
return 68.0f * ((float)(sensor - min) / (mid - min));
return 17.0f * ((float)(sensor - min) / (mid - min));
else
return 68.0f * ((float)(sensor - mid) / (max - mid)) + 68.0f;
return 17.0f * ((float)(sensor - mid) / (max - mid)) + 17.0f;
}


Expand Down
Loading