Implemented first Hangar-Service

Dependencies:   CalibrateMagneto QuaternionMath

Fork of SML2 by TobyRich GmbH

Gyroscope.h

Committer:
uadhikari
Date:
2015-05-29
Revision:
44:5483079fa156
Parent:
40:8e852115fe55

File content as of revision 44:5483079fa156:

#ifndef _H_GYROSCOPE_H
#define _H_GYROSCOPE_H

#include "I2CPeripheral.h"
#include "Sensor.h"

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(); 
    
    /**
     * 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:
    int numSamples;     //Counter for calibration
    Vector3 offset;     //Gyroscope noise compensation offset
    InterruptIn int1;   //Interrupt from the gyroscope
    InterruptIn int2;
    size_t      tick;
};

#endif//_H_GYROSCOPE_H