Пример #1
0
    void Update()
    {
        float leftLightSensor;
        float rightLightSensor;

        if (gaussian) // caso a boolean gaussiana esteja ativada a strenght das rodas irá ser calculada pela função gaussiana
        //Read light sensor values
        {
            leftLightSensor  = LeftLD.GetGaussianOutput();
            rightLightSensor = RightLD.GetGaussianOutput();
        }
        else     // caso a boolean gaussiana NÃO esteja ativada a strenght das rodas irá ser calculada linearmente
                 //sem sofrer alterações da funçao normal
        //Read light sensor values
        {
            leftLightSensor  = LeftLD.GetLinearOutput();
            rightLightSensor = RightLD.GetLinearOutput();
        }


        //Read obstacle sensor values
        float leftObstacleSensor  = LeftOD.GetLinearOutput();
        float rightObstacleSensor = RightOD.GetLinearOutput();

        // Calculate target motor values
        // LightSensors estão ligados cruzados e ObstacleSensor estão ligados diretamente
        m_LeftWheelSpeed  = (rightLightSensor + leftObstacleSensor) * MaxSpeed;
        m_RightWheelSpeed = (leftLightSensor + rightObstacleSensor) * MaxSpeed;
    }
Пример #2
0
    void Update()
    {
        //Read sensor values
        float leftSensor  = LeftLD.getLinearOutput();
        float rightSensor = RightLD.getLinearOutput();

        //Calculate target motor values
        m_LeftWheelSpeed  = (rightSensor * MaxSpeed) * 7;
        m_RightWheelSpeed = (leftSensor * MaxSpeed) * 7;
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        float leftSensor  = LeftLD.getLinearOutput();
        float rightSensor = RightLD.getLinearOutput();

        m_LeftWheelSpeed  = leftSensor * MaxSpeed;
        m_RightWheelSpeed = rightSensor * MaxSpeed;


        //Calculate target motor values
        //A velocidade das rodas é inversamente proporcional ao output dos sensores
    }
Пример #4
0
    void Update()
    {
        //Read sensor values
        float leftSensor  = LeftLD.getLinearOutput();
        float rightSensor = RightLD.getLinearOutput();

        //Calculate target motor values
        //Sensor da direita influencia roda da esquerda e vice-versa
        m_LeftWheelSpeed  = rightSensor * MaxSpeed;
        m_RightWheelSpeed = leftSensor * MaxSpeed;

        float westObjectSensor = westOD.getOutput();
        float eastObjectSensor = eastOD.getOutput();

        m_LeftWheelSpeed  += (1 / westObjectSensor) * MaxSpeed;
        m_RightWheelSpeed += (1 / eastObjectSensor) * MaxSpeed;
    }
Пример #5
0
    void Update()
    {
        //Read sensor values
        //sensores de luz
        float leftSensor  = LeftLD.getLinearOutput();
        float rightSensor = RightLD.getLinearOutput();
        //sensores de proximidade
        float leftRaySensor  = RRcast.getDistancia();
        float rightRaySensor = RRcast.getDistancia();

        //Calculate target motor values
        //usa a fórmula de relé (a+b-a*b)
        //quando não detecta nada na proximidade são os sensores de luz que controlam as rodas, estando o da direita ligado ao esquerdo e vice-versa.
        //quando detecta algo na frente ignora os imputs das luzes e gira as rodas em setidos opostos (com velocidade dependente da distância ao objecto) e vira-o para a dirita
        //até não ter nada nos sensores, passando as luzes novamente a controlar as rodas.
        m_LeftWheelSpeed  = (((leftRaySensor + rightRaySensor) / 2) + rightSensor - ((leftRaySensor + rightRaySensor) / 2) * rightSensor) * MaxSpeed;
        m_RightWheelSpeed = (-((leftRaySensor + rightRaySensor) / 2) + leftSensor - -(((leftRaySensor + rightRaySensor) / 2)) * leftSensor) * MaxSpeed;
    }
Пример #6
0
    void Update()
    {
        //Read sensor values
        float leftSensor  = LeftLD.getLinearOutput();
        float rightSensor = RightLD.getLinearOutput();

        //Calculate target motor values
        //A velocidade das rodas é inversamente proporcional ao output dos sensores


        m_LeftWheelSpeed  = (1 / leftSensor) * MaxSpeed;
        m_RightWheelSpeed = (1 / rightSensor) * MaxSpeed;

        float westObjectSensor = westOD.getOutput();
        float eastObjectSensor = eastOD.getOutput();

        m_LeftWheelSpeed  += (1 / westObjectSensor) * MaxSpeed;
        m_RightWheelSpeed += (1 / eastObjectSensor) * MaxSpeed;
    }
