Advertisement
timor2542

Intelligent Rescue Robot Maze Mission Example Code

Sep 17th, 2024
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.70 KB | Science | 0 0
  1. #define SONAR_READ_CM (analog(5) * 100) / 4095
  2. #define SPD 45
  3. #define kpsonar 7
  4. #define kpspin_t 350
  5. #define kpifr 1500
  6. #define kpfreq 500
  7. #define kpstop_t 300
  8. #include <POP32.h>
  9. void fdSONAR(int cm, int freq, int ao_t) {
  10.   fd2(SPD - 2, SPD);
  11.   motor(2, SPD);
  12.   while (SONAR_READ_CM > cm);
  13.   ao();
  14.   sound(freq, ao_t);
  15. }
  16. void slMAZE(int sl_t, int ao_t) {
  17.   sl(SPD);
  18.   delay(sl_t);
  19.   ao();
  20.   delay(ao_t);
  21. }
  22. void srMAZE(int sr_t, int ao_t) {
  23.   sr(SPD);
  24.   delay(sr_t);
  25.   ao();
  26.   delay(ao_t);
  27. }
  28. void bkSW(int freq, int ao_t) {
  29.   while (1) {
  30.     if (!in(22) && !in(23)) {
  31.       bk(SPD);
  32.       sound(freq, ao_t);
  33.       ao();
  34.       delay(ao_t);
  35.       break;
  36.     } else if (in(22) && !in(23)) {
  37.       sl(SPD);
  38.     } else if (!in(22) && in(23)) {
  39.       sr(SPD);
  40.     } else {
  41.       bk(SPD);
  42.     }
  43.   }
  44. }
  45. void stopline(int ifr, int freq, int ao_t) {
  46.   fd2(SPD - 2, SPD);
  47.   while (analog(2) > ifr);
  48.   ao();
  49.   sound(freq, ao_t);
  50. }
  51. void setup() {
  52.   // put your setup code here, to run once:
  53. }
  54. void loop() {
  55.   // put your main code here, to run repeatedly:
  56.   waitSW_OK_bmp();
  57.   fdSONAR(kpsonar, kpfreq, kpstop_t);
  58.   srMAZE(kpspin_t, kpstop_t);
  59.   bkSW(kpfreq, kpstop_t);
  60.   fdSONAR(kpsonar, kpfreq, kpstop_t);
  61.   slMAZE(kpspin_t, kpstop_t);
  62.   bkSW(kpfreq, kpstop_t);
  63.   fdSONAR(kpsonar, kpfreq, kpstop_t);
  64.   slMAZE(kpspin_t, kpstop_t);
  65.   bkSW(kpfreq, kpstop_t);
  66.   fdSONAR(kpsonar, kpfreq, kpstop_t);
  67.   slMAZE(kpspin_t, kpstop_t);
  68.   bkSW(kpfreq, kpstop_t);
  69.   fdSONAR(kpsonar, kpfreq, kpstop_t);
  70.   srMAZE(kpspin_t, kpstop_t);
  71.   bkSW(kpfreq, kpstop_t);
  72.   fdSONAR(kpsonar, kpfreq, kpstop_t);
  73.   srMAZE(kpspin_t, kpstop_t);
  74.   bkSW(kpfreq, kpstop_t);
  75.   stopline(kpifr, kpfreq, kpstop_t);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement