Shop OBEX P1 Docs P2 Docs Learn Events
ActivityBot / Propeller C: Maze Solving Programming Help — Parallax Forums

ActivityBot / Propeller C: Maze Solving Programming Help

Hello everyone! I need some assistance with my robotics code, and would very much appreciate it if anyone could help. I am coding the Activity Bot to solve a wall maze using Propeller C. So far, the robot is equipped with an ultrasound sensor to detect objects in the front and two infrared sensors on the left and right to detect things on either side. So far, the robot can make it all the way through the maze until the very end. As you can see by the code, once the ultrasound sensor detects an object, it stops and checks the infrared sensors on either side to see which way to turn. The problem with the maze, however, is that it does not detect with the infrared sensors while it is still moving, so it cannot turn to the maze exit.

I tried to make the infrared code work while the robot was still moving, but when I did that the robot spun in circles. My idea now is to increase the frequency of the infrared sensors so that it detects things further away and turns if it detects nothing (where the exit is). However, I don't know if this will work. Can anyone please help me go in the right direction?

Thanks!

Code:
#include "simpletools.h"                      // Include simple tools
#include "abdrive.h"
#include "ping.h"

int irLeft, irRight, turn;

int main()                                      // Main function
{
  low(26);                                      // D/A0 & D/A1 to 0 V
  low(27);
  drive_setRampStep(6);                         //+6 ticks per second every 20ms
   
  while(1)
  {
    drive_ramp(64, 64);                         //1 rotation per sec

    while(ping_cm(9) >= 5) pause(5);
    
    drive_ramp(0, 0);

    freqout(11, 1, 20000);                      // Left IR LED light
    irLeft = input(10);                         // Check left IR detector

    freqout(1, 1, 20000);                       // Repeat for right detector
    irRight = input(2);
    
    //IR CODE
    if(irRight == 0 && irLeft == 1)
    {
      pause(200);
      drive_goto(-24,25);
      drive_rampStep(64, 64);
    }          
    else if(irLeft == 0 && irRight == 1)
    {
      pause(200);
      drive_goto(25,-24);
      drive_rampStep(64, 64);
    }     
    else if(irRight == 0 && irLeft == 0)
    {
      turn = rand();
      pause(200);
      if(turn == 1)
      {
        pause(200);
        drive_goto(-50,51);
      }
      else if(turn == 0)
      {
        pause(200);
        drive_goto(25,-24);
      }                      
      drive_rampStep(64,64);
    }
    else if(irRight == 1 && irLeft == 1)
    {
      turn = rand();
      pause(200);
      if(turn == 1)
      {
        pause(200);
        drive_goto(-24,25);
      }
      else if(turn == 0)
      {
        pause(200);
        drive_goto(25,-24);
      }        
      drive_rampStep(64,64);     
    }                
  }
}

Comments

  • Is this a class project/assignment? We won't do your work for you, but hopefully someone will be able to give you a few pointers.

    -Phil
  • Is this a class project/assignment? We won't do your work for you, but hopefully someone will be able to give you a few pointers.

    -Phil

    It is for a class assignment, but I'm not looking for anyone to do my work for me haha. In fact, I've mostly been pretty self-sufficient but unfortuantely I've been stuck on this problem the past few days. I've tried dozens of things but none of 'em seem to work.

    Thanks!
  • kwinnkwinn Posts: 8,697
    ampersand wrote: »
    .....
    once the ultrasound sensor detects an object, it stops and checks the infrared sensors on either side to see which way to turn.......

    I tried to make the infrared code work while the robot was still moving, but when I did that the robot spun in circles.

    No code posted so I’m guessing that when the robot detects an object and stops there is an opening on one side or the other for it to turn towards. Could it be that when you are checking the sensors while moving that both sensors either sense no opening or both sides open and cause the spinning? Try a dead end corridor and then an object with both sides open to see what happens.
  • kwinn wrote: »
    No code posted

    You have to click on the "Spoilers" button to see it.

    I haven't seen this feature used to hide code before. I think there could be times when this feature would come in handy.

    Good luck with the project ampersand.

  • kwinnkwinn Posts: 8,697
    Duane Degn wrote: »
    kwinn wrote: »
    No code posted

    You have to click on the "Spoilers" button to see it.

    I haven't seen this feature used to hide code before. I think there could be times when this feature would come in handy.

    Good luck with the project ampersand.

    Thanks Duane. Saw "Spoiler" but had no idea that it was for code. Is that the new normal for posting code?
  • PublisonPublison Posts: 12,366
    edited 2017-03-22 19:13
    kwinn wrote: »
    Duane Degn wrote: »
    kwinn wrote: »
    No code posted

    You have to click on the "Spoilers" button to see it.

    I haven't seen this feature used to hide code before. I think there could be times when this feature would come in handy.

    Good luck with the project ampersand.

    Thanks Duane. Saw "Spoiler" but had no idea that it was for code. Is that the new normal for posting code?

    Not sure what the "Spoiler" tag is supposed to do:
    Users may prevent accidental spoiler by wrapping text in spoiler tags. This requires the text to be clicked in order to read it.

    This plugin allows users to hide sensitive or revealing information behind clickable barriers to prevent accidental spoilers.

    And, no, it's not normally used for code. I've only seen it used twice.


  • Perhaps putting the IR system into a separate cog and have that cog update a global variable to indicate an opening in a side wall. This way you or your program can "decide" whether or not to "explore" the opening as a possible exit.
  • Hal Albach wrote: »
    Perhaps putting the IR system into a separate cog and have that cog update a global variable to indicate an opening in a side wall. This way you or your program can "decide" whether or not to "explore" the opening as a possible exit.

    Thanks for the help, I'll try this!
  • Have you tried turning it off and back on?
  • Hey. Did you ever get it to work. If so could i see the updated code possibly. Just wanted to see how you did it because im confused on how to do the cogs
Sign In or Register to comment.