Пример #7
0
    void Update()
    {
        //Read sensor values
        float leftSensor  = LeftLD.GetLinearOutput();
        float rightSensor = RightLD.GetLinearOutput();

        //Calculate target motor values

        if (m_LeftWheelSpeed > 5)
        {
            m_LeftWheelSpeed  = leftSensor * MaxSpeed;
            m_RightWheelSpeed = rightSensor * MaxSpeed * 1.5f;
        }
        else
        {
            m_LeftWheelSpeed  = leftSensor * MaxSpeed * 1.5f;
            m_RightWheelSpeed = rightSensor * MaxSpeed;
        }
    }
Пример #8
0
    void Update()
    {
        //Read sensor values
        float leftSensor  = LeftLD.getLinearOutput();
        float rightSensor = RightLD.getLinearOutput();

        //Calculate target motor values
        m_LeftWheelSpeed  = leftSensor * MaxSpeed;
        m_RightWheelSpeed = rightSensor * MaxSpeed;

        float westObjectSensor = westOD.getOutput();
        float eastObjectSensor = eastOD.getOutput();

        m_LeftWheelSpeed  += (1 / westObjectSensor) * MaxSpeed;
        m_RightWheelSpeed += (1 / eastObjectSensor) * MaxSpeed;

        //Calcular os outputs dos sensores

        //Conforme os outputs rodar o carro
    }
Пример #9
0
    void Update()
    {
        //Read sensor values
        float leftSensor  = LeftLD.getLinearOutput();
        float rightSensor = RightLD.getLinearOutput();

        //Calculate target motor values
        m_LeftWheelSpeed  = leftSensor * MaxSpeed;
        m_RightWheelSpeed = rightSensor * MaxSpeed;


        //Calcular os outputs dos sensores
        bool northSensor = northOD.getOutput();
        bool southSensor = southOD.getOutput();
        bool eastSensor  = eastOD.getOutput();
        bool westSensor  = westOD.getOutput();

        //Conforme os outputs rodar o carro
        if (northSensor)
        {
            if (!eastSensor)
            {
                transform.root.transform.Rotate(0, 10, 0);
            }
            else if (!westSensor)
            {
                transform.root.transform.Rotate(0, -10, 0);
            }
            else if (!southSensor)
            {
                transform.root.transform.Rotate(0, 180, 0);
            }
        }

        if (westSensor)
        {
            if (!northSensor)
            {
                transform.root.transform.Rotate(0, 0, 0);
            }
            else if (!eastSensor)
            {
                transform.root.transform.Rotate(0, 10, 0);
            }
            else if (!southSensor)
            {
                transform.root.transform.Rotate(0, 180, 0);
            }
        }


        if (eastSensor)
        {
            if (!northSensor)
            {
                transform.root.transform.Rotate(0, 0, 0);
            }
            else if (!westSensor)
            {
                transform.root.transform.Rotate(0, -10, 0);
            }
            else if (!southSensor)
            {
                transform.root.transform.Rotate(0, 180, 0);
            }
        }

        if (southSensor)
        {
            if (!eastSensor)
            {
                transform.root.transform.Rotate(0, 10, 0);
            }
            else if (!westSensor)
            {
                transform.root.transform.Rotate(0, -10, 0);
            }
        }
    }
Пример #10
0
    void Update()
    {
        //Read sensor values
        float leftSensor  = LeftLD.GetGaussianOutput();
        float rightSensor = RightLD.GetGaussianOutput();

        // strength
        if (leftSensor < limiarMinimo)
        {
            leftSensor = limiarMinimo;
        }
        else if (leftSensor > limiarMaximo)
        {
            leftSensor = limiarMaximo;
        }

        if (rightSensor < limiarMinimo)
        {
            rightSensor = limiarMinimo;
        }
        else if (rightSensor > limiarMaximo)
        {
            rightSensor = limiarMaximo;
        }


        // read sensor values - blocks
        float leftSensorBlock  = LeftBD.GetLinearOutput();
        float rightSensorBlock = RightBD.GetLinearOutput();

        if (leftSensorBlock < limiarMinimo)
        {
            leftSensorBlock = limiarMinimo;
        }
        else if (leftSensorBlock > limiarMaximo)
        {
            leftSensorBlock = limiarMaximo;
        }

        if (rightSensorBlock < limiarMinimo)
        {
            rightSensorBlock = limiarMinimo;
        }
        else if (rightSensorBlock > limiarMaximo)
        {
            rightSensorBlock = limiarMaximo;
        }


        //Calculate target motor values
        m_LeftWheelSpeed  = ((leftSensor + leftSensorBlock) * MaxSpeed);
        m_RightWheelSpeed = ((rightSensor + rightSensorBlock) * MaxSpeed);

        // output
        if (m_LeftWheelSpeed < limiteInferior)
        {
            m_LeftWheelSpeed = limiteInferior;
        }
        else if (m_LeftWheelSpeed > limiteSuperior)
        {
            m_LeftWheelSpeed = limiteSuperior;
        }

        if (m_RightWheelSpeed < limiteInferior)
        {
            m_RightWheelSpeed = limiteInferior;
        }
        else if (m_RightWheelSpeed > limiteSuperior)
        {
            m_RightWheelSpeed = limiteSuperior;
        }
    }
