Exemple #1
0
    public void AskForInstructions()
    {
        // Ask for instructions
        String data = "";

        foreach (String direction in directions)
        {
            if (direction.Equals("left_front"))
            {
                data += "left,";
            }
            else if (direction.Equals("right_front"))
            {
                data += "right,";
            }
            else if (direction.Equals("front_tip"))
            {
                data += "front,";
            }
            else if (direction.Equals("back"))
            {
                data += "back,";
            }
        }
        if (data.Length > 0)
        {
            data = data.Remove(data.Length - 1);
        }
        writeSocket(data);
        Debug.Log("Sent data to app js: " + data);

        AdvanceSM = AdvanceSMStates.WAITFORINSTRUCTIONS;
    }
Exemple #2
0
    public void UpdateMasterInstruction(string received_instruction)
    {
        /*if (received_instruction == ("up"))
         * {
         *      behaviourManager.v = behaviourManager.GetV + 90f;
         *      MovementManagement(behaviourManager.h, behaviourManager.v);
         * }
         * if (received_instruction == ("down"))
         * {
         *      behaviourManager.v = behaviourManager.v - 0.90f;
         *      MovementManagement(behaviourManager.h, behaviourManager.v);
         *      writeSocket("Hey from Unity!!!");
         * }
         * if (received_instruction == ("left"))
         * {
         *      behaviourManager.h = behaviourManager.h - 0.90f;
         *      MovementManagement(behaviourManager.h, behaviourManager.v);
         * }
         * if (received_instruction == ("right"))
         * {
         *      behaviourManager.h = behaviourManager.h + 0.90f;
         *      MovementManagement(behaviourManager.h, behaviourManager.v);
         *
         * }*/

        if (received_instruction == ("up"))
        {
            // Continue straight ahead
            // No changes needed in direction
        }
        if (received_instruction == ("back"))
        {
            behaviourManager.v = behaviourManager.GetV - .3f;
            MovementManagement(behaviourManager.h, behaviourManager.v);
        }
        if (received_instruction == ("left"))
        {
            behaviourManager.h = behaviourManager.h - 0.50f;
            MovementManagement(behaviourManager.h, behaviourManager.v);
        }
        if (received_instruction == ("right"))
        {
            behaviourManager.h = behaviourManager.h + 0.50f;
            MovementManagement(behaviourManager.h, behaviourManager.v);
        }

        Debug.Log("Instruction received: " + received_instruction.ToString());

        AdvanceSM = AdvanceSMStates.PROCESSINSTRUCTION;
    }
Exemple #3
0
    public void AdvanceStep()
    {
        //Debug.Log(AdvanceSM.ToString());
        switch (AdvanceSM)
        {
        case AdvanceSMStates.IDLE:
            break;

        case AdvanceSMStates.ASKFORINSTRUCTIONS:
            AskForInstructions();
            break;

        case AdvanceSMStates.WAITFORINSTRUCTIONS:
            break;

        case AdvanceSMStates.PROCESSINSTRUCTION:
            processinstruction_ctr++;
            if (processinstruction_ctr >= 100)
            {
                processinstruction_ctr = 0;
                AdvanceSM = AdvanceSMStates.GETOUTOFCROSSROADS;
            }
            break;

        case AdvanceSMStates.GETOUTOFCROSSROADS:
            // We just received the instructions, get into move out of the asked crossroad
            if (directions.Contains("right") && directions.Contains("left"))
            {
                AdvanceSM = AdvanceSMStates.MOVEUNTILNEWSCENARIO;
            }
            else
            {
                // Move until pass the current crossroad

                // Main movement logic
                if (directions.Contains("front_left"))
                {
                    behaviourManager.h = behaviourManager.h + 0.010f;
                    MovementManagement(behaviourManager.h, behaviourManager.v);
                }
                else if (directions.Contains("front_right"))
                {
                    behaviourManager.h = behaviourManager.h - 0.010f;
                    MovementManagement(behaviourManager.h, behaviourManager.v);
                }
                //else
                {
                    // Move to front
                    behaviourManager.v = behaviourManager.GetV + .3f;
                    MovementManagement(behaviourManager.h, behaviourManager.v);
                }
            }
            break;

        case AdvanceSMStates.MOVEUNTILNEWSCENARIO:
            if (directions.Contains("front") || !directions.Contains("left") || !directions.Contains("right"))
            {
                AdvanceSM = AdvanceSMStates.ASKFORINSTRUCTIONS;
            }
            else
            {
                // Main movement logic
                if (directions.Contains("front_left"))
                {
                    behaviourManager.h = behaviourManager.h + 0.010f;
                    MovementManagement(behaviourManager.h, behaviourManager.v);
                }
                else if (directions.Contains("front_right"))
                {
                    behaviourManager.h = behaviourManager.h - 0.010f;
                    MovementManagement(behaviourManager.h, behaviourManager.v);
                }
                //else
                {
                    // Move to front
                    behaviourManager.v = behaviourManager.GetV + .3f;
                    MovementManagement(behaviourManager.h, behaviourManager.v);
                }
            }
            break;

        default:
            break;
        }
    }