[Solved] Following Code Written Nxt Nxc Bricx Command Center Write Function First Compute Average V Q37205824
The following code is written in NXT (.nxc) for Bricx CommandCenter:
Write a function that will first compute the average value ofall of the data samples stored in the passed array. Then find thedata sample that has a value that is closest to this average. Itshould then move the robot from its current position over thedarkest line to a position over the line that has the data valueclosest to the average, moving forward or backward as necessary.The slot number of the darkest line, saved from the previousfunction, should be sent to this function. Once you reach the spotdisplay the average value you computed, as well as the slot numberand the value of this particular line on the LCD. Make thisaddition to the code.
void move(float distance)
{
float sec;
if (distance >= 0) { //Write logic for robot to moveforward.
sec= 122.2*distance+27.352;
OnFwd(OUT_A, 47);
OnFwd(OUT_C, 44);
Wait(sec);
Off(OUT_AC);
}
else {
//Write #pragma debugbreak “msg”
//logic for robot to move backward.
sec= 124.07*distance+55.063;
OnRev(OUT_A, 52);
OnRev(OUT_C, 49);
Wait(sec*-1);
Off(OUT_AC);
}
}
int brightest_color(int color[])
{
int g = 0;
int j;
for(j=0;j<8;j++)
{
if( color[j] > color[g])
g=j;
}
Wait(500);
move((g-7)*3.7);
NumOut(30, 30, g, false);
Wait(3000);
return g;
}
void darkest_color(int color[],int g)
{
int e = 0;
int k;
for(k=0;k<8;k++)
{
if( color[k] < color[e])
e=k;
}
Wait(500);
move((e-g)*3.7);
NumOut(30, 30, e, false);
Wait(3000);
}
task main()
{
Wait(100);
SetSensorLight(S3); // it turns ON sensor in the robot
int color[8];
int step = 0;
int i,g;
for(i=0;i<8;i++)
{
move(4.0);
color[i]= 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(60, 8*i, color[i], false); // here the value of the 1stcolor is displayed on the screen.
// to display values of the rest of the colors use loop.
Wait(500);
}
Wait(5000);
g=brightest_color(color);
Wait(3000);
darkest_color(color,g);
}
Expert Answer
Answer to The following code is written in NXT (.nxc) for Bricx Command Center: Write a function that will first compute the avera… . . .
OR