Пример #11
0
    void Update()
    {
        //Read sensor values
        float leftSensor  = LeftLD.getLinearOutput();
        float rightSensor = RightLD.getLinearOutput();

        //Calculate target motor values
        //A velocidade das rodas é inversamente proporcional ao output dos sensores
        //Sensor da direita influencia roda da esquerda e vice-versa
        Debug.Log(leftSensor);
        m_LeftWheelSpeed  = (1 / leftSensor) * MaxSpeed;
        m_RightWheelSpeed = (1 / rightSensor) * MaxSpeed;


        //Calcular os outputs dos sensores
        bool northSensor = northOD.getOutput();
        bool southSensor = southOD.getOutput();
        bool eastSensor  = eastOD.getOutput();
        bool westSensor  = westOD.getOutput();

        //Conforme os outputs rodar o carro
        if (northSensor)
        {
            if (!eastSensor)
            {
                transform.root.transform.Rotate(0, 10, 0);
            }
            else if (!westSensor)
            {
                transform.root.transform.Rotate(0, -10, 0);
            }
            else if (!southSensor)
            {
                transform.root.transform.Rotate(0, 180, 0);
            }
        }

        if (westSensor)
        {
            if (!northSensor)
            {
                transform.root.transform.Rotate(0, 0, 0);
            }
            else if (!eastSensor)
            {
                transform.root.transform.Rotate(0, 10, 0);
            }
            else if (!southSensor)
            {
                transform.root.transform.Rotate(0, 180, 0);
            }
        }


        if (eastSensor)
        {
            if (!northSensor)
            {
                transform.root.transform.Rotate(0, 0, 0);
            }
            else if (!westSensor)
            {
                transform.root.transform.Rotate(0, -10, 0);
            }
            else if (!southSensor)
            {
                transform.root.transform.Rotate(0, 180, 0);
            }
        }
        if (southSensor)
        {
            if (!eastSensor)
            {
                transform.root.transform.Rotate(0, 10, 0);
            }
            else if (!westSensor)
            {
                transform.root.transform.Rotate(0, -10, 0);
            }
        }
    }
