Ejemplo n.º 1
0
 void Update()
 {
     if (robotVision != null)
     {
         List <GameObject> objectsInFildOfVision = robotVision.getListOfElements();
         List <GameObject> objectsInSmellSense   = robotSmell.getListOfElements();
         List <GameObject> objectsInHearingSense = robotHearing.getListOfElements();
         List <GameObject> objectsInTasteSense   = robotTaste.getListOfElements();
         List <GameObject> objectsInTouchSense   = robotTouch.getListOfElements();
         List <GameObject> allObjectsInSenses    = objectsInFildOfVision.Union(objectsInSmellSense).ToList();
         allObjectsInSenses   = allObjectsInSenses.Union(objectsInHearingSense).ToList();
         allObjectsInSenses   = allObjectsInSenses.Union(objectsInTouchSense).ToList();
         allPerceivedElements = new HashSet <GameObject>(allObjectsInSenses);
         List <GameObject> auxGOLocations = new List <GameObject>(getElementsOfTagType(allObjectsInSenses, Constants.TAG_LOCATION));
         auxGOLocations.AddRange(locationsOnScene);
         objectsList = new List <GameObject>(getElementsOfTagType(allObjectsInSenses, Constants.TAG_OBJECT));
         switchsList = new List <GameObject>(getElementsOfTagType(allObjectsInSenses, Constants.TAG_SWITCH));
         //doorsList = new List<GameObject>(getElementsOfTagType(objectsInFildOfVision, Constants.TAG_DOOR));
         locationsList = new List <GameObject>(auxGOLocations);
     }
     if (commandsQueue.Count > 0 & manageExecution())
     {
         execute(commandsQueue.Dequeue());
     }
 }
Ejemplo n.º 2
0
    void Update()
    {
        HashSet <GameObject> elementsSeenByRobot = new HashSet <GameObject>(vision.getListOfElements());
        //dropObjects.options.Clear();
        string auxText = "";

        foreach (GameObject item in elementsSeenByRobot)
        {
            if (item.tag == Constants.TAG_OBJECT)
            {
                //dropObjects.options.Add(new Dropdown.OptionData() { text = item.name });
            }
            auxText = auxText + "\n---\n" + item.tag + ": " + item.name + " " + item.transform.position;
        }
        text.text = auxText + "\n\n";
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (avatarVision != null)
        {
            List <GameObject> objectsInFildOfVision = avatarVision.getListOfElements();

            List <GameObject> auxGOLocations = new List <GameObject>(getElementsOfTagType(objectsInFildOfVision, Constants.TAG_LOCATION));
            objectsList = new List <GameObject>(getElementsOfTagType(objectsInFildOfVision, Constants.TAG_OBJECT));
            switchsList = new List <GameObject>(getElementsOfTagType(objectsInFildOfVision, Constants.TAG_SWITCH));
            //doorsList = new List<GameObject>(getElementsOfTagType(objectsInFildOfVision, Constants.TAG_DOOR));
            locationsList = new List <GameObject>(auxGOLocations);
        }

        if (commandsQueue.Count > 0 & manageExecution())
        {
            execute(commandsQueue.Dequeue());
        }
    }
Ejemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if (command != null)
        {
            switch (command.getAction())
            {
            case Action.HeadFocus:
                updateFocus(command.getNearestDesiredPosition(transform.position));
                switch (command.getActionStateID())
                {
                case (int)HeadFocus.Start:
                    Debug.Log("Command>>> " + this.name + " command " + command.getId() + " Started!");
                    command.next();
                    break;

                case (int)HeadFocus.Position:
                    ik = true;
                    if (animator.GetFloat("HeadReach") > 0.9)
                    {
                        Debug.Log("Command>>> " + this.name + " command " + command.getId() + " Success!");
                        command.success();
                    }
                    else
                    if (command.getReference() != null && isFocusInPosition(focus, command.getReference().position) && !isVisible(command.getReference()))
                    {
                        Debug.Log("Command>>> " + this.name + " command " + command.getId() + " Failed! Obj. is not visible.");
                        command.fail();
                    }
                    break;

                case (int)HeadFocus.End:
                    if (command.isFail())
                    {
                        ik = false;
                    }
                    break;
                }
                break;

            case Action.HeadReset:
                switch (command.getActionStateID())
                {
                case (int)HeadReset.Start:
                    Debug.Log("Command>>> " + this.name + " command " + command.getId() + " Started!");
                    command.next();
                    break;

                case (int)HeadReset.Position:
                    moveFocus(originalFocusRotation);
                    if (isFocusMoved(focus.parent.localRotation, originalFocusRotation))
                    {
                        ik = false;
                    }
                    if (animator.GetFloat("HeadReach") < 0.25)
                    {
                        Debug.Log("Command>>> " + this.name + " command " + command.getId() + " Success!");
                        command.success();
                    }
                    break;

                case (int)HeadReset.End:
                    break;

                default:
                    break;
                }
                break;

            case Action.LookFor:
                switch (command.getActionStateID())
                {
                case (int)LookFor.Start:
                    Debug.Log("Command>>> " + this.name + " command " + command.getId() + " Started!");
                    command.next();
                    break;

                case (int)LookFor.Position:
                    ik = true;
                    Quaternion auxQuater = Quaternion.Euler(listOfRotations[0]);
                    moveFocus(originalFocusRotation);
                    if (isFocusMoved(focus.parent.localRotation, originalFocusRotation))
                    {
                        idListOfRot = 0;
                        command.next();
                    }
                    break;

                case (int)LookFor.Search:
                    if (idListOfRot < listOfRotations.Count)
                    {
                        Quaternion auxQuater2 = Quaternion.Euler(listOfRotations[idListOfRot]);
                        moveFocus(originalFocusRotation * auxQuater2);
                        if (isFocusMoved(focus.parent.localRotation, originalFocusRotation * auxQuater2))
                        {
                            idListOfRot++;
                            if (isOnList(robotVision.getListOfElements(), command.getRefName()))
                            {
                                command.next();
                            }
                        }
                    }
                    else
                    {
                        Debug.Log("Command>>> " + this.name + " command " + command.getId() + " Failed! " + command.getRefName() + " Not found.");
                        command.fail();
                    }
                    break;

                case (int)LookFor.Focus:
                    if (command.getReference() == null)
                    {
                        GameObject auxGameObject = getOnList(robotVision.getListOfElements(), command.getRefName());
                        if (auxGameObject != null)
                        {
                            command.setReference(auxGameObject.transform);
                            if (isFocusInPosition(focus, auxGameObject.transform.position) && !isVisible(auxGameObject.transform))
                            {
                                Debug.Log("Command>>> " + this.name + " command " + command.getId() + " Failed! Obj. is not visible.");
                                command.fail();
                            }
                        }
                        else
                        {
                            command.resetState();
                        }
                    }
                    else
                    {
                        updateFocus(command.getNearestDesiredPosition(transform.position));
                        if (isFocusInPosition(focus, command.getNearestDesiredPosition(transform.position)) && (animator.GetFloat("HeadReach") > 0.9))
                        {
                            command.next();
                        }
                    }
                    break;

                case (int)LookFor.Turn:
                    Command auxCommand = new Command("", Action.Turn, command.getReference());
                    GetComponent <AgentMovement>().sendCommand(auxCommand);
                    Debug.Log("Command>>> " + this.name + " command " + command.getId() + " Success!");
                    command.success();
                    break;

                case (int)LookFor.End:
                    if (command.isFail())
                    {
                        moveFocus(originalFocusRotation);
                        if (isFocusMoved(focus.parent.localRotation, originalFocusRotation))
                        {
                            ik = false;
                        }
                    }
                    else
                    {
                        updateFocus(command.getNearestDesiredPosition(transform.position));
                    }
                    break;

                default:
                    break;
                }
                break;
            }
        }
    }
