Psi Swarm robot library version 0.9

Fork of PsiSwarmV9 by Psi Swarm Robot

Committer:
jah128
Date:
Thu Jun 01 21:58:14 2017 +0000
Revision:
15:66be5ec52c3b
Parent:
14:2f1ad77d281e
Child:
16:50686c07ad07
Added colour detection code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jah128 0:d6269d17c8cf 1 /* University of York Robotics Laboratory PsiSwarm Library: Colour Sensors Header File
jah128 13:adbd827234a4 2 *
jah128 14:2f1ad77d281e 3 * Copyright 2017 University of York
jah128 6:b340a527add9 4 *
jah128 13:adbd827234a4 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 13:adbd827234a4 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: colour.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 14:2f1ad77d281e 16 * PsiSwarm Library Version: 0.9
jah128 0:d6269d17c8cf 17 *
jah128 14:2f1ad77d281e 18 * June 2017
jah128 0:d6269d17c8cf 19 *
jah128 0:d6269d17c8cf 20 *
jah128 13:adbd827234a4 21 */
jah128 0:d6269d17c8cf 22
jah128 0:d6269d17c8cf 23
jah128 0:d6269d17c8cf 24 #ifndef COLOUR_H
jah128 0:d6269d17c8cf 25 #define COLOUR_H
jah128 0:d6269d17c8cf 26
jah128 15:66be5ec52c3b 27 #define ENABLE 0x00
jah128 15:66be5ec52c3b 28 #define ATIME 0x01
jah128 15:66be5ec52c3b 29 #define CONTROL 0x0F
jah128 15:66be5ec52c3b 30 #define CDATA 0x14
jah128 15:66be5ec52c3b 31
jah128 13:adbd827234a4 32 /**
jah128 13:adbd827234a4 33 * The Colour class contains the functions for reading the base-mounted and top-mounted I2C colour sensors (optional).
jah128 7:aa5a4a257895 34 */
jah128 13:adbd827234a4 35 class Colour
jah128 13:adbd827234a4 36 {
jah128 13:adbd827234a4 37 public:
jah128 13:adbd827234a4 38 /** Set the gain of the base colour sensor
jah128 13:adbd827234a4 39 *
jah128 13:adbd827234a4 40 * @param gain The gain value for the sensor
jah128 13:adbd827234a4 41 */
jah128 13:adbd827234a4 42 void set_base_colour_sensor_gain(char gain);
jah128 7:aa5a4a257895 43
jah128 13:adbd827234a4 44 /** Set the integration time constant for the base colour sensor
jah128 13:adbd827234a4 45 *
jah128 13:adbd827234a4 46 * @param gain The gain value for the sensor
jah128 13:adbd827234a4 47 */
jah128 13:adbd827234a4 48 void set_base_colour_sensor_integration_time(char int_time);
jah128 13:adbd827234a4 49
jah128 13:adbd827234a4 50 /** Enable the base colour sensor
jah128 13:adbd827234a4 51 */
jah128 13:adbd827234a4 52 void enable_base_colour_sensor(void);
jah128 0:d6269d17c8cf 53
jah128 15:66be5ec52c3b 54 /** Disable (power-down) the base colour sensor
jah128 15:66be5ec52c3b 55 */
jah128 15:66be5ec52c3b 56 void disable_base_colour_sensor(void);
jah128 15:66be5ec52c3b 57
jah128 13:adbd827234a4 58 /** Read the values from the base colour sensor
jah128 13:adbd827234a4 59 *
jah128 13:adbd827234a4 60 * @param Pointer to 3 x int array for r-g-b values
jah128 13:adbd827234a4 61 */
jah128 13:adbd827234a4 62 void read_base_colour_sensor_values(int * store_array);
jah128 15:66be5ec52c3b 63
jah128 15:66be5ec52c3b 64 /** Function enables colour sensor, takes a reading, returns a single int (range -1 to 8)
jah128 15:66be5ec52c3b 65 *
jah128 15:66be5ec52c3b 66 * @return Output of identify_colour_from_calibrated_colour_scores - int range -1 to 8
jah128 15:66be5ec52c3b 67 */
jah128 15:66be5ec52c3b 68 int detect_colour_once();
jah128 15:66be5ec52c3b 69
jah128 15:66be5ec52c3b 70 /** Returns the most recent identified colour from detect_colour_once or detect_colour_ticker (range -1 to 8)
jah128 15:66be5ec52c3b 71 *
jah128 15:66be5ec52c3b 72 * @return Output of identify_colour_from_calibrated_colour_scores - int range -1 to 8
jah128 15:66be5ec52c3b 73 */
jah128 15:66be5ec52c3b 74 int get_detected_colour();
jah128 15:66be5ec52c3b 75
jah128 15:66be5ec52c3b 76 /** Attempts to identify a colour from a given array of calibrated colour values
jah128 15:66be5ec52c3b 77 *
jah128 15:66be5ec52c3b 78 * @param calibrate_colour_array_in : Pointer to the calibrate colour array [output of get_calibrated_colour]
jah128 15:66be5ec52c3b 79 * @return int defining detected colour: 0=RED 1=YELLOW 2=GREEN 3=CYAN 4=BLUE 5=MAGENTA 6=WHITE 7=BLACK 8=UNSURE
jah128 15:66be5ec52c3b 80 */
jah128 15:66be5ec52c3b 81 int identify_colour_from_calibrated_colour_scores(float * calibrate_colour_array_in);
jah128 15:66be5ec52c3b 82
jah128 15:66be5ec52c3b 83 /** Translate an input array of raw CT,R,G,B values into calibrated, normalised values
jah128 15:66be5ec52c3b 84 *
jah128 15:66be5ec52c3b 85 * @param colour_array_in : 4-element int input array [output of read_base_colour_sensor_values()]
jah128 15:66be5ec52c3b 86 * @param colour_array_out : Target 4-element float array of normalised values [0=CT, range 0-1 1=R 2=G 3=B, Sum R+G+B=3.0]
jah128 15:66be5ec52c3b 87 */
jah128 15:66be5ec52c3b 88 void get_calibrated_colour(int * colour_array_in, float * colour_array_out);
jah128 15:66be5ec52c3b 89
jah128 15:66be5ec52c3b 90 /** Returns a string form of the output of identify_colour_from_calibrated_colour_scores()
jah128 15:66be5ec52c3b 91 *
jah128 15:66be5ec52c3b 92 * @param colour_index : Output of identify_colour_from_calibrated_colour_scores()
jah128 15:66be5ec52c3b 93 * @return 7-character String (eg 0="RED ")
jah128 15:66be5ec52c3b 94 */
jah128 15:66be5ec52c3b 95 const char * get_colour_string(int colour_index);
jah128 15:66be5ec52c3b 96
jah128 15:66be5ec52c3b 97 /** Starts a polling ticker that cyclically checks to see if a colour can be detected
jah128 15:66be5ec52c3b 98 *
jah128 15:66be5ec52c3b 99 * @param period_ms : The approximate cycle period in milliseconds
jah128 15:66be5ec52c3b 100 */
jah128 15:66be5ec52c3b 101 void start_colour_ticker(int period_ms);
jah128 15:66be5ec52c3b 102
jah128 15:66be5ec52c3b 103
jah128 15:66be5ec52c3b 104
jah128 15:66be5ec52c3b 105 void IF_colour_ticker_start();
jah128 15:66be5ec52c3b 106 void IF_colour_ticker_main();
jah128 13:adbd827234a4 107 char IF_check_base_colour_sensor(void);
jah128 15:66be5ec52c3b 108 int IF_writeSingleRegister( char address, char data );
jah128 15:66be5ec52c3b 109 int IF_writeMultipleRegisters( char address, char* data, int quantity );
jah128 15:66be5ec52c3b 110 char IF_readSingleRegister( char address );
jah128 15:66be5ec52c3b 111 int IF_readMultipleRegisters( char address, char* output, int quantity );
jah128 15:66be5ec52c3b 112 float IF_roundTowardsZero( const float value );
jah128 13:adbd827234a4 113 };
jah128 0:d6269d17c8cf 114 #endif