Psi Swarm robot library version 0.9

Dependents:   PsiSwarm_V9_Blank

Fork of PsiSwarmV9 by James Hilder

Committer:
jah128
Date:
Sun Oct 16 16:00:20 2016 +0000
Revision:
10:e58323951c08
Parent:
6:b340a527add9
Child:
16:50686c07ad07
Added Sensors class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jah128 0:d6269d17c8cf 1 /* University of York Robotics Laboratory PsiSwarm Library: Sensor Functions Header File
jah128 10:e58323951c08 2 *
jah128 6:b340a527add9 3 * Copyright 2016 University of York
jah128 6:b340a527add9 4 *
jah128 10:e58323951c08 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
jah128 6:b340a527add9 6 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
jah128 6:b340a527add9 7 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS
jah128 10:e58323951c08 8 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
jah128 6:b340a527add9 9 * See the License for the specific language governing permissions and limitations under the License.
jah128 6:b340a527add9 10 *
jah128 0:d6269d17c8cf 11 * File: sensors.h
jah128 0:d6269d17c8cf 12 *
jah128 0:d6269d17c8cf 13 * (C) Dept. Electronics & Computer Science, University of York
jah128 0:d6269d17c8cf 14 * James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis
jah128 0:d6269d17c8cf 15 *
jah128 10:e58323951c08 16 * PsiSwarm Library Version: 0.8
jah128 0:d6269d17c8cf 17 *
jah128 5:3cdd1a37cdd7 18 * October 2016
jah128 0:d6269d17c8cf 19 *
jah128 0:d6269d17c8cf 20 */
jah128 10:e58323951c08 21
jah128 0:d6269d17c8cf 22 #ifndef SENSORS_H
jah128 0:d6269d17c8cf 23 #define SENSORS_H
jah128 0:d6269d17c8cf 24
jah128 10:e58323951c08 25 /**
jah128 10:e58323951c08 26 * Sensors class
jah128 10:e58323951c08 27 * Functions to read values from the Psi Swarm infrared, ultrasonic, temperature and power sensors
jah128 10:e58323951c08 28 *
jah128 10:e58323951c08 29 * Example:
jah128 10:e58323951c08 30 * @code
jah128 10:e58323951c08 31 * #include "psiswarm.h"
jah128 10:e58323951c08 32 *
jah128 10:e58323951c08 33 * int main() {
jah128 10:e58323951c08 34 * init();
jah128 10:e58323951c08 35 *
jah128 10:e58323951c08 36 * }
jah128 10:e58323951c08 37 * @endcode
jah128 10:e58323951c08 38 */
jah128 10:e58323951c08 39 class Sensors
jah128 10:e58323951c08 40 {
jah128 10:e58323951c08 41 public:
jah128 10:e58323951c08 42
jah128 10:e58323951c08 43 /** Returns the current battery voltage for the robot
jah128 10:e58323951c08 44 * @return The voltage (in V); this should range between 3.5V for a discharged battery and 4.2V for a fully charged battery
jah128 10:e58323951c08 45 */
jah128 10:e58323951c08 46 float get_battery_voltage ( void );
jah128 10:e58323951c08 47
jah128 10:e58323951c08 48 /** Returns the current being used by the robot
jah128 10:e58323951c08 49 * @return The current (in A)
jah128 10:e58323951c08 50 */
jah128 10:e58323951c08 51 float get_current ( void );
jah128 10:e58323951c08 52
jah128 10:e58323951c08 53 /** Returns the voltage sensed from the DC input (post rectification)
jah128 10:e58323951c08 54 * @return The voltage (in V); note some back-voltage from the battery is expected even when no DC input is detected
jah128 10:e58323951c08 55 */
jah128 10:e58323951c08 56 float get_dc_voltage ( void );
jah128 10:e58323951c08 57
jah128 10:e58323951c08 58 /** Returns the temperature sensed by the digital thermometer placed near the front of the MBED socket
jah128 10:e58323951c08 59 * @return The temperature (in degrees C)
jah128 10:e58323951c08 60 */
jah128 10:e58323951c08 61 float get_temperature ( void );
jah128 10:e58323951c08 62
jah128 10:e58323951c08 63 /** Enables a 10Hz ticker that automatically takes readings from the SRF-02 ultrasonic sensor (if fitted)
jah128 10:e58323951c08 64 */
jah128 10:e58323951c08 65 void enable_ultrasonic_ticker( void );
jah128 10:e58323951c08 66
jah128 10:e58323951c08 67 /** Disables the ultrasonic ticker
jah128 10:e58323951c08 68 */
jah128 10:e58323951c08 69 void disable_ultrasonic_ticker( void );
jah128 0:d6269d17c8cf 70
jah128 10:e58323951c08 71 /** Sends a message to SRF-02 ultrasonic sensor (if fitted) to instruct it to take a new reading. The result is available approx 70ms later
jah128 10:e58323951c08 72 */
jah128 10:e58323951c08 73 void update_ultrasonic_measure ( void );
jah128 10:e58323951c08 74 void IF_read_ultrasonic_measure ( void );
jah128 10:e58323951c08 75
jah128 10:e58323951c08 76 /** Stores the raw ADC values for all 8 IR side-facing sensors without enabling IR emitters
jah128 10:e58323951c08 77 */
jah128 10:e58323951c08 78 void store_background_raw_ir_values ( void );
jah128 10:e58323951c08 79
jah128 10:e58323951c08 80 /** Stores the raw ADC values for all 8 IR side-facing sensors after enabling IR emitters
jah128 10:e58323951c08 81 */
jah128 10:e58323951c08 82 void store_illuminated_raw_ir_values ( void );
jah128 10:e58323951c08 83
jah128 10:e58323951c08 84 /** Stores the raw ADC values for all 8 IR side-facing sensors both before and after enabling IR emitters
jah128 10:e58323951c08 85 * Calls store_background_raw_ir_values() then store_illuminated_raw_ir_values()
jah128 10:e58323951c08 86 */
jah128 10:e58323951c08 87 void store_ir_values ( void );
jah128 10:e58323951c08 88
jah128 10:e58323951c08 89 /** Returns the stored value of the non-illuminated side-facing IR sensor value based on last call of store_background_raw_ir_values
jah128 10:e58323951c08 90 * Call either store_ir_values() or store_background_raw_ir_values() before using this function to update reading
jah128 10:e58323951c08 91 * @param index - The index of the sensor to read (range 0 to 7, clockwise around robot from front-right)
jah128 10:e58323951c08 92 * @return Unsigned short of background IR reading (range 0 to 4095)
jah128 10:e58323951c08 93 */
jah128 10:e58323951c08 94 unsigned short get_background_raw_ir_value ( char index );
jah128 10:e58323951c08 95
jah128 10:e58323951c08 96 /** Returns the stored value of the illuminated side-facing IR sensor value based on last call of store_illuminated_raw_ir_values
jah128 10:e58323951c08 97 * Call either store_ir_values() or store_illuminated_raw_ir_values() before using this function to update reading
jah128 10:e58323951c08 98 * @param index - The index of the sensor to read (range 0 to 7, clockwise around robot from front-right)
jah128 10:e58323951c08 99 * @return Unsigned short of illuminated IR reading (range 0 to 4095)
jah128 10:e58323951c08 100 */
jah128 10:e58323951c08 101 unsigned short get_illuminated_raw_ir_value ( char index );
jah128 10:e58323951c08 102
jah128 10:e58323951c08 103 /** Returns the subtraction of the background side IR value from the reflection based on last call of store_ir_values()
jah128 10:e58323951c08 104 * For most purposes this is the best method of detected obstacles etc as it mitigates for varying background levels of IR
jah128 10:e58323951c08 105 * @param index - The index of the sensor to read (range 0 to 7, clockwise around robot from front-right)
jah128 10:e58323951c08 106 * @return Unsigned short of compensated ir value (illuminated value - background value) (range 0 to 4095)
jah128 10:e58323951c08 107 */
jah128 10:e58323951c08 108 unsigned short calculate_side_ir_value ( char index );
jah128 10:e58323951c08 109
jah128 10:e58323951c08 110 /** Enables the IR emitter then returns the value of the given side-facing IR sensor
jah128 10:e58323951c08 111 * This function is used when just one sensor is needed to be read; in general using store_ir_values() and get_illuminated_raw_ir_value(index) is preferable
jah128 10:e58323951c08 112 * @param index - The index of the sensor to read (range 0 to 7, clockwise around robot from front-right)
jah128 10:e58323951c08 113 * @return Unsigned short of illuminated IR reading (range 0 to 4095)
jah128 10:e58323951c08 114 */
jah128 10:e58323951c08 115 unsigned short read_illuminated_raw_ir_value ( char index ) ;
jah128 0:d6269d17c8cf 116
jah128 10:e58323951c08 117 /** Stores the raw ADC values for all 5 base IR sensors without enabling IR emitters
jah128 10:e58323951c08 118 */
jah128 10:e58323951c08 119 void store_background_base_ir_values ( void );
jah128 10:e58323951c08 120
jah128 10:e58323951c08 121 /** Stores the raw ADC values for all 5 base IR sensors after enabling IR emitters
jah128 10:e58323951c08 122 */
jah128 10:e58323951c08 123 void store_illuminated_base_ir_values ( void );
jah128 0:d6269d17c8cf 124
jah128 10:e58323951c08 125 /** Stores the raw ADC values for all 5 base IR sensors both before and after enabling IR emitters
jah128 10:e58323951c08 126 * Calls store_background_base_ir_values() then store_illuminated_base_ir_values()
jah128 10:e58323951c08 127 */
jah128 10:e58323951c08 128 void store_base_ir_values ( void );
jah128 10:e58323951c08 129
jah128 10:e58323951c08 130 /** Returns the stored value of the non-illuminated base IR sensor value based on last call of store_background_base_ir_values
jah128 10:e58323951c08 131 * Call either store_base_ir_values() or store_background_base_ir_values() before using this function to update reading
jah128 10:e58323951c08 132 * @param index - The index of the sensor to read (range 0 to 4, sensor from left to right viewed from above - 2 is in middle of front)
jah128 10:e58323951c08 133 * @return Unsigned short of background IR reading (range 0 to 4095)
jah128 10:e58323951c08 134 */
jah128 10:e58323951c08 135 unsigned short get_background_base_ir_value ( char index );
jah128 10:e58323951c08 136
jah128 10:e58323951c08 137 /** Returns the stored value of the illuminated base IR sensor value based on last call of store_illuminated_base_ir_values
jah128 10:e58323951c08 138 * Call either store_base_ir_values() or store_illuminated_base_ir_values() before using this function to update reading
jah128 10:e58323951c08 139 * @param index - The index of the sensor to read (range 0 to 4, sensor from left to right viewed from above - 2 is in middle of front)
jah128 10:e58323951c08 140 * @return Unsigned short of illuminated IR reading (range 0 to 4095)
jah128 10:e58323951c08 141 */
jah128 10:e58323951c08 142 unsigned short get_illuminated_base_ir_value ( char index );
jah128 10:e58323951c08 143
jah128 10:e58323951c08 144
jah128 10:e58323951c08 145 /** Returns the subtraction of the background base IR value from the reflection based on last call of store_base_ir_values()
jah128 10:e58323951c08 146 * For most purposes this is the best method of getting values from the base IR sensor as it mitigates for background levels of IR
jah128 10:e58323951c08 147 * @param index - The index of the sensor to read (range 0 to 4, sensor from left to right viewed from above - 2 is in middle of front)
jah128 10:e58323951c08 148 * @return Unsigned short of compensated ir value (illuminated value - background value) (range 0 to 4095)
jah128 10:e58323951c08 149 */
jah128 10:e58323951c08 150 unsigned short calculate_base_ir_value ( char index );
jah128 10:e58323951c08 151
jah128 10:e58323951c08 152 // The following functions are used for special programs or to retain backwards compatability but are not documented as part of the API
jah128 10:e58323951c08 153
jah128 10:e58323951c08 154 void store_reflected_ir_distances ( void );
jah128 10:e58323951c08 155 float read_reflected_ir_distance ( char index );
jah128 10:e58323951c08 156 float get_reflected_ir_distance ( char index );
jah128 10:e58323951c08 157 float calculate_reflected_distance ( unsigned short background_value, unsigned short illuminated_value );
jah128 10:e58323951c08 158 int get_bearing_from_ir_array ( unsigned short * ir_sensor_readings);
jah128 10:e58323951c08 159 void store_line_position ( void );
jah128 10:e58323951c08 160 void calibrate_base_ir_sensors ( void );
jah128 0:d6269d17c8cf 161
jah128 10:e58323951c08 162 };
jah128 0:d6269d17c8cf 163 #endif