summaryrefslogtreecommitdiffstats
path: root/source/Concept/Framework/modules/input
diff options
context:
space:
mode:
authorsicarius <devnull@localhost>2007-02-22 21:59:02 +0100
committersicarius <devnull@localhost>2007-02-22 21:59:02 +0100
commitf544ab78229d3a4d54b910135ba61bb816009589 (patch)
tree6b1d9aad746299631a0b67661c2d2be62b5e7525 /source/Concept/Framework/modules/input
parentdc8b1cde313f3f8a60462187bbeeea4277fd0313 (diff)
downloadrc2007-soccer-f544ab78229d3a4d54b910135ba61bb816009589.tar
rc2007-soccer-f544ab78229d3a4d54b910135ba61bb816009589.zip
The Last Day ?
Diffstat (limited to 'source/Concept/Framework/modules/input')
-rwxr-xr-xsource/Concept/Framework/modules/input/distance_sensor.c96
-rwxr-xr-xsource/Concept/Framework/modules/input/distance_sensor.h47
-rwxr-xr-xsource/Concept/Framework/modules/input/ir_sensor.h4
3 files changed, 75 insertions, 72 deletions
diff --git a/source/Concept/Framework/modules/input/distance_sensor.c b/source/Concept/Framework/modules/input/distance_sensor.c
index 1ab3755..239e63b 100755
--- a/source/Concept/Framework/modules/input/distance_sensor.c
+++ b/source/Concept/Framework/modules/input/distance_sensor.c
@@ -1,22 +1,12 @@
-#include "distance_sensor.h"
-
-/*!
- * SRF10 initialsieren
- */
-
-void Distance_Sensor::srf10_init(void){
- srf10_set_range(SRF10_MAX_RANGE);
- //srf10_set_range(6); //Mit diesem Wert muss man spielen um das Optimum zu ermitteln
-return;
-}
-
-/*!
- * Verstaerkungsfaktor setzen
- * @param gain Verstaerkungsfaktor
- */
-
-void Distance_Sensor::srf10_set_gain(unsigned char gain){
- if(gain>16) { gain=16; }
+#include "distance_sensor.h"
+
+//-----------------------------------------------------------------------------
+void Distance_Sensor::SetSignalFactor(uint8 factor)
+{
+ if(factor > 16)
+ {
+ factor = 16;
+ }
uint8 temp[2];
uint8 state;
@@ -24,30 +14,59 @@ void Distance_Sensor::srf10_set_gain(unsigned char gain){
state = SUCCESS;
- tx_frame[0].slave_adr = this->slaveAddr+W;
+ tx_frame[0].slave_adr = this->slaveAddr + W;
tx_frame[0].size = 2;
tx_frame[0].data_ptr = temp;
tx_frame[0].data_ptr[0] = 1;
- tx_frame[0].data_ptr[1] = gain;
+ tx_frame[0].data_ptr[1] = factor;
tx_frame[1].slave_adr = OWN_ADR;
state = Send_to_TWI(tx_frame);
+}
+
+//-----------------------------------------------------------------------------
+void Distance_Sensor::SetSlaveAddress(uint8 newSlaveAddress)
+{
+ uint8 temp[2];
+ uint8 state;
+ tx_type tx_frame[2];
+
+ state = SUCCESS;
+
+ tx_frame[0].slave_adr = this->slaveAddr + W;
+ tx_frame[0].size = 2;
+ tx_frame[0].data_ptr = temp;
+ tx_frame[0].data_ptr[0] = 0;
+ tx_frame[0].data_ptr[1] = 160;
+ tx_frame[1].slave_adr = OWN_ADR;
+ state = Send_to_TWI(tx_frame);
+
+ msleep(60);
+
+ tx_frame[0].data_ptr[1] = 170;
+ state = Send_to_TWI(tx_frame);
+
+ msleep(60);
+
+ tx_frame[0].data_ptr[1] = 165;
+ state = Send_to_TWI(tx_frame);
+
+ msleep(60);
+
+ tx_frame[0].data_ptr[1] = newSlaveAddress;
+ state = Send_to_TWI(tx_frame);
}
-/*!
- * Reichweite setzen, hat auch Einfluss auf die Messdauer
- * @param millimeters Reichweite in mm
- */
-
-void Distance_Sensor::srf10_set_range(unsigned int millimeters){
+//-----------------------------------------------------------------------------
+void Distance_Sensor::SetRange(unsigned int millimeters){
uint8 temp[2];
uint8 state;
tx_type tx_frame[2];
state = SUCCESS;
- millimeters= (millimeters/43);
+ millimeters = (millimeters/43);
tx_frame[0].slave_adr = this->slaveAddr+W;
tx_frame[0].size = 2;
@@ -85,14 +104,9 @@ uint8 Distance_Sensor::srf10_ping(uint8 metric_unit){
return state;
}
-
-/*!
- * Register auslesen
- * @param srf10_register welches Register soll ausgelsen werden
- * @return Inhalt des Registers
- */
-
-uint8 Distance_Sensor::srf10_read_register(uint8 srf10_register){
+
+//-----------------------------------------------------------------------------
+uint8 Distance_Sensor::ReadRegister(uint8 registerToRead){
uint8 temp;
uint8 value;
uint8 state;
@@ -104,7 +118,7 @@ uint8 Distance_Sensor::srf10_read_register(uint8 srf10_register){
tx_frame[0].slave_adr = this->slaveAddr+W;
tx_frame[0].size = 1;
tx_frame[0].data_ptr = &temp;
- tx_frame[0].data_ptr[0] = srf10_register;
+ tx_frame[0].data_ptr[0] = registerToRead;
tx_frame[1].slave_adr = this->slaveAddr+R;
tx_frame[1].size = 1;
@@ -130,10 +144,10 @@ uint16 Distance_Sensor::srf10_get_measure(){
state = SUCCESS;
state = srf10_ping(SRF10_CENTIMETERS);
- usleep(10); //Optimierungs Potential
- lob=srf10_read_register(SRF10_LOB);
- usleep(10); //Optimierungs Potential
- hib=srf10_read_register(SRF1sr0_HIB);
+ msleep(10); //Optimierungs Potential
+ lob=ReadRegister(SRF10_LOB);
+ msleep(10); //Optimierungs Potential
+ hib=ReadRegister(SRF10_HIB);
return (hib*256)+lob;
}
diff --git a/source/Concept/Framework/modules/input/distance_sensor.h b/source/Concept/Framework/modules/input/distance_sensor.h
index 9fb2c58..0bb2baf 100755
--- a/source/Concept/Framework/modules/input/distance_sensor.h
+++ b/source/Concept/Framework/modules/input/distance_sensor.h
@@ -9,9 +9,9 @@
#define SRF10_MIN_RANGE 0 /*!< Minimale Reichweite 43mm */
#define SRF10_MAX_RANGE 5977 /*!< Maximale Reichweite 5977mm */
-#define SRF10_INCHES 0X50 /*!< Messung in INCHES */
-#define SRF10_CENTIMETERS 0X51 /*!< Messung in CM */
-#define SRF10_MICROSECONDS 0X52 /*!< Messung in Millisekunden */
+#define SRF10_INCHES 0x50 /*!< Messung in INCHES */
+#define SRF10_CENTIMETERS 0x51 /*!< Messung in CM */
+#define SRF10_MICROSECONDS 0x52 /*!< Messung in Millisekunden */
#define SRF10_COMMAND 0 /*!< W=Befehls-Register R=Firmware*/
#define SRF10_LIGHT 1 /*!< W=Verstaerkungsfaktor R=Nicht benutzt */
@@ -50,55 +50,44 @@ public:
default:
this->slaveAddr = 0;
break;
- }
-
- // initialiate the sensor
- srf10_init();
+ }
+
+ //SetRange(100);
+ SetRange(2000);
+ SetSignalFactor(0x06);
}
protected:
//Hardware
- slaveAddr;
-
- /*!
- * SRF10 initialsieren
- */
-extern void srf10_init(void);
-
-/*!
- * Verstaerkungsfaktor setzen
- * @param gain Verstaerkungsfaktor
- */
-extern void srf10_set_gain(uint8 gain);
-
-/*!
- * Reichweite setzen, hat auch Einfluss auf die Messdauer
- * @param millimeters Reichweite in mm
- */
-extern void srf10_set_range(uint16 millimeters);
+ uint8 slaveAddr;
+
+ void SetSignalFactor(uint8 factor);
+
+ void SetRange(uint16 millimeters);
/*!
* Messung ausloesen
* @param metric_unit 0x50 in Zoll, 0x51 in cm, 0x52 ms
* @return Resultat der Aktion
*/
-extern uint8 srf10_ping(uint8 metric_unit);
+ uint8 srf10_ping(uint8 metric_unit);
/*!
* Register auslesen
* @param srf10_register welches Register soll ausgelsen werden
* @return Inhalt des Registers
*/
-extern uint8 srf10_read_register(uint8 SRF10_register);
+ uint8 ReadRegister(uint8 registerToRead);
/*!
* Messung starten Ergebniss aufbereiten und zurueckgeben
* @return Messergebniss
*/
-extern uint16 srf10_get_measure(void);
+ uint16 srf10_get_measure(void);
public:
- float GetDistance();
+ uint16 GetDistance();
+ void SetSlaveAddress(uint8 newSlaveAddress);
};
#endif
diff --git a/source/Concept/Framework/modules/input/ir_sensor.h b/source/Concept/Framework/modules/input/ir_sensor.h
index 74396ec..c8f692b 100755
--- a/source/Concept/Framework/modules/input/ir_sensor.h
+++ b/source/Concept/Framework/modules/input/ir_sensor.h
@@ -34,11 +34,11 @@ public:
break;
case IO_SENSOR_IR_100_DEG:
this->channel = 3;
- this->intensityCorrection = 40;
+ this->intensityCorrection = 80;
break;
case IO_SENSOR_IR_180_DEG:
this->channel = 4;
- this->intensityCorrection = 50;
+ this->intensityCorrection = 70;
break;
case IO_SENSOR_IR_260_DEG:
this->channel = 5;