|
00001 /*!@addtogroup Dexter_Industries 00002 * @{ 00003 * @defgroup dPress dPressure Sensor 00004 * Dexter Industries dPressure Sensor driver 00005 * @{ 00006 */ 00007 00008 /* 00009 * $Id: dexterind-pressure.h 133 2013-03-10 15:15:38Z xander $ 00010 */ 00011 00012 #ifndef __DPRESS_DRIVER_H__ 00013 #define __DPRESS_DRIVER_H__ 00014 00015 /** \file dexterind-pressure.h 00016 * \brief ROBOTC dPressure Sensor Driver 00017 * 00018 * DPRESS-driver.h provides an API for the Dexter Industries dPressure Sensor. 00019 * 00020 * Changelog: 00021 * - 0.1: Initial release 00022 * 00023 * Credits : 00024 * - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this. 00025 * 00026 * License: You may use this code as you wish, provided you give credit where its due. 00027 * 00028 * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. 00029 00030 * \author Xander Soldaat (mightor@gmail.com) 00031 * \date 13 June 2010 00032 * \version 0.1 00033 * \example dexterind-pressure-test1.c 00034 */ 00035 00036 #pragma systemFile 00037 00038 #define DPRESS_VREF 4.85 /*!< The voltage reference is assumed to be around 4V85 */ 00039 00040 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00041 // Function prototypes 00042 bool DPRESSreadPress250kPa(tSensors link, float &pressure); 00043 bool DPRESSreadPress250PSI(tSensors link, float &pressure); 00044 bool DPRESSreadPress500kPa(tSensors link, float &pressure); 00045 bool DPRESSreadPress500PSI(tSensors link, float &pressure); 00046 00047 /** 00048 * Read the pressure in kiloPascals\n 00049 * Note: This function is for the dPressure 250 00050 * @param link the dPressure Sensor port number 00051 * @param pressure the pressure in kiloPascals 00052 * @return true if no error occured, false if it did 00053 */ 00054 00055 bool DPRESSreadPress250kPa(tSensors link, float &pressure) { 00056 float Vout = 0.0; 00057 00058 int val = 0; 00059 00060 // dPressure sensor type must absolutely be set to sensorAnalogInactive 00061 if (SensorType[link] != sensorAnalogInactive) 00062 return false; 00063 00064 // Pressure is calculated using Vout = VS x (0.00369 x P + 0.04) 00065 // => P 00066 // Where Vs is assumed to be equal to around 4.85 on the NXT 00067 00068 // Get raw sensor value 00069 val = SensorValue[link]; 00070 00071 // Calculate Vout 00072 Vout = ((val * DPRESS_VREF) / 1023); 00073 00074 pressure = ((Vout / DPRESS_VREF) - 0.04) / 0.00369; 00075 return true; 00076 } 00077 00078 00079 /** 00080 * Read the pressure in kiloPascals\n 00081 * Note: This function is for the dPressure 250 00082 * @param link the dPressure Sensor port number 00083 * @param pressure the pressure in Pounds per Square Inch 00084 * @return true if no error occured, false if it did 00085 */ 00086 bool DPRESSreadPress250PSI(tSensors link, float &pressure) { 00087 return true; 00088 } 00089 00090 00091 /** 00092 * Read the pressure in kiloPascals\n 00093 * Note: This function is for the dPressure 500 00094 * @param link the dPressure 500 Sensor port number 00095 * @param pressure the pressure in kiloPascals 00096 * @return true if no error occured, false if it did 00097 */ 00098 bool DPRESSreadPress500kPa(tSensors link, float &pressure) { 00099 float Vout = 0.0; 00100 00101 int val = 0; 00102 00103 // dPressure sensor type must absolutely be set to sensorAnalogInactive 00104 if (SensorType[link] != sensorAnalogInactive) 00105 return false; 00106 00107 // Pressure is calculated using Vout = VS x (0.0018 x P + 0.04) 00108 // => P 00109 // Where Vs is assumed to be equal to around 4.85 on the NXT 00110 00111 // Get raw sensor value 00112 val = SensorValue[link]; 00113 00114 // Calculate Vout 00115 Vout = ((val * DPRESS_VREF) / 1023); 00116 00117 pressure = ((Vout / DPRESS_VREF) - 0.04) / 0.0018; 00118 return true; 00119 } 00120 00121 00122 /** 00123 * Read the pressure in kiloPascals\n 00124 * Note: This function is for the dPressure 500 00125 * @param link the dPressure 500 Sensor port number 00126 * @param pressure the pressure in Pounds per Square Inch 00127 * @return true if no error occured, false if it did 00128 */ 00129 bool DPRESSreadPress500PSI(tSensors link, float &pressure) { 00130 return true; 00131 } 00132 00133 00134 #endif // __DPRESS_DRIVER_H__ 00135 00136 /* 00137 * $Id: dexterind-pressure.h 133 2013-03-10 15:15:38Z xander $ 00138 */ 00139 /* @} */ 00140 /* @} */