-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensor.c
100 lines (81 loc) · 3.6 KB
/
sensor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* c't-Sim - Robotersimulator fuer den c't-Bot
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your
* option) any later version.
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307, USA.
*
*/
/*! @file sensor.c
* @brief Architekturunabhaengiger Teil der Sensorsteuerung
* @author Benjamin Benz ([email protected])
* @date 15.01.05
*/
#include "ct-Bot.h"
#include "timer.h"
#include "bot-local.h"
#ifdef SRF10_AVAILABLE
#include "srf10.h"
#endif
volatile int16 sensLDRL=0; /*!< Lichtsensor links */
volatile int16 sensLDRR=0; /*!< Lichtsensor rechts */
volatile int16 sensDistL=1023; /*!< Distanz linker IR-Sensor in [mm], wenn korrekt umgerechnet wird */
volatile int16 sensDistR=1023; /*!< Distanz rechter IR-Sensor in [mm], wenn korrekt umgerechnet wird */
volatile int16 sensBorderL=0; /*!< Abgrundsensor links */
volatile int16 sensBorderR=0; /*!< Abgrundsensor rechts */
volatile int16 sensLineL=0; /*!< Lininensensor links */
volatile int16 sensLineR=0; /*!< Lininensensor rechts */
volatile uint8 sensTrans=0; /*!< Sensor Ueberwachung Transportfach */
volatile uint8 sensDoor=0; /*!< Sensor Ueberwachung Klappe */
volatile uint8 sensError=0; /*!< Ueberwachung Motor oder Batteriefehler */
volatile int8 sensMouseDX; /*!< Maussensor Delta X, positive Werte zeigen querab der Fahrtrichtung nach rechts */
volatile int8 sensMouseDY; /*!< Maussensor Delta Y, positive Werte zeigen in Fahrtrichtung */
volatile int sensMouseX; /*!< Mausposition X, positive Werte zeigen querab der Fahrtrichtung nach rechts */
volatile int sensMouseY; /*!< Mausposition Y, positive Werte zeigen in Fahrtrichtung */
volatile int16 sensEncL=0; /*!< Encoder linker Motor */
volatile int16 sensEncR=0; /*!< Encoder rechter Motor */
volatile int16 v_left; /*!< Abrollgeschwindigkeit des linken Rades in [mm/s] [-128 bis 127] relaisitisch [-50 bis 50] */
volatile int16 v_right; /*!< Abrollgeschwindigkeit des linken Rades in [mm/s] [-128 bis 127] relaisitisch [-50 bis 50] */
volatile int8 sensors_initialized = 0; /*!< Wird 1 sobald die Sensorwerte zur Verfügung stehen */
#ifdef SRF10_AVAILABLE
volatile uint16 sensSRF10; /*!< Messergebniss Ultraschallsensor */
#endif
/*! Sensor_update
* Kümmert sich um die Weiterverarbeitung der rohen Sensordaten
*/
void sensor_update(void){
#ifdef TIME_AVAILABLE
static int16 lastTime =0;
#endif
static int16 lastEncL =0;
static int16 lastEncR =0;
sensMouseY += sensMouseDY;
sensMouseX += sensMouseDX;
#ifdef TIME_AVAILABLE
if (timer_get_s() != lastTime) { // sollte genau 1x pro Sekunde zutreffen
#endif
v_left= ((sensEncL - lastEncL) * WHEEL_PERIMETER) / ENCODER_MARKS;
v_right= ((sensEncR - lastEncR) * WHEEL_PERIMETER) / ENCODER_MARKS;
lastEncL= sensEncL;
lastEncR= sensEncR;
#ifdef TIME_AVAILABLE
lastTime = timer_get_s();
#endif
#ifdef SRF10_AVAILABLE
sensSRF10 = srf10_get_measure(); /*!< Messung Ultraschallsensor */
#endif
#ifdef TIME_AVAILABLE
}
#endif
sensors_initialized=1;
}