first edition of the code for a wall-following robot

Dependencies:   motorController HC-SR04 UoY-serial

Files at this revision

API Documentation at this revision

Comitter:
snapo
Date:
Wed Nov 03 09:52:25 2021 +0000
Commit message:
first edition of the robot code for the micromouse project

Changed in this revision

HC-SR04.lib Show annotated file Show diff for this revision Revisions of this file
UoY-serial.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
motorController.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HC-SR04.lib	Wed Nov 03 09:52:25 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/snapo/code/HC-SR04/#b4a6f6bcab30
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UoY-serial.lib	Wed Nov 03 09:52:25 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/ajp109/code/UoY-serial/#a86a8c72aca6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 03 09:52:25 2021 +0000
@@ -0,0 +1,59 @@
+#include "mbed.h"
+#include "HC-SR04.h"
+#include "motor.h"
+
+#define uint unsigned int
+
+motor motor1 (D1, D2, D3);
+motor motor2 (D8, D9, D10);
+
+HCSR04 ultraSoundF ( D5 , D6);
+HCSR04 ultraSoundL ( D12 , D13);
+HCSR04 ultraSoundR ( D14 , D15);
+
+int main(){
+    
+    uint uSReadingF = 0;
+    uint uSReadingL = 0;
+    uint uSReadingR = 0;
+    
+    while(true){
+        
+        ultraSoundF.fastTimeReading();
+        uSReadingF = ultraSoundF.getTime();
+        ultraSoundL.fastTimeReading();
+        uSReadingL = ultraSoundL.getTime();
+        ultraSoundR.fastTimeReading();
+        
+       
+        if (uSReadingF > 450){
+            motor1 = 0.5;
+            motor2 = 0.5;
+            } else if (uSReadingF > 300) {
+                motor1 = 0.2;
+                } else {
+                    motor1 = 0;
+                    }
+        
+        
+        if (uSReadingL > 300){
+            motor1 = -0.5;
+            motor2 = 0.5;
+            thread_sleep_for(500);
+            motor1 = 0;
+            motor2 = 0;
+            ultraSoundF.fastTimeReading();
+            if (ultraSoundF.getTime() > 450){
+                motor1 = 0.5;
+                motor2 = 0.5;
+                }
+            }
+        
+    
+        thread_sleep_for(500);
+        motor1 = 0;
+        motor2 = 0;
+        thread_sleep_for(3000);
+        
+        }           
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Wed Nov 03 09:52:25 2021 +0000
@@ -0,0 +1,1 @@
+https://github.com/armmbed/mbed-os/#c6d65fe5082aeef6bf0d7043b4cbf0a9cc9a9d5e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motorController.lib	Wed Nov 03 09:52:25 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/snapo/code/motorController/#322cf8e3ef05