Robot team project

Dependencies:   QEI Motordriver ros_lib_melodic

Committer:
florine_van
Date:
Tue Oct 22 15:06:44 2019 +0000
Revision:
5:8ef79eebbc97
Parent:
4:cb50c6fa340b
Implementation of motor class; Link to sensors in main method

Who changed what in which revision?

UserRevisionLine numberNew contents of line
florine_van 0:57855aafa907 1 #ifndef _Sensor_h
florine_van 0:57855aafa907 2 #define _Sensor_h
florine_van 0:57855aafa907 3
florine_van 0:57855aafa907 4 #include "mbed.h"
florine_van 0:57855aafa907 5
florine_van 2:c537f1ebad7b 6 #define DEFAULT_DEVICE_ADDRESS 0x29
florine_van 0:57855aafa907 7
florine_van 0:57855aafa907 8 #define FAILURE_RESET -1
florine_van 0:57855aafa907 9
florine_van 0:57855aafa907 10 #define IDENTIFICATION_MODEL_ID 0x0000
florine_van 0:57855aafa907 11 #define IDENTIFICATION_MODEL_REV_MAJOR 0x0001
florine_van 0:57855aafa907 12 #define IDENTIFICATION_MODEL_REV_MINOR 0x0002
florine_van 0:57855aafa907 13 #define IDENTIFICATION_MODULE_REV_MAJOR 0x0003
florine_van 0:57855aafa907 14 #define IDENTIFICATION_MODULE_REV_MINOR 0x0004
florine_van 0:57855aafa907 15 #define IDENTIFICATION_DATE 0x0006 //16bit value
florine_van 0:57855aafa907 16 #define IDENTIFICATION_TIME 0x0008 //16bit value
florine_van 0:57855aafa907 17
florine_van 0:57855aafa907 18 #define SYSTEM_MODE_GPIO0 0x0010
florine_van 0:57855aafa907 19 #define SYSTEM_MODE_GPIO1 0x0011
florine_van 0:57855aafa907 20 #define SYSTEM_HISTORY_CTRL 0x0012
florine_van 0:57855aafa907 21 #define SYSTEM_INTERRUPT_CONFIG_GPIO 0x0014
florine_van 0:57855aafa907 22 #define SYSTEM_INTERRUPT_CLEAR 0x0015
florine_van 0:57855aafa907 23 #define SYSTEM_FRESH_OUT_OF_RESET 0x0016
florine_van 0:57855aafa907 24 #define SYSTEM_GROUPED_PARAMETER_HOLD 0x0017
florine_van 0:57855aafa907 25
florine_van 0:57855aafa907 26 #define SYSRANGE_START 0x0018
florine_van 0:57855aafa907 27 #define SYSRANGE_THRESH_HIGH 0x0019
florine_van 0:57855aafa907 28 #define SYSRANGE_THRESH_LOW 0x001A
florine_van 0:57855aafa907 29 #define SYSRANGE_INTERMEASUREMENT_PERIOD 0x001B
florine_van 0:57855aafa907 30 #define SYSRANGE_MAX_CONVERGENCE_TIME 0x001C
florine_van 0:57855aafa907 31 #define SYSRANGE_CROSSTALK_COMPENSATION_RATE 0x001E
florine_van 0:57855aafa907 32 #define SYSRANGE_CROSSTALK_VALID_HEIGHT 0x0021
florine_van 0:57855aafa907 33 #define SYSRANGE_EARLY_CONVERGENCE_ESTIMATE 0x0022
florine_van 0:57855aafa907 34 #define SYSRANGE_PART_TO_PART_RANGE_OFFSET 0x0024
florine_van 0:57855aafa907 35 #define SYSRANGE_RANGE_IGNORE_VALID_HEIGHT 0x0025
florine_van 0:57855aafa907 36 #define SYSRANGE_RANGE_IGNORE_THRESHOLD 0x0026
florine_van 0:57855aafa907 37 #define SYSRANGE_MAX_AMBIENT_LEVEL_MULT 0x002C
florine_van 0:57855aafa907 38 #define SYSRANGE_RANGE_CHECK_ENABLES 0x002D
florine_van 0:57855aafa907 39 #define SYSRANGE_VHV_RECALIBRATE 0x002E
florine_van 0:57855aafa907 40 #define SYSRANGE_VHV_REPEAT_RATE 0x0031
florine_van 0:57855aafa907 41
florine_van 0:57855aafa907 42 #define SYSALS_START 0x0038
florine_van 0:57855aafa907 43 #define SYSALS_THRESH_HIGH 0x003A
florine_van 0:57855aafa907 44 #define SYSALS_THRESH_LOW 0x003C
florine_van 0:57855aafa907 45 #define SYSALS_INTERMEASUREMENT_PERIOD 0x003E
florine_van 0:57855aafa907 46 #define SYSALS_ANALOGUE_GAIN 0x003F
florine_van 0:57855aafa907 47 #define SYSALS_INTEGRATION_PERIOD 0x0040
florine_van 0:57855aafa907 48
florine_van 0:57855aafa907 49 #define RESULT_RANGE_STATUS 0x004D
florine_van 0:57855aafa907 50 #define RESULT_ALS_STATUS 0x004E
florine_van 0:57855aafa907 51 #define RESULT_INTERRUPT_STATUS_GPIO 0x004F
florine_van 0:57855aafa907 52 #define RESULT_ALS_VAL 0x0050
florine_van 0:57855aafa907 53 #define RESULT_HISTORY_BUFFER 0x0052
florine_van 0:57855aafa907 54 #define RESULT_RANGE_VAL 0x0062
florine_van 0:57855aafa907 55 #define RESULT_RANGE_RAW 0x0064
florine_van 0:57855aafa907 56 #define RESULT_RANGE_RETURN_RATE 0x0066
florine_van 0:57855aafa907 57 #define RESULT_RANGE_REFERENCE_RATE 0x0068
florine_van 0:57855aafa907 58 #define RESULT_RANGE_RETURN_SIGNAL_COUNT 0x006C
florine_van 0:57855aafa907 59 #define RESULT_RANGE_REFERENCE_SIGNAL_COUNT 0x0070
florine_van 0:57855aafa907 60 #define RESULT_RANGE_RETURN_AMB_COUNT 0x0074
florine_van 0:57855aafa907 61 #define RESULT_RANGE_REFERENCE_AMB_COUNT 0x0078
florine_van 0:57855aafa907 62 #define RESULT_RANGE_RETURN_CONV_TIME 0x007C
florine_van 0:57855aafa907 63 #define RESULT_RANGE_REFERENCE_CONV_TIME 0x0080
florine_van 0:57855aafa907 64
florine_van 0:57855aafa907 65 #define READOUT_AVERAGING_SAMPLE_PERIOD 0x010A
florine_van 0:57855aafa907 66 #define FIRMWARE_BOOTUP 0x0119
florine_van 0:57855aafa907 67 #define FIRMWARE_RESULT_SCALER 0x0120
florine_van 0:57855aafa907 68 #define I2C_SLAVE_DEVICE_ADDRESS 0x0212
florine_van 0:57855aafa907 69 #define INTERLEAVED_MODE_ENABLE 0x02A3
florine_van 0:57855aafa907 70
florine_van 0:57855aafa907 71 class Sensor{
florine_van 0:57855aafa907 72
florine_van 0:57855aafa907 73 public:
florine_van 5:8ef79eebbc97 74 /** Constructor
florine_van 5:8ef79eebbc97 75 * Create a VL6180 object at I2C specified address (7 bit).
florine_van 0:57855aafa907 76 *
florine_van 0:57855aafa907 77 * @param sda I2C sda pin number
florine_van 0:57855aafa907 78 * @param scl I2C scl pin number
florine_van 0:57855aafa907 79 * @param shdn I2C shdn pin number
florine_van 0:57855aafa907 80 */
florine_van 1:d5adc483bce0 81 Sensor(PinName sda, PinName scl, PinName shdn);
florine_van 0:57855aafa907 82
florine_van 5:8ef79eebbc97 83 /** Init the sensor, load settings and change I2C address
florine_van 0:57855aafa907 84 *
florine_van 5:8ef79eebbc97 85 * @param address I2C new address
florine_van 0:57855aafa907 86 */
florine_van 0:57855aafa907 87 int init();
florine_van 0:57855aafa907 88
florine_van 5:8ef79eebbc97 89 /** Change I2C address
florine_van 5:8ef79eebbc97 90 *
florine_van 5:8ef79eebbc97 91 */
florine_van 5:8ef79eebbc97 92 void changeAddress(char address);
florine_van 5:8ef79eebbc97 93
florine_van 0:57855aafa907 94 /** Make a range reading
florine_van 0:57855aafa907 95 *
florine_van 0:57855aafa907 96 */
florine_van 4:cb50c6fa340b 97 float read();
florine_van 1:d5adc483bce0 98
florine_van 4:cb50c6fa340b 99 /** Turn off the device
florine_van 2:c537f1ebad7b 100 *
florine_van 2:c537f1ebad7b 101 */
florine_van 1:d5adc483bce0 102 void turnOff();
florine_van 2:c537f1ebad7b 103
florine_van 4:cb50c6fa340b 104 /** Turn on the device
florine_van 2:c537f1ebad7b 105 *
florine_van 2:c537f1ebad7b 106 */
florine_van 1:d5adc483bce0 107 void turnOn();
florine_van 5:8ef79eebbc97 108
florine_van 5:8ef79eebbc97 109 /** Indicate if the device detects an obstacle
florine_van 5:8ef79eebbc97 110 *
florine_van 5:8ef79eebbc97 111 * @return true if osbtacle otherwise false
florine_van 5:8ef79eebbc97 112 */
florine_van 5:8ef79eebbc97 113 bool getIsObstacle();
florine_van 0:57855aafa907 114
florine_van 0:57855aafa907 115 private:
florine_van 0:57855aafa907 116 char addr;
florine_van 0:57855aafa907 117 I2C i2c;
florine_van 0:57855aafa907 118 DigitalOut SHDN;
florine_van 5:8ef79eebbc97 119 bool isObstacle;
florine_van 0:57855aafa907 120 void startRange();
florine_van 0:57855aafa907 121 void pollRange();
florine_van 4:cb50c6fa340b 122 float readRange();
florine_van 0:57855aafa907 123 void clearInterrupts();
florine_van 0:57855aafa907 124 void setRegister(wchar_t reg, char data);
florine_van 0:57855aafa907 125 void writeByte(wchar_t reg,char data);
florine_van 0:57855aafa907 126 char readByte(wchar_t reg);
florine_van 0:57855aafa907 127
florine_van 0:57855aafa907 128 };
florine_van 0:57855aafa907 129 #endif