10a Maze Solver and Debugging

Поделиться
HTML-код
  • Опубликовано: 3 окт 2024

Комментарии • 31

  • @CrazyRobotics
    @CrazyRobotics  11 месяцев назад +2

    For all those who want to try this as it is with the same components, try this code.....
    /*Pin usage with the Motorshield
    ---------------------------------------
    Analog pins: not used at all...
    A0 ... A5 are still available...
    They all can also be used as digital pins.
    Also, I2C (A4 = SDA and A5 = SCL) can be used.
    These pins have a breadboard area on the shield.
    Digital pins: used: 3,4,5,6,7,8,9,10,11,12
    Pin 9 and 10 are only used for the servo motors.
    Already in use: 0 (RX) and 1 (TX).
    Unused: 2,13
    Pin 2 has an soldering hole on the board, easy to connect a wire.
    Pin 13 is also connected to the system led.
    I2C is possible, but SPI is not possible since those pins are used.
    */
    #include
    AF_DCMotor m1(1);
    AF_DCMotor m2(2);
    String path;
    int mode = 0;
    void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
    for (int i = 14; i < 20; i++) {
    pinMode(i, INPUT);
    }
    pinMode(2, INPUT);
    m1.setSpeed(255);
    m2.setSpeed(255);
    }
    void loop() {
    // mode-0 //mode-0 //mode-0 //mode-0 //mode-0 //mode-0 //mode-0 //mode-0 //mode-0 //mode-0 //mode-0 //mode-0
    if(digitalRead(2) == 0)
    {
    for (int i = 14; i < 20; i++) {
    Serial.print("pin");
    Serial.print("i");
    Serial.print(" ** ");
    Serial.println(digitalRead(i));
    }
    // SENSOR POSITION
    // 16
    //14 15 18 19
    // 17
    if (!digitalRead(14) && !digitalRead(15) && digitalRead(16) && digitalRead(17) && !digitalRead(18) && !digitalRead(19)) {
    // Serial.println("move forward ");
    path += 'S';
    front();
    }
    //Reverse condition
    if (!digitalRead(15) && !digitalRead(17) && !digitalRead(18)) {
    m1.run(FORWARD);
    m2.run(FORWARD);
    delay(1000);
    if (digitalRead(15) && !digitalRead(17) && digitalRead(18)) {
    path += 'B';
    back();
    } else {
    m1.run(BACKWARD);
    m2.run(BACKWARD);
    delay(1000);
    }
    }
    // LEFT/LEFT-T CONDITION
    if (digitalRead(14) && digitalRead(15) && digitalRead(16) && digitalRead(17)) {
    if (path[0] == 'R') { right(); }
    if (path[0] == 'L') { left(); }
    if (path[0] == 'S') { front(); }
    Serial.println("Check LEFT I &/ Move LEFT");
    Serial.println("Move LEFT");
    path += 'L';
    left();
    }
    //RIGHT/RIGHT-T
    if (digitalRead(16) && digitalRead(17) && digitalRead(18) && digitalRead(19)) {
    Serial.println("Check RIGHT T &/ Move RIGHT");
    path += 'R';
    right();
    }
    //Cross Condition
    if (digitalRead(14) && digitalRead(15) && digitalRead(16) && digitalRead(17) && digitalRead(18) && digitalRead(19)) {
    Serial.println("");
    left();
    }
    //Move slight left condition
    if (digitalRead(14) || digitalRead(15)) {
    Serial.println("move slight left");
    left();
    }
    //Move slight Right Condition
    if (digitalRead(18) || digitalRead(19)) {
    Serial.println("move slight right");
    right();
    }
    // mode-1 //mode-1 //mode-1 //mode-1 //mode-1 //mode-1 //mode-1 //mode-1 //mode-1 //mode-1 //mode-1 //mode-1 //mode-1
    if(digitalRead(2) == 1)
    {
    ShortPath();
    go();
    }
    }
    }
    String ShortPath() {
    String path = "LBLLLBSBLLBSLL";
    path.replace("LBL", "S");
    path.replace("LBS", "R");
    path.replace("RBL", "B");
    path.replace("SBS", "B");
    path.replace("SBL", "R");
    path.replace("LBR", "B");
    return path;
    }
    void go()
    {
    unsigned int i=0;
    // Follow the outpath
    if (!digitalRead(14) && !digitalRead(15) && digitalRead(16) && digitalRead(17) && !digitalRead(18) && !digitalRead(19)) {
    if (path.charAt(i)== 'L') {
    // Update the PATH only if there is a change
    // take left turn
    left();
    i++;
    }
    if (path.charAt(i)== 'R') {
    // Update the PATH only if there is a change
    // take right turn
    right();
    i++;
    }
    if (path.charAt(i)== 'S') {
    // Update the PATH only if there is a change
    // move straight
    // moveForward();
    front();
    i++;
    }
    }
    if (!digitalRead(14) && !digitalRead(15) && digitalRead(16) && digitalRead(17) && !digitalRead(18) && !digitalRead(19)) {
    // Serial.println("move forward ");
    front();
    }
    if (!digitalRead(14) && !digitalRead(15) && !digitalRead(16) && !digitalRead(17) && !digitalRead(18) && !digitalRead(19)) {
    // Serial.println("move forward ");
    halt();
    }
    }
    void front() {
    m1.run(FORWARD);
    m2.run(FORWARD);
    delay(100);
    m1.run(RELEASE);
    m2.run(RELEASE);
    delay(1);
    }
    void back() {
    m1.run(BACKWARD);
    m2.run(BACKWARD);
    delay(100);
    m1.run(RELEASE);
    m2.run(RELEASE);
    delay(1);
    }
    void right() {
    m1.run(FORWARD);
    m2.run(BACKWARD);
    delay(100);
    m1.run(RELEASE);
    m2.run(RELEASE);
    delay(1);
    }
    void left() {
    m1.run(BACKWARD);
    m2.run(FORWARD);
    delay(100);
    m1.run(RELEASE);
    m2.run(RELEASE);
    delay(1);
    }
    void halt() {
    m1.run(RELEASE);
    m2.run(RELEASE);
    delay(10);
    }

  • @hani9737
    @hani9737 11 дней назад

    Sir how are we defining for unknown no. Of index..?

  • @arihantsurana2319
    @arihantsurana2319 21 день назад

    sir can you please tell what items like motors have you used in this

  • @adityajain7178
    @adityajain7178 6 месяцев назад +1

    sir can you please provide the final code for shortest path maze solver robot for my college techenical fest as i am not able to code it.
    very much neened sir.

    • @CrazyRobotics
      @CrazyRobotics  6 месяцев назад

      The final working code is already pinned under comments. Please use it.

  • @adityajain7178
    @adityajain7178 6 месяцев назад

    sir you have already defined string path but for different maze there will be different string path what should be do at that time ?

    • @CrazyRobotics
      @CrazyRobotics  6 месяцев назад +1

      The program remembers the path, basically it records the path in the first iteration based on the sensor readings. There is a need to tweak sensor placement on the robot for optimum path recording with multiple trial-error experiments to cover all types of moves. The rest of the headache is handled by the code in optimizing the path and reaching the goal in the second iteration.

  • @ahmedesam037
    @ahmedesam037 6 месяцев назад

    i have two dc motor with encoder can i use this code for my robot line follower?

    • @CrazyRobotics
      @CrazyRobotics  6 месяцев назад

      Yes, why not!..... as long as you follow the basics such as Motor speed, sensor placement, motor driver and proper pin mapping in the code.
      All the best.....✨

  • @adityajain7178
    @adityajain7178 6 месяцев назад

    sir I am using motor drive so how can i use adafruit library

    • @CrazyRobotics
      @CrazyRobotics  6 месяцев назад

      You must use the following official library and refer their documentation www.arduino.cc/reference/en/libraries/adafruit-motor-shield-library/.
      Once you install you may then use the default examples provided e.g. MotorTest to modify according to your needs.
      Let me know how you go with this.....

  • @fisherman1963
    @fisherman1963 Год назад

    can we use this bod as line following robot?

  • @adityajain7178
    @adityajain7178 6 месяцев назад

    sir can is use this code for any path

  • @abhishekkumargupta2991
    @abhishekkumargupta2991 Год назад +1

    Sir... Can you share me the code or Please provide me the link of same code... I need it for my college project... I'm waiting for your reply... Thank you sir..!

    • @CrazyRobotics
      @CrazyRobotics  11 месяцев назад

      Please find the code provided above.

  • @adityajain7178
    @adityajain7178 6 месяцев назад

    how to modify your code for unknown code

    • @CrazyRobotics
      @CrazyRobotics  6 месяцев назад

      Depends on what your build and application is. If you prefer using the AFmotor library then use their documentation. On the other hand if you prefer using no library then simply modify( which means write your own I/O operations on digital pins to get the job done) as per your requirements. If you prefer using the same build and components then you may utilize the code pinned under the video.
      Alternatively, you may also write down a pseudocode for your application and later decide which approach fits best for achieving goals.

  • @chinmayil1pat615
    @chinmayil1pat615 9 месяцев назад

    If I need to follow white line what changes has to make in code

    • @CrazyRobotics
      @CrazyRobotics  9 месяцев назад

      Simply you need to invert all conditional values under "if" conditions. e.g. if it was if (a==1), make it if (a==). Additionally, this process is applicable when you are switching from Active-High to Active-Low sensors or vice-versa.

    • @chinmayil1pat615
      @chinmayil1pat615 9 месяцев назад

      can you give the sample code for it
      @@CrazyRobotics

    • @linuxgeek1872
      @linuxgeek1872 9 месяцев назад

      it is already shared under the comments section. Please try it out and keep exploring 🎉

  • @natarajanas8789
    @natarajanas8789 6 месяцев назад

    Sir, This code is not working

    • @CrazyRobotics
      @CrazyRobotics  6 месяцев назад

      Please check, the code is posted and pinned under the comments section.

  • @ayushsrivastava9775
    @ayushsrivastava9775 Год назад +1

    can i get a code

    • @CrazyRobotics
      @CrazyRobotics  11 месяцев назад

      Shared it under comments. Try and let me know.

  • @fisherman1963
    @fisherman1963 Год назад

    can you kindly share the code?