public void transitionAction(ref System.Windows.Forms.Panel panel,
                                     System.Windows.Forms.TextBox[] texts, ref int pass)
        {
            switch (state)
            {
            case stIdle:     // nothing
                break;

            case stSensorDataTransmission:
                if (Robosapien.flagSensorDataAcquired)
                {
                    Robosapien.fillSensorTexts(texts);

                    state = stFrameTransmission;
                    Robosapien.retrieveAbstraction();
                }
                break;

            case stFrameTransmission:
                if (Robosapien.flagAbstractionReady)
                {
                    Robosapien.drawAbstraction(panel);
                    state = stAbilityExecuting;
                    // running the cognitive array now
                    double[][] inputVecs = Robosapien.makeInputVector();
                    pass++;
                    int output = (int)MetaNode.getOutput(Robosapien.CogTop, inputVecs, pass);

                    Robosapien.useAbility((t_RSV2Ability)output);
                }
                break;

            case stAbilityExecuting:
                if (Robosapien.flagAbilityDone)
                {
                    Robosapien.flagAbilityDone = false;
                    state = stIdle;
                }
                break;
            }
        }
Ejemplo n.º 2
0
        public void transitionAction(System.Windows.Forms.Panel panel, System.Windows.Forms.TextBox[] texts)
        {
            switch (state)
            {
            case stIdle:     // nothing
                break;

            case stAbilityExecuting:
                if (Robosapien.flagAbilityDone)
                {
                    Robosapien.flagAbilityDone = false;
                    // ability dopne. Now firing the transducers
                    state = stSensorDataTransmission;
                    Robosapien.requestSensorData();
                }
                break;

            case stSensorDataTransmission:
                if (Robosapien.flagSensorDataAcquired)
                {
                    Robosapien.fillSensorTexts(texts);
                    // flag has been cleared inside fillSensorTexts
                    // now retrieving a camera frame abstraction
                    state = stFrameTransmission;
                    Robosapien.retrieveAbstraction();
                }
                break;

            case stFrameTransmission:
                if (Robosapien.flagAbstractionReady)
                {
                    Robosapien.drawAbstraction(panel);     // no need to reset the flag.
                    // It's being reset inside drawAbstraction()
                    state = stIdle;
                }
                break;
            }
        }
        public void browsingStep(ref System.Windows.Forms.TextBox[] texts)
        {
            if ((!close2Cart()) || (TaskQueueLength > 0))
            {
                switch (state)
                {
                case stIdle:
                    // call to the planner
                    planner();
                    // now switching to execution
                    state = stTasksExecuting;
                    break;

                case stSensorDataTransmission:
                    if (Robosapien.flagSensorDataAcquired)
                    {
                        Robosapien.fillSensorTexts(texts);
                        // Now checking if we bumped into something
                        if ((Robosapien.sensorLeft_Hand_Triggered == 1) && (Robosapien.sensorRight_Hand_Triggered == 1))
                        {
                            // re-assigning last move
                            insertPriorityTask(CurrentTask);

                            // inserting correction in queue
                            insertPriorityTask(taskGO_BACKWARD);
                            state = stTasksExecuting;
                        }
                        else
                        if (Robosapien.sensorLeft_Hand_Triggered == 1)
                        {
                            // re-assigning last move
                            insertPriorityTask(CurrentTask);

                            insertPriorityTask(taskGO_BACKLEFT);
                            state = stTasksExecuting;
                        }
                        else
                        if (Robosapien.sensorRight_Hand_Triggered == 1)
                        {
                            // re-assigning last move
                            insertPriorityTask(CurrentTask);

                            insertPriorityTask(taskGO_BACKRIGHT);
                            state = stTasksExecuting;
                        }
                        else             // ability was excuted without interruption. finding new position and orientation
                        {
                            // updating last known position of the robosapien
                            // in the mapping FSM
                            mappingFSM.LastKnownRsv2Ipos = ipos;
                            mappingFSM.LastKnownRsv2Jpos = jpos;

                            // finding new orientation and position
                            switch (orientation)
                            {
                            case orNORTH:
                                switch (CurrentTask)
                                {
                                case taskGO_FORWARD: orientation = orNORTH;

                                    ipos--;

                                    break;

                                case taskGO_BACKWARD: orientation = orNORTH;

                                    ipos++;

                                    break;

                                case taskTURN_LEFT: orientation = orWEST;
                                    break;

                                case taskTURN_RIGHT: orientation = orEAST;
                                    break;
                                }
                                break;

                            case orSOUTH:
                                switch (CurrentTask)
                                {
                                case taskGO_FORWARD: orientation = orSOUTH;

                                    ipos++;

                                    break;

                                case taskGO_BACKWARD: orientation = orSOUTH;

                                    ipos--;

                                    break;

                                case taskTURN_LEFT: orientation = orEAST;
                                    break;

                                case taskTURN_RIGHT: orientation = orWEST;
                                    break;
                                }
                                break;

                            case orEAST:
                                switch (CurrentTask)
                                {
                                case taskGO_FORWARD: orientation = orEAST;

                                    jpos++;

                                    break;

                                case taskGO_BACKWARD: orientation = orEAST;

                                    jpos--;

                                    break;

                                case taskTURN_LEFT: orientation = orNORTH;
                                    break;

                                case taskTURN_RIGHT: orientation = orSOUTH;
                                    break;
                                }
                                break;

                            case orWEST:
                                switch (CurrentTask)
                                {
                                case taskGO_FORWARD: orientation = orWEST;

                                    jpos--;

                                    break;

                                case taskGO_BACKWARD: orientation = orWEST;

                                    jpos++;

                                    break;

                                case taskTURN_LEFT: orientation = orSOUTH;
                                    break;

                                case taskTURN_RIGHT: orientation = orNORTH;
                                    break;
                                }
                                break;
                            }             // end  switch (orientation)



                            state = stIdle;
                        }
                    }
                    break;

                case stTasksExecuting:
                    if (TaskQueueLength == 0)
                    {
                        state = stSensorDataTransmission;
                        Robosapien.requestSensorData();
                    }
                    else
                    {
                        CurrentTask = removeTask();

                        state = stAbilityExecuting;

                        switch (CurrentTask)
                        {
                        case taskGO_FORWARD: Robosapien.useAbility(t_RSV2Ability.abWALK_FORWARD);
                            break;

                        case taskGO_BACKWARD: Robosapien.useAbility(t_RSV2Ability.abWALK_BACKWARD);
                            break;

                        case taskTURN_LEFT: Robosapien.useAbility(t_RSV2Ability.abTURN_LEFT);
                            break;

                        case taskTURN_RIGHT: Robosapien.useAbility(t_RSV2Ability.abTURN_RIGHT);
                            break;

                        case taskGO_BACKLEFT: Robosapien.useAbility(t_RSV2Ability.abWALK_BACKWARDLEFT);
                            break;

                        case taskGO_BACKRIGHT: Robosapien.useAbility(t_RSV2Ability.abWALK_BACKWARDRIGHT);
                            break;

                        case taksGO_FORWARDLEFT: Robosapien.useAbility(t_RSV2Ability.abWALK_FORWARDLEFT);
                            break;

                        case taskGO_FORWARDRIGHT: Robosapien.useAbility(t_RSV2Ability.abWALK_FORWARDRIGHT);
                            break;

                        case taskDISSAPOINTED: Robosapien.useAbility(t_RSV2Ability.abSPARE_CHANGE);
                            break;

                        case taskHUG: Robosapien.useAbility(t_RSV2Ability.abHUG);
                            break;
                        }
                    }

                    break;

                case stAbilityExecuting:
                    if (Robosapien.flagAbilityDone)
                    {
                        // reseting the flag
                        Robosapien.flagAbilityDone = false;
                        // requesting sensor data
                        Robosapien.requestSensorData();
                        // changing state
                        state = stSensorDataTransmission;
                    }     // end if
                    break;
                } // end state switch
            }
        }