You are on page 1of 3

In order to make this code compile, run successfully, and easy to write there are certain

steps that the code can be created in, and in this way each task, define, or command that you
use will run properly:
1. Before writing task main() make sure that you have all your defines clear and that they
make sense because they are there in order to make writing and understanding the
code easier just in case the program does not run the way it is supposed to. For example
make sure that your defines for the each sensor and what port they are in is true, and
that a mistake was not made because that will mess up the entire program.
2. The most important step is to write your main task(task main()), which will be the
simplest of the tasks, and will set all of your sensors in the ports that they are supposed
to be, and will also start the other tasks that you created(task ball(), task hunt(), task
wall()).
3. Because we have separate tasks before running and testing your program it is important
to stop one task when a condition in another task is true because it will be a mess if they
are being executed at the same time. The way to do this is to strategically place each
task in a certain area in the code and when one task starts that might conflict with the
task that is already running, then before anything is executed within the code a stop__
will have to be written. By doing this no tasks will interfere with each other and make
the robot act strangely and not do what it is supposed to do. The only way to do this
correctly is to write the code, run it and continuously revise it. The easiest way to do this
is to start with the most important task, test to see if it runs successfully and then add
one task at a time, test it and revise it if need be.
4. The first task that you want to deal with now is hunt() because without your robot
sampling the arena space and moving around randomly continuously if will not come in
contact with any balls. In order to do this in the most easiest way is to use a while(true),
because the while statement will always be true and will loop continuously, and then
inside this while(true) you will assign the variables to different randomizations, and then
use those variables as Wait(____) times for when the robot moves forward, and when it
turns right, in order to make it continuously move around the arena at random.
5. If the robot is still not running correctly make sure that the two variables that you set up
for the robot to move continuously are placed correctly in the code, which should be
outside of all tasks, it is like a define in the sense that it is a preprocessor. If it still is not
working make sure that when you refer to it in the wait() times that it is spelled
correctly/the same way.
6. The robot is now moving around successfully, but now you have to deal with it running
into the walls of the arena, so you have to write another task called wall(). In this task
will reside a while(true) so that is continuously loops, because the robot will
continuously be randomly moving around and also probably be continuously running
into the walls. It will be easiest if in the while(true) there is a condition statement(an
“if”) using the ultrasound sensor in the front of the robot, so that if the robot is a certain
distance away it then reverses for a certain amount of time and then moves forward
again and continues sampling the arena space. However, if you test the code like this
the robot will be doing weird movements and that is because there are two tasks
working at the same time when a wall is encountered, so now you have to start testing
were to put a stop task;. After testing and revising you should have it run successfully if
there is a stop hunt; inside the task wall() at the beginning of the if(), and then a start
hunt; at the end of the if(), because after the robot encounters a wall and reverses you
want it to go back to randomly moving around in search of a ball.
7. Now that you have the robot moving around successfully you have to make it so that it
discerns between green colored balls and white colored balls. This will be done in the
next most important task called ball(). The easiest way to do this is to again have a
while(true) statement so that it loops continuously while the robot is randomly moving
continuously, and then inside the while(true) there will be “if” statements/conditions.
One of them will be a dynamic threshold for the values of the green ball, and the other
will be a dynamic threshold for the values of the white balls. The first “if” statement will
deal with the dynamic threshold for the green balls, however, before we can write any
robot execution code we need to write stop hunt; , and then stop wall(), because we do
not want the robot to continuously move around randomly once a green ball is
detected, instead we want the robot to eject it out of the arena. After the stop wall; you
can then write code to make the ball stay on the forklift(by lifting the arm a little), and
then tell the robot to reverse until the touch sensors on the back are activated, and
once they are the forklift can lift all the way up at a high speed to make sure the green
ball clears the arena. Lastly inside this if() statement you need to write start hunt; and
start wall; because after ejecting a green wall you want it to go back to searching. If the
code still does not properly work try using an until() statement for when the bumpers
on the back of the robot are activated, and then ejecting the green ball.
8. The last step is to make the robot not eject white balls, and that is also going to be done
in task ball(), by using another condition statement within the while(true), but this one
will have a threshold dealing with the readings of the white ball. In this “if else()”
statement you want to make sure to write stop hunt; and stop wall; at the beginning so
that no tasks are running at the same time, which will cause the robot to act weird. You
can then write code that will make it avoid white balls by slightly reversing when
encountering one in order to clear the light sensor, and then restart searching for more
balls again. If the code does not work make sure that start hunt; and start wall; are
written at the end of that condition statement that deals with what the robot should do
when it picks up the readings/threshold of a white ball.
9. Lastly if the program is still not working correctly, make sure that the thresholds in task
ball() for white and green balls are correct because the range for white and green balls is
very large depending on how close they are to the light sensor, so you will have to
continuously test and revise the code until you find perfectly compatible thresholds.

You might also like