ok

Dependencies:   TB6612 VL53L0X

Files at this revision

API Documentation at this revision

Comitter:
sas638
Date:
Sun May 08 20:14:38 2022 +0000
Commit message:
ok;

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
TB6612.lib Show annotated file Show diff for this revision Revisions of this file
VL53L0X.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
resources/official_armmbed_example_badge.png Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r e26f2e97182d .gitignore
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Sun May 08 20:14:38 2022 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
diff -r 000000000000 -r e26f2e97182d TB6612.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TB6612.lib	Sun May 08 20:14:38 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/sas638/code/TB6612/#f51c00c6d476
diff -r 000000000000 -r e26f2e97182d VL53L0X.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VL53L0X.lib	Sun May 08 20:14:38 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/joelvonrotz/code/VL53L0X/#ccc67c76fecb
diff -r 000000000000 -r e26f2e97182d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun May 08 20:14:38 2022 +0000
@@ -0,0 +1,72 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2019 ARM Limited
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include "mbed.h"
+#include "platform/mbed_thread.h"
+#include "tb6612.h"
+#include "VL53L0X.h"
+
+I2C         i2c(D14,D15);
+VL53L0X     vl_sensors[3] = {(&i2c),(&i2c),(&i2c)}
+BusOut      vl_shutdown(D0,D1,D3);
+Serial      usb(USBTX. USBRX, 115200);
+TB6612      motorL(D2,D4,D5);
+TB6612      motorR(D9,D10,D11);
+
+float DR; //distance measured if need to turn 45º right - manual measured value
+float DL; //distance measured if need to turn 45º left - manual measured value 
+float D; // distance measured to go straight - given value
+float TM; //Time needed to turn 45º in either direction
+float DI; // distance measured
+float R; //Ratio between D1 and D
+float T; //Calculated turn time for current offset
+float Dlefts; //left sensor reading
+float Drights; //right sensor reading
+float Dfronts; // front sensor reading
+
+int main()
+{
+    usb.printf("Multiple VL53L0X\n\r");
+
+    uint8_t expander_shutdown_mask = 1;
+    for(uint8_t i = 0; i < 3; i++) {
+        vl_shutdown = expander_shutdown_mask;
+        expander_shutdown_mask = (expander_shutdown_mask << 1) + 1;
+        vl_sensors[i].init();
+        vl_sensors[i].setDeviceAddress(0x40 + i);
+        vl_sensors[i].setModeContinuous();
+        vl_sensors[i].startContinuous();
+    }
+    uint16_t results[3];
+
+    while(1) {
+        for(uint8_t i = 0; i < 3; i++) {
+            results[i] = vl_sensors[i].getRangeMillimeters();
+        }
+        Dfronts = results[0];
+        Dlefts = results[1];
+        Drigts = results [2];
+        
+        DI = Dfronts;
+        
+        if(DI>D) {
+            R = DR/DI;
+            T = TM/R;
+            motorR.setSpeed(-1);
+            motorL.setSpeed(1);
+            usb.printf("right turn\n\r");
+            wait(T);
+        }
+        if (DI<D) {
+            R = DL/DI;
+            T = TM/R;
+            motorR.setSpeed(1);
+            motorL.setSpeed(-1);
+            usb.printf("left turn\n\r");
+            wait(T);
+        }
+    }
+
+}
diff -r 000000000000 -r e26f2e97182d mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Sun May 08 20:14:38 2022 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9
diff -r 000000000000 -r e26f2e97182d resources/official_armmbed_example_badge.png
Binary file resources/official_armmbed_example_badge.png has changed