Ejemplo n.º 5
0
    /*void FixedUpdate () {
     *
     *  if (count % sensesRefreshRate == 0)
     *  {
     *      //Vision
     *      objectsInFildOfVision = vision.getListOfElements();
     *      //Hear
     *      soundsInHearing = hearing.getListOfElements();
     *      knowObjInHearing = objectsInFildOfVision.Intersect(soundsInHearing).ToList();
     *      foreach (GameObject obj in knowObjInHearing)
     *      {
     *          soundsInHearing.Remove(obj);
     *      }
     *      //Smell
     *      odorInSmell = smell.getListOfUnknowElements();
     *      //Touch
     *      knowObjInTouch = touch.getListOfKnowElements();
     *      touchInTouch = touch.getListOfUnknowElements();
     *
     *
     *      insertVision(objectsInFildOfVision);
     *  }
     *  if (count % triggerRefreshRate == 0)
     *  {
     *      knowObjInSmell = smell.getListOfKnowElements();
     *      //Taste
     *      objectsInTaste = taste.getListOfElements();
     *  }
     *  count++;
     * }*/

    void FixedUpdate()
    {
        if (getSensesCommand != null)
        {
            switch (getSensesCommand.getActionStateID())
            {
            case (int)GetSenses.Start:
                //if (count % sensesRefreshRate == 0){
                Debug.Log("Command>>> " + this.name + " command " + getSensesCommand.getId() + " Started!");
                //Vision
                objectsInFildOfVision = vision.getListOfElements();
                visionQueue           = new Queue <GameObject>(objectsInFildOfVision);

                //Hear
                soundsInHearing = hearing.getListOfElements();

                knowObjInHearing = objectsInFildOfVision.Intersect(soundsInHearing).ToList();
                hearKnowQueue    = new Queue <GameObject>(knowObjInHearing);
                foreach (GameObject obj in knowObjInHearing)
                {
                    soundsInHearing.Remove(obj);
                }
                hearUnkQueue = new Queue <GameObject>(soundsInHearing);
                //Smell
                odorInSmell   = smell.getListOfUnknowElements();
                smellUnkQueue = new Queue <GameObject>(odorInSmell);
                //Touch
                knowObjInTouch = touch.getListOfKnowElements();
                touchKnowQueue = new Queue <GameObject>(knowObjInTouch);
                //Unknow objects in touch
                touchInTouch  = touch.getListOfUnknowElements();
                touchUnkQueue = new Queue <GameObject>(touchInTouch);
                //objQueue = new Queue<GameObject>(objectsInFildOfVision.Union(soundsInHearing).Union(knowObjInHearing).Union(odorInSmell).Union(knowObjInTouch).Union(touchInTouch));
                int totalSize = visionQueue.Count + touchKnowQueue.Count + touchUnkQueue.Count + hearUnkQueue.Count +
                                hearKnowQueue.Count + smellUnkQueue.Count;
                batchSize = (int)Math.Ceiling((float)totalSize / sensesRefreshRate);
                //insertVision(objectsInFildOfVision);
                atDateTime = DateTime.Now;
                //}
                getSensesCommand.next();
                break;

            case (int)GetSenses.Position:

                for (int i = 0; i < batchSize; i++)
                {
                    if (visionQueue.Count > 0)
                    {
                        insertVision(visionQueue.Dequeue(), atDateTime);
                    }
                    else if (hearKnowQueue.Count > 0)
                    {
                        insertHearID(hearKnowQueue.Dequeue(), atDateTime);
                    }
                    else if (hearUnkQueue.Count > 0)
                    {
                        insertHearPos(hearUnkQueue.Dequeue(), atDateTime);
                    }
                    else if (touchKnowQueue.Count > 0)
                    {
                        insertTouchID(touchKnowQueue.Dequeue(), atDateTime);
                    }
                    else if (touchUnkQueue.Count > 0)
                    {
                        insertTouchPos(touchUnkQueue.Dequeue(), atDateTime);
                    }
                    else if (smellUnkQueue.Count > 0)
                    {
                        insertSmellPos(smellUnkQueue.Dequeue(), atDateTime);
                    }
                }
                if (count % triggerRefreshRate == 0)
                {
                    knowObjInSmell = smell.getListOfKnowElements();
                    foreach (GameObject goSmell in knowObjInSmell)
                    {
                        insertSmellID(goSmell, DateTime.Now);
                    }
                    //Taste
                    objectsInTaste = taste.getListOfElements();
                    foreach (GameObject goTaste in objectsInTaste)
                    {
                        insertTaste(goTaste, DateTime.Now);
                    }
                }
                count++;
                if (count % sensesRefreshRate == 0)
                {
                    count = 0;
                    getSensesCommand.success();
                    Debug.Log("Command>>> " + this.name + " command " + getSensesCommand.getId() + " Success!");
                }

                break;

            case (int)GetSenses.End:
                break;

            default:
                break;
            }
        }
    }
