0% found this document useful (0 votes)
242 views

Implementation

Uploaded by

api-270809735
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
242 views

Implementation

Uploaded by

api-270809735
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Implementation

Before writing any code start by testing the sensors using the view option in the nxt screen to
check if they are returning a value and are operational.

Start the code by first writing up the task main() and establishing the global variables. In this
project I have only used a long variable for time (t) and an int variable for reversing
(REVERSE_TIME). It is advisable to use more variable specifically for colors. The colors will be
green , and an int variable for keeping track of white raw value. You may name them GREEN for
the range which will specify green and WHITE which will specify white.
Also set up and initialize the sensors. It is best to put light sensor values in raw mode.
The code for setting up sensor in raw is:
SetSensorType(IN_2, SENSOR_TYPE_LIGHT_ACTIVE);
SetSensorMode(IN_2, SENSOR_MODE_RAW);

First step would be to create a bot with semi-random movement or complete random
movement based on the physical design. As our bot has limited ability to react to angles and
corners we are using a semi-random design.
o First create a task movement(). Write a while statement that says, while the neither of
the touch sensors are pressed keep going straight.
o Next outside of this loop write a statement that reverses the bot. How long it reverses is
whats going to be random. The statement for it is
Wait(Random(REVERSE_TIME) + 500)
The 500 that is added is the lower limit of the random reverse. In other words no matter
how low the value of random is the bot will at least move backwards for half a second.
Set the value for REVERSE_TIME in the task main().
o After reversing make the bot turn. While we did not use a random turn, it may be
advisable to use a random turn or instead use
RotateMotor(Port, speed, Random(amount of max angles you wish the tire to rotate);
This will make the bot rotate or turn a random degree and give you random motion.
Debug this entire task.

Second phase is setting up the claw for picking up and recognizing the colors of the balls. Before
you start coding it is best that you have set up Bluetooth functionality for the bot. If not the
other option is to make the raw values of the sensor appear on the nxt screen.
Basically open a new program, create a task main, set up the light sensors for raw values
as described earlier and then afterwards write a while (true) statement. In that statement write
NumOut(50,50, Sensor(port of the light sensor)); and close the loop. Then run the program. This
will set out the raw values onto the screen of the nxt continuously.

After you are done gathering the data for the color values you need to set up a
task the_claw.

Write if else statements such that:


if (light sensor value >= GREEN and light sensor <= WHITE) then
lift claw slowly until it deposits the ball in the container and go back to neutral position.
Else if (light sensor value > WHITE) then
Reverse the claw at full speed so it tosses the ball out and then returns to neutral
position.

Test and debug this task.

Add the task the_claw() to the main program with task movement(). Debug after adding. It is
noteworthy that these tasks should not run at the same time but rather one at a time. Hence
run task movement() at the start and when the touch sensors are triggered it will try to detect if
it picked up a ball. Then if it did (light sensor value will be at least green in this state so use if
statement to check) start the task the_claw and stop the task movement. Once the claw has
done its job start the movement task again and stop the_claw.

Last step is to add a Task Timer(). This task will be responsible for getting out of corners should
it get stuck.
o

Write a while(true) loop. Inside that loop write an if statement such that.
If ((CurrentTick() t) >= 7 seconds) then

Stop task movement and reverse the bot and turn around. Then reset the timer by
putting t = CurrentTick(); And restart task movement. Debug this after adding to the
main program and you should have a fully functional robot.

Debugging Procedure;
Refer to the testing table.

You might also like