Ejemplo n.º 1
0
void GY80Task::printAccelerator()
{
	/* Get a new sensor event */
	sensors_event_t event;
	accel.getEvent(&event);

	/* Display the results (acceleration is measured in m/s^2) */
	Serial1.print("X: "); Serial1.print(event.acceleration.x); Serial1.print("  ");
	Serial1.print("Y: "); Serial1.print(event.acceleration.y); Serial1.print("  ");
	Serial1.print("Z: "); Serial1.print(event.acceleration.z); Serial1.print("  "); Serial1.println("m/s^2 ");
}
Ejemplo n.º 2
0
void readAccel(){
	/* Get a new sensor event */ 
	sensors_event_t event; 
	accel.getEvent(&event);

	/* Display the results (acceleration is measured in m/s^2) */
#ifdef PRINT_ACCEL
	Serial.print(F("X: ")); Serial.print(event.acceleration.x);
	Serial.print(F(" Y: ")); Serial.print(event.acceleration.y);
	Serial.print(F(" Z: ")); Serial.print(event.acceleration.z); Serial.print(" m/s^2 ");

	Serial.print(F("  Angle: "));
	Serial.println(atan2(event.acceleration.z, event.acceleration.x));
#endif

	nsamples++;
	// avgTilt += atan2(event.acceleration.z, event.acceleration.x);
	avgTilt += asin(event.acceleration.z / 10.8);
	float delta = event.acceleration.x - meanZ;
	meanZ = meanZ + delta / (float) nsamples;
	m2 = m2 + delta*(event.acceleration.x - meanZ);

	return;
}