Exemple #1
0
void setupAccel(){
	if(!accel.begin()){
		Serial.println("Failed to init sensor");
	}

	else accel.setRange(ADXL345_RANGE_4_G);
}
Exemple #2
0
void GY80Task::setupADXL345()
{
	/* Initialise the sensor */
	if (!accel.begin())
	{
		/* There was a problem detecting the ADXL345 ... check your connections */
		LogUtils::instance()->logTrace(LogUtils::error, "Ooops, no ADXL345 detected ... Check your wiring!");
		while (1);
	}

	/* Set the range to whatever is appropriate for your project */
	accel.setRange(ADXL345_RANGE_16_G);
}
Exemple #3
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 ");
}
Exemple #4
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;
}