algorithm/osp/tilt.c
void OSP_tilt_process(struct ThreeAxis *acc, struct ThreeAxis *tilt)
{
	struct ThreeAxis cur;
	int ang = 0;

	if (sampcount > 10000) {
		tilt->x = 0;
		return;
	}


	accHist[samp_head] = *acc;		

	if (sampcount < (NUM_SAMPLE2-1)) {
		if (sampcount == (NUM_SAMPLE1-1)) {
			computeMean(&prevMean, accHist, 0, NUM_SAMPLE1);
		}
		sampcount++;
		samp_head++;
		samp_head %= NUM_SAMPLE2;
		tilt->x = 0;
		return;
	}

	computeMean(&cur, accHist, samp_tail, samp_head);
	samp_head++; samp_head %= NUM_SAMPLE2;
	samp_tail++; samp_tail %= NUM_SAMPLE2;
	ang = computeAngle(&cur, &prevMean);
	if (ABS(ang) > INT_to_Q15(35)) {
		tilt->x = 1;
		sampcount = 99999;	
	}
	return;
}
/* Assumes the sensor runs at 50Hz */
Assumes the sensor runs at 50Hz
Assumes the sensor runs at 50Hz
void OSP_tilt_process(struct ThreeAxis *acc, struct ThreeAxis *tilt)
{
	struct ThreeAxis cur;
	int ang = 0;
	if (sampcount > 10000) {
		tilt->x = 0;
		return;
	}
	accHist[samp_head] = *acc;		
	if (sampcount < (NUM_SAMPLE2-1)) {
		if (sampcount == (NUM_SAMPLE1-1)) {
			computeMean(&prevMean, accHist, 0, NUM_SAMPLE1);
		}
		sampcount++;
		samp_head++;
		samp_head %= NUM_SAMPLE2;
		tilt->x = 0;
		return;
	}
	computeMean(&cur, accHist, samp_tail, samp_head);
	samp_head++; samp_head %= NUM_SAMPLE2;
	samp_tail++; samp_tail %= NUM_SAMPLE2;
	ang = computeAngle(&cur, &prevMean);
	if (ABS(ang) > INT_to_Q15(35)) {
		tilt->x = 1;
		sampcount = 99999;	
	}
	return;
}
void OSP_tilt_process ( struct ThreeAxis * acc , struct ThreeAxis * tilt ) { struct ThreeAxis cur ; int ang = 0 ; if ( sampcount > 10000 ) { tilt -> x = 0 ; return ; } accHist [ samp_head ] = * acc ; if ( sampcount < ( NUM_SAMPLE2 - 1 ) ) { if ( sampcount == ( NUM_SAMPLE1 - 1 ) ) { computeMean ( & prevMean , accHist , 0 , NUM_SAMPLE1 ) ; } sampcount ++ ; samp_head ++ ; samp_head %= NUM_SAMPLE2 ; tilt -> x = 0 ; return ; } computeMean ( & cur , accHist , samp_tail , samp_head ) ; samp_head ++ ; samp_head %= NUM_SAMPLE2 ; samp_tail ++ ; samp_tail %= NUM_SAMPLE2 ; ang = computeAngle ( & cur , & prevMean ) ; if ( ABS ( ang ) > INT_to_Q15 ( 35 ) ) { tilt -> x = 1 ; sampcount = 99999 ; } return ; }
Assumes the sensor runs at 50Hz
Assumes the sensor runs at 50Hz