首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Robotc Line Follow代码需要更快

Robotc Line Follow代码需要更快
EN

Stack Overflow用户
提问于 2018-06-25 12:57:39
回答 1查看 54关注 0票数 1

有关完整的详细信息,请阅读Robocup Documentation

我正在做高级救援,如果你能帮我,我会很高兴的。

谢谢。

代码语言:javascript
复制
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{

        }
    }
}

下面是第1行到第10行。我正试着把速度提高到100。但是我找不到合适的比例。

EN

回答 1

Stack Overflow用户

发布于 2018-09-20 06:41:24

我个人没有在NXT上使用过一个以上的光传感器来跟踪光线。但是你应该能够在一个传感器上获得一个不错的速度。下面我将尝试解释如何执行此操作的代码。

(我不太熟悉用于NXT的RobotC,对不起!)

代码语言:javascript
复制
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?
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51016527

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档