|
00001 /*!@addtogroup mindsensors 00002 * @{ 00003 * @defgroup MSSUMO Sumo Eyes Sensor 00004 * Mindsensors Sumo Eyes Sensor 00005 * @{ 00006 */ 00007 00008 /* 00009 * $Id: mindsensors-sumoeyes.h 133 2013-03-10 15:15:38Z xander $ 00010 */ 00011 00012 #ifndef __MSSUMO_H__ 00013 #define __MSSUMO_H__ 00014 /** \file mindsensors-sumoeyes.h 00015 * \brief Mindsensors Sumo Eyes Sensor driver 00016 * 00017 * mindsensors-sumoeyes.h provides an API for the Mindsensors Sumo Eyes sensor. 00018 * 00019 * Changelog: 00020 * - 0.1: Initial release 00021 * 00022 * Credits: 00023 * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this. 00024 * 00025 * License: You may use this code as you wish, provided you give credit where its due. 00026 * 00027 * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. 00028 00029 * \author Xander Soldaat (xander_at_botbench.com) 00030 * \date 30 October 2011 00031 * \version 0.1 00032 * \example mindsensors-sumoeyes-test1.c 00033 */ 00034 00035 #pragma systemFile 00036 00037 #ifndef __COMMON_H__ 00038 #include "common.h" 00039 #endif 00040 00041 // This ensures the correct sensor types are used. 00042 TSensorTypes MSSUMOLRType = sensorLightInactive; 00043 TSensorTypes MSSUMOSRType = sensorLightActive; 00044 00045 typedef enum { 00046 MSSUMO_NONE = 0, 00047 MSSUMO_FRONT = 1, 00048 MSSUMO_LEFT = 2, 00049 MSSUMO_RIGHT = 3 00050 } tObstacleZone; 00051 00052 tObstacleZone MSSUMOreadZone(tSensors link); 00053 void MSSUMOsetShortRange(tSensors link); 00054 void MSSUMOsetLongRange(tSensors link); 00055 00056 /** 00057 * Get the raw value from the sensor 00058 * @param link the MSSUMO port number 00059 * @return raw value of the sensor 00060 */ 00061 tObstacleZone MSSUMOreadZone(tSensors link) { 00062 int sensordata = 0; 00063 00064 sensordata = SensorValue[link]; 00065 00066 if ( sensordata > 30 && sensordata < 36 ) 00067 { 00068 // obstacle is on left 00069 return (MSSUMO_LEFT); 00070 } 00071 else if ( sensordata > 63 && sensordata < 69 ) 00072 { 00073 // obstacle is on right 00074 return (MSSUMO_RIGHT); 00075 } 00076 else if ( sensordata >= 74 && sensordata <= 80 ) 00077 { 00078 // obstacle is in front. 00079 return (MSSUMO_FRONT); 00080 } 00081 else 00082 { 00083 return (MSSUMO_NONE); 00084 } 00085 } 00086 00087 00088 /** 00089 * Set the range of the sensor to short range, this is done 00090 * by configuring the sensor as sensorLightActive. 00091 * @param link the MSSUMO port number 00092 */ 00093 void MSSUMOsetShortRange(tSensors link) { 00094 if (SensorType[link] != MSSUMOSRType) 00095 SetSensorType(link, MSSUMOSRType); 00096 } 00097 00098 00099 /** 00100 * Set the range of the sensor to long range, this is done 00101 * by configuring the sensor as sensorLightInactive 00102 * @param link the MSSUMO port number 00103 */ 00104 void MSSUMOsetLongRange(tSensors link) { 00105 if (SensorType[link] != MSSUMOLRType) 00106 SetSensorType(link, MSSUMOLRType); 00107 } 00108 00109 00110 #endif // __MSSUMO_H__ 00111 00112 /* 00113 * $Id: mindsensors-sumoeyes.h 133 2013-03-10 15:15:38Z xander $ 00114 */ 00115 /* @} */ 00116 /* @} */