⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sim.cpp

📁 a program that generates a pulse-width modulated (PWM)signal.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            // Action
            // Test/Exit
            if(GetRTMessage(LOAD_ROBOT_CMD_LoadCylinder,&MsgIndex,
                        &MsgVal,&FromTask))
                {
                // Load the cylinder
                NextState = PickupCylinder;
                cmdFromTask = FromTask;
                cmdFromBox = MsgIndex;
                }
            if(GetRTMessage(LOAD_ROBOT_CMD_LoadBase,&MsgIndex,
                        &MsgVal,&FromTask))
                {
                // Load the base
                NextState = PickupBase;
                cmdFromTask = FromTask;
                cmdFromBox = MsgIndex;
                }
            break;
        case PickupCylinder:
            // Entry
            if(RunEntry)
                {
                PrivateGlobalData[LOAD_ROBOT_Status] = 2;  // Moving
                StartTime = GetTimeNow();
                }
            // Action
            // Test/Exit
            if(GetTimeNow() >= (StartTime + LoadCylinderTime/2.0))
                {
                NextState = PlaceCylinder;
                }
            break;
        case PlaceCylinder:
            // Entry
            if(RunEntry)
                {
                StartTime = GetTimeNow();
                }
            // Action
            // Test/Exit
            if(GetTimeNow() >= (StartTime + LoadCylinderTime/2.0))
                {
                NextState = GoingToReady;
                }
            break;
        case PickupBase:
            // Entry
            if(RunEntry)
                {
                PrivateGlobalData[LOAD_ROBOT_Status] = 1;  // Moving
                StartTime = GetTimeNow();
                }
            // Action
            // Test/Exit
            if(GetTimeNow() >= (StartTime + LoadBaseTime/2.0))
                {
                NextState = PlaceBase;
                }
            break;
        case PlaceBase:
            // Entry
            if(RunEntry)
                {
                StartTime = GetTimeNow();
                }
            // Action
            // Test/Exit
            if(GetTimeNow() >= (StartTime + LoadBaseTime/2.0))
                {
                NextState = GoingToReady;
                }
            break;
        case GoingToReady:
            // Entry
            if(RunEntry)
                {
                StartTime = GetTimeNow();
                }
            // Action
            // Test/Exit
            if(GetTimeNow() >= (StartTime + ToReadyTime))
                {
                NextState = AtReady;
                }
            break;
        default:
            StopControl("<LoadRobot> Illegal state");
        }
    PrivateGlobalData[LOAD_ROBOT_State] = State;
    CopyGlobal();  // Make global data visible
    return(1);
    }

// UnLoad Robot
//States:
#define Initialize 0
#define Start 1
#define PickupAssembly 2
#define PlaceAssembly 3
#define GoingToReady 4
#define AtReady 5

CUnloadRobot::CUnloadRobot(char *aName,double aUnloadTime,
            double aToReadyTime,int ProcNo) :BaseTask(aName,ProcNo)
    {
    UnloadTime = aUnloadTime;
    ToReadyTime = aToReadyTime;
    InitialState = Start;
    cmdFromBox = -1;  // Initial value

    CreateStateNameArray(10);  // So the audit trail will have
        // state names
    CreateGlobal(5);  // Create global data bases
    //ActivateProfiling(5.e-6,80.e-6,15,LOG_PROFILE);
    RegisterStateName("Initialize",Initialize);
    RegisterStateName("Start",Start);
    RegisterStateName("PickupAssembly",PickupAssembly);
    RegisterStateName("PlaceAssembly",PlaceAssembly);
    RegisterStateName("GoingToReady",GoingToReady);
    RegisterStateName("AtReady",AtReady);
    }

int CUnloadRobot::Run(void)
    {
    double Time;
    NumScans++; // Increment scan count
    int MsgIndex,FromTask;
    double MsgVal;

    if (State == Initialize)
        {
        // Initialization code.  If there is anything
        // that the task needs to do only once at
        // start-up, put it here.
        State = NextState = InitialState;  // To prevent this from running again
        return (1);
        }
    // Don't bother checking time here -- none of the states of this
    //  task do anything more than check time.
    if (NextState != -1)
        {
        // record audit trail here if desired
        AuditTrail(this, State, NextState);
        State = NextState;
        PrivateGlobalData[UNLOAD_ROBOT_State] = State;
        NextState = -1;
        RunEntry = 1;
        }
    else
        RunEntry = 0;

    switch(State)
        {
        case Start:
            // Entry
            if(RunEntry)
                {
                PrivateGlobalData[UNLOAD_ROBOT_Status] = 0; // Ready
                }
            // Action
            // Test/Exit
            NextState = AtReady;  // Unconditional
            break;
        case AtReady:
            // Entry
            if(RunEntry)
                {
                PrivateGlobalData[UNLOAD_ROBOT_Status] = 0; // Ready
                }
            // Action
            // Test/Exit
            if(GetRTMessage(UNLOAD_ROBOT_CMD_Unload,&MsgIndex,
                        &MsgVal,&FromTask))
                {
                // Unload the assembly from the conveyor
                NextState = PickupAssembly;
                cmdFromTask = FromTask;
                cmdFromBox = MsgIndex;
                }
            break;
        case PickupAssembly:
            // Entry
            if(RunEntry)
                {
                PrivateGlobalData[UNLOAD_ROBOT_Status] = 2;  // Moving
                StartTime = GetTimeNow();
                }
            // Action
            // Test/Exit
            if(GetTimeNow() >= (StartTime + UnloadTime/2.0))
                {
                NextState = PlaceAssembly;
                }
            break;
        case PlaceAssembly:
            // Entry
            if(RunEntry)
                {
                StartTime = GetTimeNow();
                SendCompletionMessage(cmdFromTask,cmdFromBox,1);
                  // Send completion message when robot has grasped
                  //the assembly. This allows overlapped operation.
                }
            // Action
            // Test/Exit
            if(GetTimeNow() >= (StartTime + UnloadTime/2.0))
                {
                NextState = GoingToReady;
                }
            break;
        case GoingToReady:
            // Entry
            if(RunEntry)
                {
                StartTime = GetTimeNow();
                }
            // Action
            // Test/Exit
            if(GetTimeNow() >= (StartTime + ToReadyTime))
                {
                NextState = AtReady;
                }
            break;
        default:
            StopControl("<UnloadRobot> Illegal state");
        }
    PrivateGlobalData[UNLOAD_ROBOT_State] = State;
    CopyGlobal();  // Make global data visible
    return(1);
    }

