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

dexterind-temp.h

Go to the documentation of this file.
00001 /*!@addtogroup Dexter_Industries
00002  * @{
00003  * @defgroup dTemp Temp Probe
00004  * Dexter Industries Temperature Probe Sensor driver
00005  * @{
00006  */
00007 
00008 /*
00009  * $Id: dexterind-temp.h 133 2013-03-10 15:15:38Z xander $
00010  */
00011 
00012 #ifndef __DTMP_DRIVER_H__
00013 #define __DTMP_DRIVER_H__
00014 
00015 /** \file dexterind-temp.h
00016  * \brief ROBOTC DI Temp Probe Driver
00017  *
00018  * dexterind-temp.h provides an API for the Dexter Industries Temperature Probe.
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-temp-test1.c
00034  */
00035 
00036 #pragma systemFile
00037 
00038 // internal lookup tables used for resistance to temp conversions
00039 const float _a[] = {0.003357042,         0.003354017,        0.0033530481,       0.0033536166};
00040 const float _b[] = {0.00025214848,       0.00025617244,      0.00025420230,      0.000253772};
00041 const float _c[] = {0.0000033743283,     0.0000021400943,    0.0000011431163,    0.00000085433271};
00042 const float _d[] = {-0.000000064957311, -0.000000072405219, -0.000000069383563, -0.000000087912262};
00043 
00044 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
00045 // Function prototypes
00046 bool DTMPreadTemp(tSensors link, float &temp);
00047 bool DTMPreadTempK(tSensors link, float &temp);
00048 bool DTMPreadTempF(tSensors link, float &temp);
00049 
00050 
00051 /**
00052  * Read the temperature in degrees Celcius.
00053  * @param link the DI Temp Sensor port number
00054  * @param temp the temperature value in degrees Celcius,
00055  * @return true if no error occured, false if it did
00056  */
00057 bool DTMPreadTemp(tSensors link, float &temp) {
00058   float _tempK = 0.0;
00059   if (!DTMPreadTempK(link, _tempK))
00060     return false;
00061 
00062   temp = _tempK - 273;
00063   return true;
00064 }
00065 
00066 
00067 /**
00068  * Read the temperature in Kelvin.
00069  * @param link the DI Temp Sensor port number
00070  * @param temp the temperature value in Kelvin,
00071  * @return true if no error occured, false if it did
00072  */
00073 bool DTMPreadTempK(tSensors link, float &temp) {
00074   // local vars
00075   byte i = 0;
00076   int val = 0;
00077   float RtRt25 = 0.0;
00078   float lnRtRt25 = 0.0;
00079 
00080   // Temp sensor type must absolutely be set to sensorAnalogInactive
00081   if (SensorType[link] != sensorAnalogInactive)
00082     return false;
00083 
00084   // Get the basic factors for equation
00085   val = SensorValue[link];
00086   RtRt25 = (float)val / (1023 - val);
00087   lnRtRt25 = log(RtRt25);
00088 
00089   if (RtRt25 > 3.277)
00090     i = 0;
00091   else if (RtRt25 > 0.3599)
00092     i = 1;
00093   else if (RtRt25 > 0.06816)
00094     i = 2;
00095   else
00096     i = 3;
00097 
00098   temp =  1.0 / (_a[i] + (_b[i] * lnRtRt25) + (_c[i] * lnRtRt25 * lnRtRt25) + (_d[i] * lnRtRt25 * lnRtRt25 * lnRtRt25));
00099 
00100   return true;
00101 }
00102 
00103 
00104 /**
00105  * Read the temperature in Fahrenheit.
00106  * @param link the DI Temp Sensor port number
00107  * @param temp the temperature value in Fahrenheit,
00108  * @return true if no error occured, false if it did
00109  */
00110 bool DTMPreadTempF(tSensors link, float &temp) {
00111   float _tempK = 0.0;
00112   if (!DTMPreadTempK(link, _tempK))
00113     return false;
00114 
00115   temp = 32 + ((_tempK - 273) * 9) / 5;
00116 
00117   return true;
00118 }
00119 
00120 #endif // __DTMP_DRIVER_H__
00121 
00122 /*
00123  * $Id: dexterind-temp.h 133 2013-03-10 15:15:38Z xander $
00124  */
00125 /* @} */
00126 /* @} */