with the tof code

Dependencies:   mbed Servo ros_lib_kinetic

Committer:
Stumi
Date:
Tue Nov 12 10:36:59 2019 +0000
Revision:
5:bc5081f0c063
Parent:
4:36a04230554d
Child:
6:2cc2aac35868
Code added to control the RGB LED

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Stumi 0:6021ec1b1449 1 /*--------------------------------------------------------------------------------
Stumi 0:6021ec1b1449 2 Filename: main.cpp
Stumi 0:6021ec1b1449 3 Description: Main program loop
Stumi 0:6021ec1b1449 4 --------------------------------------------------------------------------------*/
Stumi 0:6021ec1b1449 5 #include "mbed.h"
Stumi 0:6021ec1b1449 6 #include "TOF.h"
Stumi 4:36a04230554d 7 #include "Motor.h"
Stumi 4:36a04230554d 8 #include "power.h"
Stumi 5:bc5081f0c063 9 #include "LED.h"
Stumi 0:6021ec1b1449 10
Stumi 0:6021ec1b1449 11 Serial pc(SERIAL_TX, SERIAL_RX, 9600); // set-up serial to pc
Stumi 1:9bc7f95c3c7d 12
Stumi 1:9bc7f95c3c7d 13 //TOF chip shutdown signals
Stumi 4:36a04230554d 14 DigitalOut TOF1(PC_8);
Stumi 4:36a04230554d 15 DigitalOut TOF4(PC_11);
Stumi 4:36a04230554d 16 DigitalOut TOF6(PC_12);
Stumi 4:36a04230554d 17 DigitalOut TOF7(PD_2);
Stumi 0:6021ec1b1449 18
Stumi 4:36a04230554d 19 //Class define
Stumi 4:36a04230554d 20 cAdafruit_VL6180X VL6180X(TOF1,TOF4,TOF6,TOF7); //Define TOF sensor class and initialise devices
Stumi 4:36a04230554d 21 cPower cPower(VBATT, V5, V3);
Stumi 5:bc5081f0c063 22 cRBG_LED cRBG_LED(DIAG_RED, DIAG_BLU, DIAG_GRN);
Stumi 0:6021ec1b1449 23
Stumi 0:6021ec1b1449 24 int main()
Stumi 0:6021ec1b1449 25 {
Stumi 4:36a04230554d 26 uint8_t TOFRange[4]; //Array to store TOF measurements 0-sensor1, 1-sensor4, 2-sensor6, 3-sensor7
Stumi 4:36a04230554d 27 float power_levels[3]; //Array to voltage levels
Stumi 0:6021ec1b1449 28
Stumi 5:bc5081f0c063 29 while(1){
Stumi 0:6021ec1b1449 30
Stumi 1:9bc7f95c3c7d 31 //Perform TOF measurements
Stumi 4:36a04230554d 32 TOFRange[0] = serviceTOF(VL6180X, ADDR1);
Stumi 4:36a04230554d 33 TOFRange[1] = serviceTOF(VL6180X, ADDR4);
Stumi 4:36a04230554d 34 TOFRange[2] = serviceTOF(VL6180X, ADDR6);
Stumi 4:36a04230554d 35 TOFRange[3] = serviceTOF(VL6180X, ADDR7);
Stumi 4:36a04230554d 36
Stumi 4:36a04230554d 37 Check_for_obstacles(TOFRange);
Stumi 4:36a04230554d 38
Stumi 1:9bc7f95c3c7d 39 //Send range to pc by serial
Stumi 4:36a04230554d 40 //pc.printf("TOF1:%d TOF3: %d TOF5: %d TOF7: %d\r\n", TOFRange[0], TOFRange[1], TOFRange[2],TOFRange[3]);
Stumi 0:6021ec1b1449 41
Stumi 4:36a04230554d 42 power_levels[0] = cPower.monitor_battery();
Stumi 4:36a04230554d 43 power_levels[1] = cPower.monitor_5v_line();
Stumi 4:36a04230554d 44 power_levels[2] = cPower.monitor_3v3_line();
Stumi 5:bc5081f0c063 45 printf("BATT:%4.2f, 5V:%4.2f, 3v3:%4.2f\n\r", power_levels[0], power_levels[1], power_levels[2]);
Stumi 5:bc5081f0c063 46
Stumi 5:bc5081f0c063 47 cRBG_LED.yellow_led();
Stumi 4:36a04230554d 48
Stumi 0:6021ec1b1449 49 }
Stumi 0:6021ec1b1449 50 }