Mindstorms 3rd Party ROBOTC Drivers RobotC
[Home] [Download] [Submit a bug/suggestion] [ROBOTC Forums] [Blog] [Support this project]

DPRESS-driver.h

Go to the documentation of this file.
00001 /*!@addtogroup Dexter_Industries
00002  * @{
00003  * @defgroup dPress dPressure Sensor
00004  * Dexter Industries dPressure Sensor driver
00005  * @{
00006  */
00007 
00008 /*
00009  * $Id: DPRESS-driver.h 29 2010-06-25 12:55:41Z xander $
00010  */
00011 
00012 #ifndef __DPRESS_DRIVER_H__
00013 #define __DPRESS_DRIVER_H__
00014 
00015 /** \file DPRESS-driver.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 2.00 AND HIGHER.
00029  * \author Xander Soldaat (mightor@gmail.com)
00030  * \date 13 June 2010
00031  * \version 0.1
00032  * \example DPRESS-test1.c
00033  */
00034 
00035 #pragma systemFile
00036 
00037 #define DPRESS_VREF 4.85 /*!< The voltage reference is assumed to be around 4V85 */
00038 
00039 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
00040 // Function prototypes
00041 bool DPRESSreadPress250kPa(tSensors link, float &pressure);
00042 bool DPRESSreadPress250PSI(tSensors link, float &pressure);
00043 bool DPRESSreadPress500kPa(tSensors link, float &pressure);
00044 bool DPRESSreadPress500PSI(tSensors link, float &pressure);
00045 
00046 /**
00047  * Read the pressure in kiloPascals\n
00048  * Note: This function is for the dPressure 250
00049  * @param link the dPressure Sensor port number
00050  * @param pressure the pressure in kiloPascals
00051  * @return true if no error occured, false if it did
00052  */
00053 
00054 bool DPRESSreadPress250kPa(tSensors link, float &pressure) {
00055   float Vout = 0.0;
00056 
00057   int val = 0;
00058 
00059   // dPressure sensor type must absolutely be set to sensorAnalogInactive
00060   if (SensorType[link] != sensorAnalogInactive)
00061     return false;
00062 
00063   // Pressure is calculated using Vout = VS x (0.00369 x P + 0.04)
00064   // => P
00065   // Where Vs is assumed to be equal to around 4.85 on the NXT
00066 
00067   // Get raw sensor value
00068   val = SensorValue[link];
00069 
00070   // Calculate Vout
00071   Vout = ((val * DPRESS_VREF) / 1023);
00072 
00073   pressure = ((Vout / DPRESS_VREF) - 0.04) / 0.00369;
00074   return true;
00075 }
00076 
00077 
00078 /**
00079  * Read the pressure in kiloPascals\n
00080  * Note: This function is for the dPressure 250
00081  * @param link the dPressure Sensor port number
00082  * @param pressure the pressure in Pounds per Square Inch
00083  * @return true if no error occured, false if it did
00084  */
00085 bool DPRESSreadPress250PSI(tSensors link, float &pressure) {
00086   return true;
00087 }
00088 
00089 
00090 /**
00091  * Read the pressure in kiloPascals\n
00092  * Note: This function is for the dPressure 500
00093  * @param link the dPressure 500 Sensor port number
00094  * @param pressure the pressure in kiloPascals
00095  * @return true if no error occured, false if it did
00096  */
00097 bool DPRESSreadPress500kPa(tSensors link, float &pressure) {
00098   float Vout = 0.0;
00099 
00100   int val = 0;
00101 
00102   // dPressure sensor type must absolutely be set to sensorAnalogInactive
00103   if (SensorType[link] != sensorAnalogInactive)
00104     return false;
00105 
00106   // Pressure is calculated using Vout = VS x (0.0018 x P + 0.04)
00107   // => P
00108   // Where Vs is assumed to be equal to around 4.85 on the NXT
00109 
00110   // Get raw sensor value
00111   val = SensorValue[link];
00112 
00113   // Calculate Vout
00114   Vout = ((val * DPRESS_VREF) / 1023);
00115 
00116   pressure = ((Vout / DPRESS_VREF) - 0.04) / 0.0018;
00117   return true;
00118 }
00119 
00120 
00121 /**
00122  * Read the pressure in kiloPascals\n
00123  * Note: This function is for the dPressure 500
00124  * @param link the dPressure 500 Sensor port number
00125  * @param pressure the pressure in Pounds per Square Inch
00126  * @return true if no error occured, false if it did
00127  */
00128 bool DPRESSreadPress500PSI(tSensors link, float &pressure) {
00129   return true;
00130 }
00131 
00132 
00133 #endif // __DPRESS_DRIVER_H__
00134 
00135 /*
00136  * $Id: DPRESS-driver.h 29 2010-06-25 12:55:41Z xander $
00137  */
00138 /* @} */
00139 /* @} */