first edition of the code for a wall-following robot
Dependencies: motorController HC-SR04 UoY-serial
Revision 0:e8a382e50908, committed 2021-11-03
- 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
diff -r 000000000000 -r e8a382e50908 HC-SR04.lib --- /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
diff -r 000000000000 -r e8a382e50908 UoY-serial.lib --- /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
diff -r 000000000000 -r e8a382e50908 main.cpp --- /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
diff -r 000000000000 -r e8a382e50908 mbed-os.lib --- /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
diff -r 000000000000 -r e8a382e50908 motorController.lib --- /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