1 /* 2 * Author: Jon Trulson <jtrulson (at) ics.com> 3 * Copyright (c) 2014 Intel Corporation. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining 6 * a copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sublicense, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be 14 * included in all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 */ 24 #pragma once 25 26 #include <string> 27 #include <mraa/aio.h> 28 29 namespace upm { 30 31 /** 32 * @brief ENC03R Single Axis Gyro library 33 * @defgroup enc03r libupm-enc03r 34 * @ingroup seeed analog compass robok 35 */ 36 37 /** 38 * @library enc03r 39 * @sensor enc03r 40 * @comname ENC03R Single Axis Gyro 41 * @altname Grove Single Axis Analog Gyro 42 * @type compass 43 * @man seeed 44 * @con analog 45 * @kit robok 46 * 47 * @brief API for the ENC03R Single Axis Analog Gyro 48 * 49 * UPM module for the ENC03R single axis analog gyro. 50 * This gyroscope measures x-axis angular velocity, that is 51 * how fast the sensor is rotating around the x-axis. 52 * Calibration of the sensor is necessary for accurate readings. 53 * 54 * @image html enc03r.jpg 55 * @snippet enc03r.cxx Interesting 56 */ 57 class ENC03R { 58 public: 59 60 /** 61 * ENC03R sensor constructor 62 * 63 * @param pin Analog pin to use 64 * @param vref Reference voltage to use; default is 5.0 V 65 */ 66 ENC03R(int pin, float vref=5.0); 67 68 /** 69 * ENC03R destructor 70 */ 71 ~ENC03R(); 72 73 /** 74 * Calibrates the sensor by determining an analog reading over many 75 * samples with no movement of the sensor. This must be done 76 * before attempting to use the sensor. 77 * 78 * @param samples Number of samples to use for calibration 79 */ 80 void calibrate(unsigned int samples); 81 82 /** 83 * Returns the raw value of the sensor 84 * 85 * @return Raw value of the sensor 86 */ 87 unsigned int value(); 88 89 /** 90 * Returns the currently stored calibration value 91 * 92 * @return Current calibration value 93 */ 94 float calibrationValue() { return m_calibrationValue; }; 95 96 /** 97 * Computes angular velocity based on the value and stored calibration 98 * reference. 99 * 100 * @param val Value to use to compute angular velocity 101 * @return Computed angular velocity 102 */ 103 double angularVelocity(unsigned int val); 104 105 private: 106 // determined by calibrate(); 107 float m_calibrationValue; 108 109 // reference voltage 110 float m_vref; 111 mraa_aio_context m_aio; 112 }; 113 } 114 115 116