1

For full details read the Robocup Documentation.

I am doing senior rescue, If you could help me, I would be very happy.

Thanks.

int diff;
long redValue1;
long greenValue1;
long blueValue1;
long redValue2;
long greenValue2;
long blueValue2;

task main()
{
    repeat(forever)
    {
        getColorRGB(S1, redValue1, greenValue1, blueValue1);
        getColorRGB(S2, redValue2, greenValue2, blueValue2);
        diff = greenValue1-greenValue2;
        diff = diff*2;
        motor[motorA] = -30 -diff;
        motor[motorB] = diff+ -30;
        if (getUSDistance(S3)<10)
        {
            motor[motorA] = -20;
            motor[motorB] = 20;
            delay(800);
            motor[motorA] = -20;
            motor[motorB] = -20;
            delay(1200);
            motor[motorA] = 20;
            motor[motorB] = -20;
            delay(800);
            motor[motorA] = -20;
            motor[motorB] = -20;
            delay(3000);
            motor[motorA] = 20;
            motor[motorB] = -20;
            delay(800);
            motor[motorA] = -20;
            motor[motorB] = -20;
            delay(1200);
            motor[motorA] = -20;
            motor[motorB] = 20;
            delay(800);
        }


        if (greenValue1>14 && redValue1<10 && blueValue1<10
            && greenValue2>14  && redValue2<10 && blueValue2<10){
            playTone(200, 10);

            motor[motorA] = -20;
            motor[motorB] = -20;
            delay(2000);
            motor[motorA] = -20;
            motor[motorA] = 20;
            delay(3000);
            motor[motorA] = -20;
            motor[motorA] = 20;
            waitUntil(getUSDistance(S3)<40);
            motor[motorA] = -60;
            motor[motorA] = -60;
            motor[motorB] = -60;
            motor[motorA] = -60;
            motor[motorB] = -60;
            delay(1000);
            motor[motorA] = 60;
            motor[motorB] = 60;
            delay(600);

        }else{


        }

        if (greenValue1>14 && redValue1<7 && blueValue1<7){
            delay(100);
            motor[motorA] = 40;
            motor[motorB] = -40;
            delay(250);
            }else{

        }

        if (greenValue2>14 && redValue2<7 && blueValue2<7){
            delay(100);
            motor[motorA] = -40;
            motor[motorB] = 40;
            delay(250);
        }else{

        }
    }
}

Linefollowing is the from the 1st line to the 10th line. I am trying to increase the speed to 100. But I can't get the proportion right.

SHR
  • 7,940
  • 9
  • 38
  • 57

1 Answers1

0

I have not personally used more than one light sensor on an NXT for light following. But you should be able to get a decent speed with one sensor. I'll try to explain the code on how to do this below.

(I'm not very familiar with RobotC for NXT, sorry!)

float diff; // change this to float
long redValue1;
long greenValue1;
long blueValue1;
long redValue2;
long greenValue2;
long blueValue2;

float kP = 0.5;
long targetSpeed = -30; 
long targetGreenValue = 67;
// I don't know what this value should be. I suggest approximately 2/3rds toward white.
// If fully black = 0 and fully white = 100, then I would try 67.

task main()
{
    repeat(forever)
    {
        getColorRGB(S1, redValue1, greenValue1, blueValue1);
        diff = (greenValue1 - targetGreenValue)(float) * kP;
        motor[motorA] = targetSpeed - round(diff);
        motor[motorB] = targetSpeed + round(diff);
        delay(10); // This is milliseconds, right?
    }
}
Joseph Dykstra
  • 1,416
  • 1
  • 15
  • 17
  • Thanks, for help. But, we need 2 sensors because on one of the tiles, there is a small green square, either on the LEFT or RIGHT. We need to make that if the left sensor detects green, it would turn left, and so on... I don't think with one sensor, you could do it. – Tankster 10002 Sep 21 '18 at 04:48
  • You do need the two sensors to find the green squares. I was saying that you might only need to use one of your two sensors to follow the line. (But I looked at the video, and saw that the turns are pretty sharp, so that might be tricky to do that quickly.) Anyway, I recommend reading this, if you have not already. http://legolab.daimi.au.dk/Danish.dir/WRO2016Regular/LeftEdgeDrive/PID%20Controller%20For%20Lego%20Mindstorms%20Robots.pdf It describes a PID controller. You and I were describing a P controller. (The I and D parts of the controller are not necessary, and are more difficult.) – Joseph Dykstra Sep 24 '18 at 17:32