Kouki Suzuki / IRsensor

Dependents:   IRsensor_sample 2019NHK_A_sensor 200_yotsuba_21

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers IRsensor.h Source File

IRsensor.h

Go to the documentation of this file.
00001 /**
00002 * @file IRsensor.h
00003 * @brief SHARP 2Y0A21を使ったIR距離測定
00004 *
00005 * Example :
00006 * @code
00007 * #include"mbed.h"
00008 * #include"IRsensor.h"
00009 * 
00010 * IRsensor ir1(PC_1);
00011 *
00012 * Serial pc(USBTX,USBRX,115200);
00013 *
00014 * int main()
00015 * {
00016 *    ir1.startAveraging(255);
00017 *    while(1){
00018 *        float dis = ir1.getDistance();
00019 *        float ave_dis = ir1.get_Averagingdistance();
00020 *        pc.printf("dis:%4.4f[cm]||ave_dis:%4.4f[cm]\n\r",dis,ave_dis);
00021 *        
00022 *    }   
00023 * }
00024 * @endcode
00025 */
00026 
00027 #ifndef IRSENSOR_H
00028 #define IRSENSOE_H
00029 
00030 #include"mbed.h"
00031 
00032 /**
00033 * @brief SHARP 2Y0A21を使ったIR距離測定のクラス
00034 */
00035 class IRsensor{
00036  public:
00037     /**
00038      * @brief コンストラクタ
00039      * @param pin Pint that can do analogin
00040      */
00041     IRsensor(PinName pin);
00042     
00043     /**
00044     * @brief センサの値を取得
00045     * @return voltage
00046     */
00047     float getVoltage();
00048     
00049     /**
00050     * @brief センサの値を距離変換し取得
00051     * @return originaldistance
00052     */
00053     float getDistance();
00054     
00055     /**
00056     * @brief 距離の平均化設定
00057     * @param averaging_range averaging range 1~255
00058     */
00059     void startAveraging(uint8_t averaging_range);
00060     
00061     /**
00062     * @brief 平均化した距離を取得
00063     * @return distance_average
00064     */
00065     float get_Averagingdistance();
00066 
00067 private:
00068     void threadloop_get_distance();
00069     void threadloop_averaging_distance();
00070     void compute_distance();
00071     void getInputvoltage();
00072     void changeVtoD();
00073     void computeaverage();
00074     
00075     float voltage;
00076     float originaldistance;
00077     float* data;
00078     float distance_sum;
00079     float distance_average;
00080     uint8_t bufferSize;
00081     uint8_t bufferpoint;
00082     Thread thread_get_distance;
00083     Thread thread_averaging_distance;
00084     AnalogIn a_in;
00085 
00086 };
00087 
00088 #endif