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:
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
-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!
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.
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:
And, no, it's not normally used for code. I've only seen it used twice.
Thanks for the help, I'll try this!