Пример #12
0
    void Update()
    {
        //Read sensor values
        float leftSensor  = LeftLD.GetLinearOutput();
        float rightSensor = RightLD.GetLinearOutput();
        //float leftBlockSensor = LeftBD.GetLinearOutput ();
        //float rightBlockSensor = RightBD.GetLinearOutput ();
        float speed;

        //Calculate target motor values
        switch (escolha)
        {
        //Caso linear 1
        case 1:
            m_LeftWheelSpeed  = (leftSensor /*+ leftBlockSensor*/) * MaxSpeed;
            m_RightWheelSpeed = (rightSensor /*+ rightBlockSensor*/) * MaxSpeed;
            break;

        //Caso linear 2
        case 2:
            //Sensor Esquerda
            if (leftSensor > minLimiar && leftSensor < maxLimiar)
            {
                m_LeftWheelSpeed = (leftSensor /*+ leftBlockSensor*/) * MaxSpeed;
            }
            else
            {
                m_LeftWheelSpeed = 0;
            }

            //Sensor Direita
            if (rightSensor > minLimiar && rightSensor < maxLimiar)
            {
                m_RightWheelSpeed = (rightSensor /*+ rightBlockSensor*/) * MaxSpeed;
            }
            else
            {
                m_RightWheelSpeed = 0;
            }
            break;

        //Caso linear 3
        case 3:
            //Sensor Esquerda
            if (leftSensor > minLimiar && leftSensor < maxLimiar)
            {
                float y = (leftSensor /*+ leftBlockSensor*/);
                if (y > botLimit && y < topLimit)
                {
                    m_LeftWheelSpeed = y;
                }
                else if (y < botLimit)
                {
                    m_LeftWheelSpeed = botLimit;
                }
                else if (y > topLimit)
                {
                    m_LeftWheelSpeed = topLimit;
                }
            }
            else
            {
                m_LeftWheelSpeed = botLimit;
            }

            if (rightSensor > minLimiar && rightSensor < maxLimiar)
            {
                float y = (rightSensor /*+ leftBlockSensor*/);
                if (y > botLimit && y < topLimit)
                {
                    m_RightWheelSpeed = y;
                }
                else if (y < botLimit)
                {
                    m_RightWheelSpeed = botLimit;
                }
                else if (y > topLimit)
                {
                    m_RightWheelSpeed = topLimit;
                }
            }
            else
            {
                m_RightWheelSpeed = botLimit;
            }
            m_RightWheelSpeed = m_RightWheelSpeed * MaxSpeed;
            m_LeftWheelSpeed  = m_LeftWheelSpeed * MaxSpeed;

            break;

        case 7:
            //Sensor Esquerda
            if (leftSensor > minLimiar && leftSensor < maxLimiar)
            {
                float y = (1 - leftSensor);
                if (y > botLimit && y < topLimit)
                {
                    m_LeftWheelSpeed = y;
                }
                else if (y < botLimit)
                {
                    m_LeftWheelSpeed = botLimit;
                }
                else if (y > topLimit)
                {
                    m_LeftWheelSpeed = topLimit;
                }
            }
            else
            {
                m_LeftWheelSpeed = botLimit;
            }

            if (rightSensor > minLimiar && rightSensor < maxLimiar)
            {
                float y = (1 - rightSensor);
                if (y > botLimit && y < topLimit)
                {
                    m_RightWheelSpeed = y;
                }
                else if (y < botLimit)
                {
                    m_RightWheelSpeed = botLimit;
                }
                else if (y > topLimit)
                {
                    m_RightWheelSpeed = topLimit;
                }
            }
            else
            {
                m_RightWheelSpeed = botLimit;
            }
            m_RightWheelSpeed = m_RightWheelSpeed * MaxSpeed;
            m_LeftWheelSpeed  = m_LeftWheelSpeed * MaxSpeed;

            break;

        //Caso gaussiana 1 (Fórmula encontrada na Wikipédia)
        case 4:
            m_LeftWheelSpeed  = Mathf.Exp((-Mathf.Pow(leftSensor - media, 2) / (2.0f * Mathf.Pow(desvio, 2)))) * MaxSpeed;
            m_RightWheelSpeed = Mathf.Exp((-Mathf.Pow(rightSensor - media, 2) / (2.0f * Mathf.Pow(desvio, 2)))) * MaxSpeed;
            print("left " + m_LeftWheelSpeed + " right " + m_RightWheelSpeed + "\n");
            break;

        //Caso gaussiana 2 - limite esquerda e direita
        case 5:
            //Sensor Esquerda
            if (leftSensor > minLimiar && leftSensor < maxLimiar)
            {
                m_LeftWheelSpeed = Mathf.Exp((-Mathf.Pow(leftSensor - media, 2) / (2.0f * Mathf.Pow(desvio, 2)))) * MaxSpeed;
            }
            else
            {
                m_LeftWheelSpeed = 0;
            }

            //Sensor Direita
            if (rightSensor > minLimiar && rightSensor < maxLimiar)
            {
                m_RightWheelSpeed = Mathf.Exp((-Mathf.Pow(rightSensor - media, 2) / (2.0f * Mathf.Pow(desvio, 2)))) * MaxSpeed;
            }
            else
            {
                m_RightWheelSpeed = 0;
            }
            break;

        //Caso gaussiana 3
        case 6:
            //Sensor Esquerda
            if (leftSensor < minLimiar || leftSensor > maxLimiar)
            {
                leftSensor = minLimiar;
            }
            //Cálculo da gaussiana
            speed = Mathf.Exp(-Mathf.Pow(leftSensor - media, 2) / (2 * Mathf.Pow(desvio, 2)));
            if (speed > topLimit)
            {
                speed = topLimit;
            }
            else if (speed < botLimit)
            {
                speed = botLimit;
            }
            m_RightWheelSpeed = speed * MaxSpeed;

            //Sensor Direita
            if (rightSensor < minLimiar || rightSensor > maxLimiar)
            {
                rightSensor = minLimiar;
            }
            //Cálculo da gaussiana
            speed = Mathf.Exp(-Mathf.Pow(rightSensor - media, 2) / (2 * Mathf.Pow(desvio, 2)));
            if (speed > topLimit)
            {
                speed = topLimit;
            }
            else if (speed < botLimit)
            {
                speed = botLimit;
            }
            m_LeftWheelSpeed = speed * MaxSpeed;

            break;
            //Caso gaussiana ->elipse
        }
        if (troca == true)
        {
            float temp = m_RightWheelSpeed;
            m_RightWheelSpeed = m_LeftWheelSpeed;
            m_LeftWheelSpeed  = temp;
        }
    }