This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
rc2007-soccer/source/Concept/Framework/modules/input/distance_sensor.h

94 lines
2.3 KiB
C
Raw Normal View History

2007-02-18 00:14:00 +00:00
#ifndef _DISTANCE_SENSOR_H
#define _DISTANCE_SENSOR_H
#include "../../stdafx.h"
2007-02-22 14:08:01 +00:00
#include "sensor.h"
#define SRF10_MIN_GAIN 0 /*!< setze Verstaerung auf 40 */
#define SRF10_MAX_GAIN 16 /*!< setze Verstaerung auf 700 */
#define SRF10_MIN_RANGE 0 /*!< Minimale Reichweite 43mm */
#define SRF10_MAX_RANGE 5977 /*!< Maximale Reichweite 5977mm */
2007-02-22 20:59:02 +00:00
#define SRF10_INCHES 0x50 /*!< Messung in INCHES */
#define SRF10_CENTIMETERS 0x51 /*!< Messung in CM */
#define SRF10_MICROSECONDS 0x52 /*!< Messung in Millisekunden */
2007-02-22 14:08:01 +00:00
#define SRF10_COMMAND 0 /*!< W=Befehls-Register R=Firmware*/
#define SRF10_LIGHT 1 /*!< W=Verstaerkungsfaktor R=Nicht benutzt */
#define SRF10_HIB 2 /*!< W=Reichweite R=Messung High-Byte */
#define SRF10_LOB 3 /*!< W=Nicht benutzt R=Messung Low-Byte */
2007-02-18 00:14:00 +00:00
class Distance_Sensor : public Sensor
{
public:
Distance_Sensor()
{
this->parent = NULL;
2007-02-22 14:08:01 +00:00
this->moduleId = 0;
this->slaveAddr = 0; // Set the I2C Slave-Adress
2007-02-18 00:14:00 +00:00
}
Distance_Sensor(uint32 sensorId)
{
this->parent = NULL;
this->moduleId = sensorId;
switch(sensorId)
{
2007-02-22 14:08:01 +00:00
case IO_SENSOR_DISTANCE_0_DEG:
this->slaveAddr = 0xE0; // Set the I2C Slave-Adress
2007-02-18 00:14:00 +00:00
break;
2007-02-22 14:08:01 +00:00
case IO_SENSOR_DISTANCE_90_DEG:
this->slaveAddr = 0xE2;
2007-02-18 00:14:00 +00:00
break;
2007-02-22 14:08:01 +00:00
case IO_SENSOR_DISTANCE_180_DEG:
this->slaveAddr = 0xE4;
2007-02-18 00:14:00 +00:00
break;
2007-02-22 14:08:01 +00:00
case IO_SENSOR_DISTANCE_270_DEG:
this->slaveAddr = 0xE6;
2007-02-18 00:14:00 +00:00
break;
2007-02-22 14:08:01 +00:00
default:
this->slaveAddr = 0;
2007-02-18 00:14:00 +00:00
break;
2007-02-22 20:59:02 +00:00
}
//SetRange(100);
SetRange(2000);
SetSignalFactor(0x06);
2007-02-18 00:14:00 +00:00
}
protected:
2007-02-22 14:08:01 +00:00
//Hardware
2007-02-22 20:59:02 +00:00
uint8 slaveAddr;
void SetSignalFactor(uint8 factor);
void SetRange(uint16 millimeters);
2007-02-22 14:08:01 +00:00
/*!
* Messung ausloesen
* @param metric_unit 0x50 in Zoll, 0x51 in cm, 0x52 ms
* @return Resultat der Aktion
*/
2007-02-22 20:59:02 +00:00
uint8 srf10_ping(uint8 metric_unit);
2007-02-22 14:08:01 +00:00
/*!
* Register auslesen
* @param srf10_register welches Register soll ausgelsen werden
* @return Inhalt des Registers
*/
2007-02-22 20:59:02 +00:00
uint8 ReadRegister(uint8 registerToRead);
2007-02-22 14:08:01 +00:00
/*!
* Messung starten Ergebniss aufbereiten und zurueckgeben
* @return Messergebniss
*/
2007-02-22 20:59:02 +00:00
uint16 srf10_get_measure(void);
2007-02-18 00:14:00 +00:00
public:
2007-02-22 20:59:02 +00:00
uint16 GetDistance();
void SetSlaveAddress(uint8 newSlaveAddress);
2007-02-18 00:14:00 +00:00
};
#endif