// Glue Applicator
//States:
#define Initialize 0
#define Start 1
#define MoveToGlueSpot 2
#define GlueApplication 3
#define GoingToReady 4
#define AtReady 5

CGlueApplicator::CGlueApplicator(char *aName,double aGlueTime,
        double aToReadyTime,int ProcNo) :BaseTask(aName,ProcNo)
    {
    GlueTime = aGlueTime;
    ToReadyTime = aToReadyTime;
    InitialState = Start;
    cmdFromBox = -1;  // Initial value

    CreateStateNameArray(10);  // So the audit trail will have
        // state names
    CreateGlobal(5);  // Create global data bases
    //ActivateProfiling(5.e-6,80.e-6,15,LOG_PROFILE);
    RegisterStateName("Initialize",Initialize);
    RegisterStateName("Start",Start);
    RegisterStateName("MoveToGlueSpot",MoveToGlueSpot);
    RegisterStateName("GlueApplication",PlaceAssembly);
    RegisterStateName("GoingToReady",GoingToReady);
    RegisterStateName("AtReady",AtReady);
    }

int CGlueApplicator::Run(void)
    {
    double Time;
    NumScans++; // Increment scan count
    int MsgIndex,FromTask;
    double MsgVal;

    if (State == Initialize)
        {
        // Initialization code.  If there is anything
        // that the task needs to do only once at
        // start-up, put it here.
        State = NextState = InitialState;  // To prevent this from running again
        return (1);
        }
    // Don't bother checking time here -- none of the states of this
    //  task do anything more than check time.
    if (NextState != -1)
        {
        // record audit trail here if desired
        AuditTrail(this, State, NextState);
        State = NextState;
        PrivateGlobalData[GLUE_APPLICATOR_State] = State;
        NextState = -1;
        RunEntry = 1;
        }
    else
        RunEntry = 0;

    switch(State)
        {
        case Start:
            // Entry
            if(RunEntry)
                {
                PrivateGlobalData[GLUE_APPLICATOR_Status] = 0; // Ready
                }
            // Action
            // Test/Exit
            NextState = AtReady;  // Unconditional
            break;
        case AtReady:
            // Entry
            if(RunEntry)
                {
                PrivateGlobalData[GLUE_APPLICATOR_Status] = 0; // Ready
                SendCompletionMessage(cmdFromTask,cmdFromBox,1);
                }
            // Action
            // Test/Exit
            if(GetRTMessage(GLUE_APPLICATOR_CMD_Apply,&MsgIndex,
                        &MsgVal,&FromTask))
                {
                // Unload the assembly from the conveyor
                NextState = MoveToGlueSpot;
                cmdFromTask = FromTask;
                cmdFromBox = MsgIndex;
                }
            break;
        case MoveToGlueSpot:
            // Entry
            if(RunEntry)
                {
                PrivateGlobalData[GLUE_APPLICATOR_Status] = 2;  // Moving
                StartTime = GetTimeNow();
                }
            // Action
            // Test/Exit
            if(GetTimeNow() >= (StartTime + ToReadyTime))
                // Time getting from READY is the same as to READY
                {
                NextState = GlueApplication;
                }
            break;
        case GlueApplication:
            // Entry
            if(RunEntry)
                {
                StartTime = GetTimeNow();
                PrivateGlobalData[GLUE_APPLICATOR_Status] = 1;  // Glueing
                }
            // Action
            // Test/Exit
            if(GetTimeNow() >= (StartTime + GlueTime))
                {
                NextState = GoingToReady;
                }
            break;
        case GoingToReady:
            // Entry
            if(RunEntry)
                {
                StartTime = GetTimeNow();
                PrivateGlobalData[GLUE_APPLICATOR_Status] = 2;  // Moving
                }
            // Action
            // Test/Exit
            if(GetTimeNow() >= (StartTime + ToReadyTime))
                {
                NextState = AtReady;
                }
            break;
        default:
            StopControl("<GlueApplicator> Illegal state");
        }
    PrivateGlobalData[GLUE_APPLICATOR_State] = State;
    CopyGlobal();  // Make global data visible
    return(1);
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -