///<inheritdoc/> protected override void Analyse(DataEventArgs data) { if (_cooldown <= 0) { Accelerometer newAccValue = data.Data.Acc; double absAcc = Math.Sqrt(Math.Pow(newAccValue.G_Z, 2) + Math.Pow(newAccValue.G_Y, 2) + Math.Pow(newAccValue.G_X, 2)); //check if condition is fulfilled if (LOWER[_state] == (absAcc < ABS_ACC_THRESHOLD[_state])) { _cooldown = COOLDOWN_DURATION[_state]; _state++; //check if all states have been passed and activity therefore is detected if (_state % STATE_COUNT == 0) { _state = 0; ActivityDone.Invoke(this, new PushUpEventArgs()); } } } if (_cooldown > 0) { _cooldown -= (1.0 / _frequency); } }
///<inheritdoc/> override protected void Analyse(DataEventArgs data) { //to avoid using reflections or other stuff to dynamically get right value from sensor data, copy data to an array structure. Accelerometer newAccValue = data.Data.Acc; double[] dataAsArray = { data.Data.Acc.G_X, data.Data.Acc.G_Y, data.Data.Acc.G_Z, data.Data.Gyro.DegsPerSec_X, data.Data.Gyro.DegsPerSec_Y, data.Data.Gyro.DegsPerSec_Z }; //check if condition of current state is fulfilled if (LOWER[_state] == (dataAsArray[VALUE_INDEX[_state]] < THRESHOLD[_state])) { //progress to next state _state++; //check if all states have been passed and activity therefore is detected if (_state % STATE_COUNT == 0) { _state = 0; ActivityDone.Invoke(this, new PushUpEventArgs()); } } }
///<inheritdoc/> protected override void Analyse(DataEventArgs data) { IMUDataEntry _newValue = data.Data; //the accelerometer is the only relevant thing Accelerometer accV = _newValue.Acc; double accVAbs = Math.Sqrt(Math.Pow(accV.G_X, 2) + Math.Pow(accV.G_Y, 2) + Math.Pow(accV.G_Z, 2)); //first update average values //therefore calculate the weight of the old value int ref_weight = REF_WEIGHT_REL * _frequency; _avgAccAbsolute = (accVAbs + ref_weight * _avgAccAbsolute) / (ref_weight + 1); _avgAccX = (accV.G_X + ref_weight * _avgAccX) / (ref_weight + 1); _avgAccY = (accV.G_Y + ref_weight * _avgAccY) / (ref_weight + 1); _avgAccZ = (accV.G_Z + ref_weight * _avgAccZ) / (ref_weight + 1); if (accVAbs > TRIGGER_THRESHOLD * _avgAccAbsolute) { //threshold is passed if (cooldown <= 0) { //set cooldown, no matter what motion has been registered cooldown = COOLDOWN_DURATION; //check if direction of current value and average head in the same direction using simple formula for cosinus if ((_avgAccX * accV.G_X + _avgAccY * accV.G_Y + _avgAccZ * accV.G_Z) / accVAbs / _avgAccAbsolute > ANGLE_TOLERANCE_COS) { //step recognized ActivityDone.Invoke(this, new StepEventArgs()); } } } if (cooldown > 0) { cooldown -= 1.0 / _frequency; } }
/// <summary> /// this method is called when a change of the running state was detected. It automatically applies the change to _runningState and notifies the triggers the Event. /// </summary> protected void ChangeDetected() { _runningState = !_runningState; ActivityDone.Invoke(this, new RunningEventArgs(_runningState)); }