【问题标题】:Robotc Line Follow Code Needs to be FasterRobotc Line Follow 代码需要更快
【发布时间】:2018-06-25 04:57:39
【问题描述】:

详情请阅读Robocup Documentation

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

谢谢。

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 是从第 1 行到第 10 行。我正在尝试将速度提高到 100。但我无法获得正确的比例。

【问题讨论】:

  • 您可能想尝试将diff 设为float,而不是int,然后将其更改为1.5 或类似的值。您可能需要进行一些类型转换。
  • greenValue1的范围是多少? 0-100? 0-4095?
  • “float”是什么意思,我也相信机器人会测量绿色值。
  • greenValue1 的最小数字是多少,最大数字是多少?
  • float 是一种类型,类似于int,但它不仅可以存储整数值,还可以存储带有一些小数位的数字。例如。 int 不能存储 1.5,但 float 可以

标签: robotc


【解决方案1】:

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

(我对 NXT 的 RobotC 不是很熟悉,抱歉!)

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?
    }
}

【讨论】:

  • 谢谢您的帮助。但是,我们需要 2 个传感器,因为在其中一个瓷砖上,有一个绿色的小方块,在左边或右边。我们需要做到这一点,如果左侧传感器检测到绿色,它就会向左转,依此类推……我不认为只有一个传感器就可以做到。
  • 您确实需要两个传感器才能找到绿色方块。我是说你可能只需要使用你的两个传感器之一来跟踪这条线。 (但我看了视频,发现转弯非常锋利,所以要快速做到这一点可能会很棘手。)无论如何,如果你还没有,我建议你阅读这篇文章。 legolab.daimi.au.dk/Danish.dir/WRO2016Regular/LeftEdgeDrive/… 它描述了一个 PID 控制器。你和我在描述一个 P 控制器。 (控制器的I和D部分不是必须的,难度更大。)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多