Gyro Sensor Library

Committer:
bant62
Date:
Mon Jul 16 03:42:01 2012 +0000
Revision:
0:da10b9c9db7a
init revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bant62 0:da10b9c9db7a 1 /**
bant62 0:da10b9c9db7a 2 *****************************************************************************
bant62 0:da10b9c9db7a 3 * File Name : GyroSensor.h
bant62 0:da10b9c9db7a 4 *
bant62 0:da10b9c9db7a 5 * Title : Gyro Sensor Class Header File
bant62 0:da10b9c9db7a 6 * Revision : 0.1
bant62 0:da10b9c9db7a 7 * Notes :
bant62 0:da10b9c9db7a 8 * Target Board : mbed NXP LPC1768
bant62 0:da10b9c9db7a 9 * Tool Chain : ????
bant62 0:da10b9c9db7a 10 *
bant62 0:da10b9c9db7a 11 * Revision History:
bant62 0:da10b9c9db7a 12 * When Who Description of change
bant62 0:da10b9c9db7a 13 * ----------- ----------- -----------------------
bant62 0:da10b9c9db7a 14 * 2012/07/10 Hiroshi M init
bant62 0:da10b9c9db7a 15 *****************************************************************************
bant62 0:da10b9c9db7a 16 *
bant62 0:da10b9c9db7a 17 * Copyright (C) 2012 Hiroshi M, MIT License
bant62 0:da10b9c9db7a 18 *
bant62 0:da10b9c9db7a 19 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
bant62 0:da10b9c9db7a 20 * and associated documentation files (the "Software"), to deal in the Software without restriction,
bant62 0:da10b9c9db7a 21 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
bant62 0:da10b9c9db7a 22 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
bant62 0:da10b9c9db7a 23 * furnished to do so, subject to the following conditions:
bant62 0:da10b9c9db7a 24 *
bant62 0:da10b9c9db7a 25 * The above copyright notice and this permission notice shall be included in all copies or
bant62 0:da10b9c9db7a 26 * substantial portions of the Software.
bant62 0:da10b9c9db7a 27 *
bant62 0:da10b9c9db7a 28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
bant62 0:da10b9c9db7a 29 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
bant62 0:da10b9c9db7a 30 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
bant62 0:da10b9c9db7a 31 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bant62 0:da10b9c9db7a 32 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
bant62 0:da10b9c9db7a 33 *
bant62 0:da10b9c9db7a 34 **/
bant62 0:da10b9c9db7a 35
bant62 0:da10b9c9db7a 36 #ifndef MBED_GYRO_SENSOR_H
bant62 0:da10b9c9db7a 37 #define MBED_GYRO_SENSOR_H
bant62 0:da10b9c9db7a 38
bant62 0:da10b9c9db7a 39 /* Includes ----------------------------------------------------------------- */
bant62 0:da10b9c9db7a 40 #include "mbed.h"
bant62 0:da10b9c9db7a 41
bant62 0:da10b9c9db7a 42 /* typedef ------------------------------------------------------------------ */
bant62 0:da10b9c9db7a 43 typedef enum {CLEAR,INI,IDLE,READY} GyroState;
bant62 0:da10b9c9db7a 44
bant62 0:da10b9c9db7a 45 typedef GyroState (*GYRO_CALLBACK_FUNC)(int gyv, int gyv, int offset);
bant62 0:da10b9c9db7a 46 typedef int (*GET_DISTANCE_GAIN_FUNC)(void);
bant62 0:da10b9c9db7a 47 typedef int (*GET_DISTANCE_FEEDBACK_FUNC)(void);
bant62 0:da10b9c9db7a 48
bant62 0:da10b9c9db7a 49 /* define ------------------------------------------------------------------- */
bant62 0:da10b9c9db7a 50 #define INI_COUNT 16
bant62 0:da10b9c9db7a 51 #define AV_COUNT 32
bant62 0:da10b9c9db7a 52
bant62 0:da10b9c9db7a 53 /* macro -------------------------------------------------------------------- */
bant62 0:da10b9c9db7a 54 /* variables ---------------------------------------------------------------- */
bant62 0:da10b9c9db7a 55
bant62 0:da10b9c9db7a 56 /* class define --------------------------------------------------------------*/
bant62 0:da10b9c9db7a 57 class GyroSensor
bant62 0:da10b9c9db7a 58 {
bant62 0:da10b9c9db7a 59 public:
bant62 0:da10b9c9db7a 60 GyroSensor(PinName _pin_no, GYRO_CALLBACK_FUNC _p_callack, GET_DISTANCE_FEEDBACK_FUNC _p_feedback, GET_DISTANCE_GAIN_FUNC _p_disatnce_gain);
bant62 0:da10b9c9db7a 61 ~GyroSensor();
bant62 0:da10b9c9db7a 62
bant62 0:da10b9c9db7a 63 void Enable(void);
bant62 0:da10b9c9db7a 64 void Disable(void);
bant62 0:da10b9c9db7a 65
bant62 0:da10b9c9db7a 66 GyroState getState(void);
bant62 0:da10b9c9db7a 67 int getAngle(void);
bant62 0:da10b9c9db7a 68 int getVelocity(void);
bant62 0:da10b9c9db7a 69 int getOffset(void);
bant62 0:da10b9c9db7a 70
bant62 0:da10b9c9db7a 71 void setReady(void);
bant62 0:da10b9c9db7a 72 void setIdle(void);
bant62 0:da10b9c9db7a 73
bant62 0:da10b9c9db7a 74
bant62 0:da10b9c9db7a 75 private:
bant62 0:da10b9c9db7a 76 int gya; //
bant62 0:da10b9c9db7a 77 int gyv; //
bant62 0:da10b9c9db7a 78 int offset; //
bant62 0:da10b9c9db7a 79
bant62 0:da10b9c9db7a 80 int adcav;
bant62 0:da10b9c9db7a 81 int offset_count;
bant62 0:da10b9c9db7a 82 int offset_ini_count;
bant62 0:da10b9c9db7a 83 long int offset_sum;
bant62 0:da10b9c9db7a 84 long int offset_sum_old;
bant62 0:da10b9c9db7a 85 long int offset_sum_ini;
bant62 0:da10b9c9db7a 86 long int offset_sum_old_ini;
bant62 0:da10b9c9db7a 87 long int gyaa;
bant62 0:da10b9c9db7a 88
bant62 0:da10b9c9db7a 89 int d_fb;
bant62 0:da10b9c9db7a 90 int d_gain;
bant62 0:da10b9c9db7a 91
bant62 0:da10b9c9db7a 92 GyroState state;
bant62 0:da10b9c9db7a 93
bant62 0:da10b9c9db7a 94 GYRO_CALLBACK_FUNC callback;
bant62 0:da10b9c9db7a 95 GET_DISTANCE_FEEDBACK_FUNC getDistanceFeedback;
bant62 0:da10b9c9db7a 96 GET_DISTANCE_GAIN_FUNC getDisatnceGain;
bant62 0:da10b9c9db7a 97
bant62 0:da10b9c9db7a 98 void getParameter(void);
bant62 0:da10b9c9db7a 99
bant62 0:da10b9c9db7a 100 AnalogIn gyro_adc_in;
bant62 0:da10b9c9db7a 101 Ticker Pulse;
bant62 0:da10b9c9db7a 102
bant62 0:da10b9c9db7a 103 void ad_conv(void);
bant62 0:da10b9c9db7a 104 void gyro_control(void);
bant62 0:da10b9c9db7a 105
bant62 0:da10b9c9db7a 106 };
bant62 0:da10b9c9db7a 107
bant62 0:da10b9c9db7a 108 #endif