Menu

[Solved]Following Program Written Nxc Code Bricx Command Center 1 Write Function Move Robot Positi Q37189809

The following program is to be written in NXC code for BricxCommand Center:

1 Write a function that will move the robot from its positionover the last colored line to a position

over the brightest colored line. The function should look at allof the data samples in the array that is sent

to it from main and determine which has the largest value. Then,depending on which slot of the array is

holding this value, you should drive the robot the appropriatedistance in reverse to place the light sensor

over the corresponding line. Display the slot number and thevalue of the brightest line on the LCD.

Return the slot number to the main task, which should storeit.

2 Write a function that will move the robot from the position ofthe brightest colored line to a

position over the darkest colored line. In addition to passingthe array, the slot position of the brightest

line, saved from the previous function, should be sent to thisnew function. You should locate the data

sample with the minimum value in the array. Then, depending onthe relative location of this new

position, the robot should be driven in forward or reverse toplace the light sensor over the darkest line.

Display the slot number and the value of the darkest line on theLCD. Return the slot number to the main

task, which should store it.

3 Write a function that will first compute the average value ofall of the data samples stored in the

passed array. Then find the data sample that has a value that isclosest to this average. It should then

move the robot from its current position over the darkest lineto a position over the line that has the data

value closest to the average, moving forward or backward asnecessary. The slot number of the darkest

line, saved from the previous function, should be sent to thisfunction. Once you reach the spot display

the average value you computed, as well as the slot number andthe value of this particular line on the

LCD.

HINTS & TIPS:

In this program you’re asked to read values of 8 differentcolors and display it on the screen. But the

main task is to move your robot to the brightest, darkest colorand average color.

The sensor in the robot reads the value for you.

Port 3 is used as Sensor port. But there are some robots whosesensor is different so please check your

robot on which port its sensor works.

In this program you’ll introduced arrays. Arrays are collectionof same type of data. Arrays start with

0 and ends at n-1, where n is the number of elements in thearray. Array is declared as data_type

variable_name[size of an array], example: int color[8]

Sample program on how to read and display a color on robotscreen

Please note it this sample program only shows how to read anddisplay a number on the screen. You

will have to figure it out how to determine brightest, darkestand average color value.

Program

void move(int distance)

{

// same as in previous lab

}

void brightest_color () //please add appropriate parameters

{

//write the logic

}

void darkest _color () // please add appropriate parameters

{

//write the logic

}

void average_color() // please add appropriate parameters

{

// write the logic

}

task main()

{

int color[8];

SetSensorLight(S3); // it turns ON sensor in the robot

color[0]= Sensor(S3); // here the value of 1st color is read. Toread rest of the colors use loop

TextOut(0,0, “Value is: “, false); //displays a text on thescreen.

NumOut(0, 50, color[0], false); // here the value of the 1stcolor is displayed on the screen.

// to display values of the rest of the colors use loop.

}

Just as you can see color[0] is used in the above program, itdenotes 1st element of the array. So if you

want to access nth element in an array then that element indexwould be nth

-1.To walk through an

entire array use a loop.

Expert Answer


Answer to The following program is to be written in NXC code for Bricx Command Center: 1 Write a function that will move the robot… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *