Implemented first Hangar-Service
Dependencies: CalibrateMagneto QuaternionMath
Fork of SML2 by
Diff: Gyroscope.h
- Revision:
- 44:5483079fa156
- Parent:
- 40:8e852115fe55
--- a/Gyroscope.h Wed May 27 11:45:00 2015 +0000 +++ b/Gyroscope.h Fri May 29 12:21:31 2015 +0000 @@ -7,20 +7,53 @@ class Gyroscope : public I2CPeripheral, public Sensor { public: + /* Flag to indicate if Gryoscope is calibrated or not */ + bool isCalibrated; + Gyroscope(I2C &i2c); void handleInterrupt(void); - + + /** + * Incrementally calculates the average noise offset + * with every interrupt received from gyroscope + * until the desired iteration is reached + */ + void calibtrationInterrupt(void); + virtual void powerOff(); virtual bool powerOn(); virtual void start(); - virtual void stop(); + virtual void stop(); + + /** + * Returns raw x,y,z data from obtained from gyroscpe + */ + virtual Vector3 uncalibrated_read(); + + /** + * Returns calibrated x,y,z values from gyroscope + * The offset calculated from calibration is added + * to the raw data: + * value = (rawValue + noiseOffset) * gyro_resolution + */ virtual Vector3 read(); + /** + * Changes the interrupt handler of gyro + * to calibrationInterrupt, which is responsible + * for calculating noise offset + */ + virtual void calibrate(); volatile bool interruptSet; - + + /* Sets offset to zero*/ + virtual void reset(); + protected: - InterruptIn int1; + int numSamples; //Counter for calibration + Vector3 offset; //Gyroscope noise compensation offset + InterruptIn int1; //Interrupt from the gyroscope InterruptIn int2; size_t tick; };