Ejemplo n.º 6
0
    /*void FixedUpdate () {
     *
     *  if (count % sensesRefreshRate == 0)
     *  {
     *      //Vision
     *      objectsInFildOfVision = vision.getListOfElements();
     *      //Hear
     *      soundsInHearing = hearing.getListOfElements();
     *      knowObjInHearing = objectsInFildOfVision.Intersect(soundsInHearing).ToList();
     *      foreach (GameObject obj in knowObjInHearing)
     *      {
     *          soundsInHearing.Remove(obj);
     *      }
     *      //Smell
     *      odorInSmell = smell.getListOfUnknowElements();
     *      //Touch
     *      knowObjInTouch = touch.getListOfKnowElements();
     *      touchInTouch = touch.getListOfUnknowElements();
     *
     *
     *      insertVision(objectsInFildOfVision);
     *  }
     *  if (count % triggerRefreshRate == 0)
     *  {
     *      knowObjInSmell = smell.getListOfKnowElements();
     *      //Taste
     *      objectsInTaste = taste.getListOfElements();
     *  }
     *  count++;
     * }*/

    void FixedUpdate()
    {
        if (count % sensesRefreshRate == 0)
        {
            //Vision
            objectsInFildOfVision = vision.getListOfElements();
            visionQueue           = new Queue <GameObject>(objectsInFildOfVision);

            //Hear
            soundsInHearing = hearing.getListOfElements();

            knowObjInHearing = objectsInFildOfVision.Intersect(soundsInHearing).ToList();
            hearKnowQueue    = new Queue <GameObject>(knowObjInHearing);
            foreach (GameObject obj in knowObjInHearing)
            {
                soundsInHearing.Remove(obj);
            }
            hearUnkQueue = new Queue <GameObject>(soundsInHearing);
            //Smell
            odorInSmell   = smell.getListOfUnknowElements();
            smellUnkQueue = new Queue <GameObject>(odorInSmell);
            //Touch
            knowObjInTouch = touch.getListOfKnowElements();
            touchKnowQueue = new Queue <GameObject>(knowObjInTouch);
            //Unknow objects in touch
            touchInTouch  = touch.getListOfUnknowElements();
            touchUnkQueue = new Queue <GameObject>(touchInTouch);
            //objQueue = new Queue<GameObject>(objectsInFildOfVision.Union(soundsInHearing).Union(knowObjInHearing).Union(odorInSmell).Union(knowObjInTouch).Union(touchInTouch));
            int totalSize = visionQueue.Count + touchKnowQueue.Count + touchUnkQueue.Count + hearUnkQueue.Count +
                            hearKnowQueue.Count + smellUnkQueue.Count;
            batchSize = (int)Math.Ceiling((float)totalSize / sensesRefreshRate);
            //insertVision(objectsInFildOfVision);
            atDateTime = DateTime.Now;
        }
        for (int i = 0; i < batchSize; i++)
        {
            if (visionQueue.Count > 0)
            {
                insertVision(visionQueue.Dequeue(), atDateTime);
            }
            else if (hearKnowQueue.Count > 0)
            {
                insertHearID(hearKnowQueue.Dequeue(), atDateTime);
            }
            else if (hearUnkQueue.Count > 0)
            {
                insertHearPos(hearUnkQueue.Dequeue(), atDateTime);
            }
            else if (touchKnowQueue.Count > 0)
            {
                insertTouchID(touchKnowQueue.Dequeue(), atDateTime);
            }
            else if (touchUnkQueue.Count > 0)
            {
                insertTouchPos(touchUnkQueue.Dequeue(), atDateTime);
            }
            else if (smellUnkQueue.Count > 0)
            {
                insertSmellPos(smellUnkQueue.Dequeue(), atDateTime);
            }
        }
        if (count % triggerRefreshRate == 0)
        {
            knowObjInSmell = smell.getListOfKnowElements();
            foreach (GameObject goSmell in knowObjInSmell)
            {
                insertSmellID(goSmell, DateTime.Now);
            }
            //Taste
            objectsInTaste = taste.getListOfElements();
            foreach (GameObject goTaste in objectsInTaste)
            {
                insertTaste(goTaste, DateTime.Now);
            }
        }
        count++;
    }