Studio 3

Friday, May 19, 2006

Week 11 - Final Coding

So far we've managed to get the robot to follow a path, and avoid objects when knocked into. However, we didn't managed to get it to do both together, until now.

This is the logic in which RCX code works by, it has up to 3 input sensors, which it can "listen" to all the time. However these sensors do not have prioty over each other, which means if it detects an object with its left bumper, and while manuvering around, it detects a new path, or in this case the same path, as the first command when it bumps into objects would be to reverse, the code that makes it follow the path, would just overright the manuvering code, and the robot will just move forward and knock into the same object again.

This seems rather silly and its an endless loop we tried to find different ways to set prioity to different codes, but on the other hand if the manuvring code is over the follow path code, than it would have to bump into something first before it can follow the path, but we do not want that we want the robot to follow the path first.
So it seem like an endless problem.

So what do we know now:
1. The input sensors will all detect for input at the same time
2. We cannot set prioity to any of the codes
3. All 3 sensors have to be on as there is no function to turn them off or on
4. RCX code runs commands in a top/down procedure

What are the ways around this:
1. Input snesors will still have to detect all at the same time, as it might bump into more objects while manuvering
2. We cannot set prioity to the sensor codes, however there is a "command stack" in RCX code which take prioity over sensor code
3. We cannot run on/off sensors, but we can have sensors to do nothing upon certain conditions *this would be the discovery that helps us solve this problem.
4. Having code run in a top/down procedure would actually be to our advantage, as it would be easy to debug

So with what we've got after long hours of fight with our minds, brainstorming and wrestling with the RCX we came up with the follow concept that fianlly worked.

*Remember in this case all 3 program stacks are running together
on start program
set counter to "0";
if counter == "0" then
follow path;
alternate bewteen motor A(left) and motor C(right) to turn;
else
on both motor A and C;
move straight and prepare for manuvering;
end if
end

//Detects something hitting the left bumper
on left bumper == ture
counter++;
avoid object on left;
counter = 0;
end

//Detects somthing hitting the right bumper
on right bumper == true
counter++;
avoid object on right;
counter = 0;
end

The logic of the above code is rather simple, running the main program stack and set the counter to "0" . This will trigger the robot to follow a standard path, with the other 2 sensor inputs still on, if it bumps into any objects, it will set the counter to "1", which will effectivly stop it from floow the path, as the condistion statment is there. Now with the counter at 1 both motors are on and the manuvering code is free to perform itself, once the manuvering code is done, it sets the counter back to "0", which in turn activates the light sensor again and makes it continue to follow the path.
It feels great to have finally solved a problem, but come to think of it, it took us a rather long time to debug this issue.

0 Comments:

Post a Comment

<< Home