blob: 8ca663d2b4c529cb111b202d5675e4da5b9ed32e [file] [log] [blame]
Mustafa Ozcelikorsa3c19992017-11-28 21:04:44 +01001/*
2 * Copyright (c) 2017 FH Dortmund and others
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Description:
9 * Rover Sensors API - Interfaces for Rover sensors application development
10 * Header file
11 *
12 * Contributors:
13 * M.Ozcelikors <mozcelikors@gmail.com>, created C++ API 17.11.2017
14 * David Schmelter, Fraunhofer IEM - compass sensor initial implementation
15 * Gael Blondelle, Eclipse Foundation - initial API and parameters
16 *
17 */
18
19#ifndef API_ROVER_SENSORS_HPP_
20#define API_ROVER_SENSORS_HPP_
21
22#include <stdint.h>
23#include <stdio.h>
24#include <unistd.h>
25
26namespace rover
27{
28 /**
29 * @brief RoverSensors class contains member functions to setup and read from embedded sensors from rover's RoverSenseLayer sensor layer.
30 */
31 class RoverSensors
32 {
33 private:
34 /* Pins of ultrasonic sensors */
35 /**
36 * @brief Groove Sensor Pin for Front Sensor Socket (in wiringPi format)
37 */
38 static const int SIG0 = 0; //BCM-17 -> WiringPi 0 //Same as ECHO0 pin, if some one wants to replace front sr04 with groove sensor
39
40 /**
41 * @brief Groove Sensor Pin for Rear Sensor Socket (in wiringPi format)
42 */
43 static const int SIG1 = 2; //BCM-27 -> WiringPi 2 //Same as ECHO1 pin, if some one wants to replace back sr04 with groove sensor
44
45 /**
46 * @brief HC-SR04 Sensor Trigger Pin for Front Sensor Socket (in wiringPi format)
47 */
48 static const int TRIG0 = 7; //BCM-4 -> WiringPi 7
49 /**
50 * @brief HC-SR04 Sensor Echo Pin for Front Sensor Socket (in wiringPi format)
51 */
52 static const int ECHO0 = 0; //BCM-17 -> WiringPi 0
53
54 /**
55 * @brief HC-SR04 Sensor Trigger Pin for Rear Sensor Socket (in wiringPi format)
56 */
57 static const int TRIG1 = 1; //BCM-18 -> WiringPi 1
58 /**
59 * @brief HC-SR04 Sensor Echo Pin for Rear Sensor Socket (in wiringPi format)
60 */
61 static const int ECHO1 = 2; //BCM-27 -> WiringPi 2
62
63 /* Definitions related to DHT22 sensor */
64 /**
65 * @brief DHT22 sensor pin in wiringPi format
66 */
67 static const int DHT22_RPI_PIN = 24; //BCM19 -> wiringPi 24
68 static const int MAX_TIMINGS = 85;
69
70 /* Definitions related to compass sensor */
71 /**
72 * @brief Address for compass sensor
73 */
74 static const int HMC588L_ADDRESS = 0x1E;
75 /**
76 * @brief Calibration duration for compass sensor
77 */
78 static const int CALIBRATION_DURATION = 10000; //compass calibration has a duration of 5 seconds
79 /**
80 * @brief Declination angle / correction factor for compass sensor
81 */
82 static const float DECLINATION_ANGLE = 0.0413; //correction factor for location Paderborn
83
84 /**
85 * @brief Calibration variable for HMC588L
86 */
87 unsigned int calibration_start;
88
89 public:
90
91 /* Rover Sensor IDs */
92 /**
93 * @brief Static definition to indicate rover's front ultrasonic sensor socket
94 */
95 static const int ROVER_FRONT = 0;
96
97 /**
98 * @brief Static definition to indicate rover's rear ultrasonic sensor socket
99 */
100 static const int ROVER_REAR = 1;
101
102 /* Rover Infrared Sensor IDs */
103 /**
104 * @brief Static definition to indicate rover's rear-right infrared sensor
105 */
106 static const int ROVER_REAR_RIGHT = 0;
107
108 /**
109 * @brief Static definition to indicate rover's rear-left infrared sensor
110 */
111 static const int ROVER_REAR_LEFT = 1;
112
113 /**
114 * @brief Static definition to indicate rover's front-right infrared sensor
115 */
116 static const int ROVER_FRONT_RIGHT = 2;
117
118 /**
119 * @brief Static definition to indicate rover's front-left infrared sensor
120 */
121 static const int ROVER_FRONT_LEFT = 3;
122
123 /**
124 * @brief Initializes the sensors
125 * @return void
126 */
127 void initialize();
128
129 /***
130 * @brief Constructor for the RoverSensors class.
131 */
132 RoverSensors();
133
134 /**
135 * @brief Sets up the HC-SR04 ultrasonic sensor
136 * @return void
137 */
138 void setupHCSR04UltrasonicSensor(int sensor_id);
139
140 /**
141 * @brief Reads from HC-SR04 ultrasonic sensor in centimeters. sensor_id RoverSensors::ROVER_FRONT: Front ultrasonic sensor, RoverSensors::ROVER_REAR: Rear ultrasonic sensor.
142 * @param sensor_id RoverSensors::ROVER_FRONT: Front ultrasonic sensor, RoverSensors::ROVER_REAR: Rear ultrasonic sensor.
143 * @return sensor_val in centimeters
144 */
145 int readHCSR04UltrasonicSensor (int sensor_id);
146
147 /**
148 * @brief Sets up the groove ultrasonic sensor
149 * @return void
150 */
151 void setupGrooveUltrasonicSensor (void);
152
153 /**
154 * @brief Reads from groove ultrasonic sensor in centimeters. sensor_id RoverSensors::ROVER_FRONT: Front ultrasonic sensor, RoverSensors::ROVER_REAR: Rear ultrasonic sensor.
155 * @param sensor_id RoverSensors::ROVER_FRONT: Front ultrasonic sensor, RoverSensors::ROVER_REAR: Rear ultrasonic sensor.
156 * @return sensor_val in centimeters
157 */
158 int readGrooveUltrasonicSensor (int sensor_id);
159
160 /**
161 * @brief Sets up the infrared sensors and Analog to digital converter
162 * @return void
163 */
164 void setupInfraredSensors (void);
165
166 /**
167 * @brief Reads from infrared sensor in centimeters (float).
168 * @param infrared_sensor_id Indicates the channel of which on-board sensor is addressed. RoverSensors::ROVER_REAR_RIGHT: Rear-right, RoverSensors::ROVER_REAR_LEFT: Rear-left, RoverSensors::ROVER_FRONT_RIGHT: Front-right, RoverSensors::ROVER_FRONT_LEFT: Front-left.
169 * @return sensor_val in centimeters (float).
170 */
171 float readInfraredSensor (int infrared_sensor_id);
172
173 /**
174 * @brief Sets up the bearing sensor and its I2C interface
175 * @return void
176 */
177 void setupBearingSensor (void);
178
179 /**
180 * @brief Starts calibration for the bearing sensor
181 * @return void
182 */
183 void calibrateBearingSensor (void);
184
185 /**
186 * @brief Reads the bearing value from Bearing sensor (float).
187 * @return bearing_val in degrees (float).
188 */
189 float readBearing (void);
190
191 /**
192 * @brief Reads the temperature value in Celcius degrees from DHT22 temperature and humidity sensor (float).
193 * @return temperature_val in Celcius degrees (float).
194 */
195 float readTemperature (void);
196
197 /**
198 * @brief Reads the humidity value in percentage from DHT22 temperature and humidity sensor (float).
199 * @return humidity_val in percentage (float).
200 */
201 float readHumidity (void);
202 };
203}
204
205
206
207#endif /* API_ROVER_SENSORS_HPP_ */