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

📄 boss_plc.c

📁 CNC 的开放码,EMC2 V2.2.8版
💻 C
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************** * * Copyright (C) 2007 Peter G. Vavaroutsos <pete AT vavaroutsos DOT com> * * $RCSfile: boss_plc.c,v $ * $Author: petev $ * $Locker:  $ * $Revision: 1.12 $ * $State: Exp $ * $Date: 2007/06/27 07:12:44 $ * * This module is a hard coded PLC for use on a Bridgeport Boss. * * Installation of the component (realtime only): * * insmod boss_plc count=<1> * * * The following items are exported to the HAL. <id> is * the component id number and is formated as "%d". * *  Parameters: *        u32       boss_plc.<id>.amp-ready-delay *        u32       boss_plc.<id>.brake-on-delay *        u32       boss_plc.<id>.brake-off-delay *        u32       boss_plc.<id>.spindle-lo-to-hi *        float     boss_plc.<id>.jog-scale-0 *        float     boss_plc.<id>.jog-scale-1 *        float     boss_plc.<id>.jog-scale-2 * *  Pins: *        bit       boss_plc.<id>.cycle-start-in *        bit       boss_plc.<id>.cycle-hold-in *        bit       boss_plc.<id>.feed-hold-out *        float     boss_plc.<id>.adaptive-feed-in *        float     boss_plc.<id>.adaptive-feed-out *        bit       boss_plc.<id>.tool-change-in *        bit       boss_plc.<id>.tool-changed-out *        bit       boss_plc.<id>.wait-user-out *        bit       boss_plc.<id>.mist-on-in *        bit       boss_plc.<id>.mist-on-out *        bit       boss_plc.<id>.flood-on-in *        bit       boss_plc.<id>.flood-on-out * *        bit       boss_plc.<id>.limit-override-in *        bit       boss_plc.<id>.limit-active-out *        float     boss_plc.<id>.x-position-in *        bit       boss_plc.<id>.x-jog-en-in *        bit       boss_plc.<id>.x-limit-in *        bit       boss_plc.<id>.x-limit-pos-out *        bit       boss_plc.<id>.x-limit-neg-out *        float     boss_plc.<id>.y-position-in *        bit       boss_plc.<id>.y-jog-en-in *        bit       boss_plc.<id>.y-limit-in *        bit       boss_plc.<id>.y-limit-pos-out *        bit       boss_plc.<id>.y-limit-neg-out *        bit       boss_plc.<id>.z-jog-en-in *        bit       boss_plc.<id>.z-limit-pos-in *        bit       boss_plc.<id>.z-limit-neg-in *        bit       boss_plc.<id>.z-limit-pos-out *        bit       boss_plc.<id>.z-limit-neg-out * *        bit       boss_plc.<id>.x-amp-enable-in *        bit       boss_plc.<id>.x-amp-ready-in *        bit       boss_plc.<id>.x-amp-fault-out *        bit       boss_plc.<id>.y-amp-enable-in *        bit       boss_plc.<id>.y-amp-ready-in *        bit       boss_plc.<id>.y-amp-fault-out *        bit       boss_plc.<id>.z-amp-enable-in *        bit       boss_plc.<id>.z-amp-ready-in *        bit       boss_plc.<id>.z-amp-fault-out *        bit       boss_plc.<id>.a-amp-enable-in *        bit       boss_plc.<id>.a-amp-ready-in *        bit       boss_plc.<id>.a-amp-fault-out * *        float     boss_plc.<id>.spindle-speed-in *        bit       boss_plc.<id>.spindle-is-on-in *        bit       boss_plc.<id>.spindle-fwd-out *        bit       boss_plc.<id>.spindle-rev-out *        bit       boss_plc.<id>.spindle-inc-in *        bit       boss_plc.<id>.spindle-dec-in *        bit       boss_plc.<id>.spindle-inc-out *        bit       boss_plc.<id>.spindle-dec-out *        bit       boss_plc.<id>.brake-en-in *        bit       boss_plc.<id>.brake-en-out * *        bit       boss_plc.<id>.jog-sel-in-0 *        bit       boss_plc.<id>.jog-sel-in-1 *        bit       boss_plc.<id>.jog-sel-in-2 *        bit       boss_plc.<id>.jog-scale-out * *   Functions: *        void      boss_plc.<id>.refresh * ****************************************************************************** * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General * Public License as published by the Free Software Foundation. * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111 USA * * THE AUTHORS OF THIS LIBRARY ACCEPT ABSOLUTELY NO LIABILITY FOR * ANY HARM OR LOSS RESULTING FROM ITS USE.  IT IS _EXTREMELY_ UNWISE * TO RELY ON SOFTWARE ALONE FOR SAFETY.  Any machinery capable of * harming persons must have provisions for completely removing power * from all motors, etc, before persons enter any danger area.  All * machinery must be designed to comply with local and national safety * codes, and the authors of this software can not, and do not, take * any responsibility for such compliance. * * This code was written as part of the EMC HAL project.  For more * information, go to www.linuxcnc.org. * ******************************************************************************/#ifndef RTAPI#error This is a realtime component only!#endif#include "rtapi.h"              // RTAPI realtime OS API.#include "rtapi_app.h"          // RTAPI realtime module decls.#include "hal.h"                // HAL public API decls.#define TRUE                    1#define FALSE                   0typedef int                     BOOL;// Module information.MODULE_AUTHOR("Pete Vavaroutsos");MODULE_DESCRIPTION("Bridgeport BOSS PLC for EMC HAL");MODULE_LICENSE("GPL");static unsigned long                    count = 1;RTAPI_MP_LONG(count, "Number of BOSS PLCs to instance");static int                              debug = 0;RTAPI_MP_INT(debug, "Enables optional params");/****************************************************************************** * TIMER OBJECT * * This object implements a timer with mSec resolution. * ******************************************************************************/typedef enum {    TM_ONE_SHOT,    TM_CONTINUOUS,} TimerMode;typedef void                    (*TIMER_ROUTINE)(void *pArgs);typedef struct {    // Private data.    BOOL                        enabled;    hal_u32_t                   nSec;    hal_u32_t                   count;    hal_u32_t                   timeout;    TIMER_ROUTINE               pTimeout;    void                        *pArgs;    TimerMode                   mode;} Timer;static void Timer_Init(Timer *this);static void Timer_Enable(Timer *this, TimerMode mode);static void Timer_Disable(Timer *this);static BOOL Timer_IsEnabled(Timer *this);static void Timer_Update(Timer *this, long period);static void Timer_SetTimeout(Timer *this, hal_u32_t timeout);#if 0static void Timer_SetCallback(Timer *this, TIMER_ROUTINE pCallback, void *pArgs);#endif/****************************************************************************** * LIMIT OBJECT * * This object converts a bi-directional limit switch into to limit signals. * ******************************************************************************/typedef enum {    LS_INIT,    LS_ON_LIMIT,    LS_NO_MOTION,    LS_POS_MOTION,    LS_NEG_MOTION,} LimitState;typedef struct {    // Exported pins.    hal_float_t                 *pPositionIn;    hal_bit_t                   *pJogEnIn;    hal_bit_t                   *pIn;    hal_bit_t                   *pPosOut;    hal_bit_t                   *pNegOut;    // Internal data.    LimitState                  state;    hal_float_t                 position;    hal_bit_t                   limitPos;    hal_bit_t                   limitNeg;} Limit;static int Limit_Export(Limit *this, int compId, int id, char *name, char axis);static void Limit_Init(Limit *this);static BOOL Limit_IsActive(Limit *this);static void Limit_Refresh(Limit *this, hal_bit_t override);/****************************************************************************** * AMP OBJECT * * This object creates the amp fault signal from the enable and ready signal. * ******************************************************************************/typedef struct {    // Exported pins.    hal_bit_t                   *pEnableIn;    hal_bit_t                   *pReadyIn;    hal_bit_t                   *pFaultOut;    // Internal data.    Timer                       timer;    hal_bit_t                   lastEnable;} Amp;static int Amp_Export(Amp *this, int compId, int id, char *name, char axis);static void Amp_Init(Amp *this);static void Amp_Refresh(Amp *this, long period, hal_u32_t readyDelay);/****************************************************************************** * PLC OBJECT * * This object contains all the data for one PLC. A component object is * dynamically allocated in shmem for each PLC during initialization. * ******************************************************************************/#define NUM_JOG_SEL             3#define NUM_AXIS                4static char                     axisNames[NUM_AXIS] = {    'x', 'y', 'z', 'a'};typedef enum {    SS_OFF,    SS_WAIT_BRAKE_OFF,    SS_WAIT_ON,    SS_ON,    SS_WAIT_OFF,    SS_WAIT_BRAKE_ON,} SpindleState;typedef struct {    // Parameters.    hal_u32_t                   ampReadyDelay;    hal_u32_t                   brakeOnDelay;    hal_u32_t                   brakeOffDelay;    hal_float_t                 spindleLoToHi;    hal_float_t                 jogScale[NUM_JOG_SEL];    // Pins.    hal_bit_t                   *pCycleStartIn;    hal_bit_t                   *pCycleHoldIn;    hal_bit_t                   *pFeedHoldOut;    hal_float_t                 *pAdaptiveFeedIn;    hal_float_t                 *pAdaptiveFeedOut;    hal_bit_t                   *pToolChangeIn;    hal_bit_t                   *pToolChangedOut;    hal_bit_t                   *pWaitUserOut;    hal_bit_t                   *pMistOnIn;    hal_bit_t                   *pMistOnOut;    hal_bit_t                   *pFloodOnIn;    hal_bit_t                   *pFloodOnOut;    hal_bit_t                   *pLimitOverrideIn;    hal_bit_t                   *pLimitActiveOut;    Limit                       xLimit;    Limit                       yLimit;    hal_bit_t                   *pZJogEnIn;    hal_bit_t                   *pZLimitPosIn;    hal_bit_t                   *pZLimitNegIn;    hal_bit_t                   *pZLimitPosOut;    hal_bit_t                   *pZLimitNegOut;    Amp                         amps[NUM_AXIS];    hal_float_t                 *pSpindleSpeedIn;    hal_bit_t                   *pSpindleIsOnIn;    hal_bit_t                   *pSpindleFwdOut;    hal_bit_t                   *pSpindleRevOut;    hal_bit_t                   *pSpindleIncIn;    hal_bit_t                   *pSpindleDecIn;    hal_bit_t                   *pSpindleIncOut;    hal_bit_t                   *pSpindleDecOut;    hal_bit_t                   *pBrakeEnIn;    hal_bit_t                   *pBrakeEnOut;    hal_bit_t                   *pJogSelIn[NUM_JOG_SEL];    hal_float_t                 *pJogScaleOut;    // Private data.    SpindleState                spindleState;    Timer                       spindleTimer;    hal_float_t                 lastSpindleSpeed;    hal_bit_t                   lastCycleStart;} Plc;// These methods are used for initialization.static int Plc_Init(Plc *this);static int Plc_Export(Plc *this, int compId, int id);static int Plc_ExportFeed(Plc *this, int compId, int id, char *name);static int Plc_ExportLimits(Plc *this, int compId, int id, char *name);static int Plc_ExportAmps(Plc *this, int compId, int id, char *name);static int Plc_ExportSpindle(Plc *this, int compId, int id, char *name);static int Plc_ExportJog(Plc *this, int compId, int id, char *name);// These methods are exported to the HAL.static void Plc_Refresh(void *this, long period);// Private helper methods.static void Plc_RefreshFeed(Plc *this, long period);static void Plc_RefreshLimits(Plc *this, long period);static void Plc_RefreshAmps(Plc *this, long period);static void Plc_RefreshSpindle(Plc *this, long period);static void Plc_RefreshJog(Plc *this, long period);/****************************************************************************** * COMPONENT OBJECT * * This object contains all the data for this HAL component. * ******************************************************************************/#define MAX_DEVICES             4typedef struct {    int                         id;             // HAL component ID.    Plc                         *plcTable[MAX_DEVICES];} Component;static Component                component;/****************************************************************************** * INIT AND EXIT CODE ******************************************************************************/intrtapi_app_main(void){    int                         i;    Plc                         *pComp;    // Connect to the HAL.    component.id = hal_init("boss_plc");    if (component.id < 0) {        rtapi_print_msg(RTAPI_MSG_ERR, "BOSS_PLC: ERROR: hal_init() failed\n");        return(-1);    }    for(i = 0; i < MAX_DEVICES; i++){        component.plcTable[i] = NULL;    }    if(count > MAX_DEVICES)        count = MAX_DEVICES;    for(i = 0; i < count; i++){        // Allocate memory for device object.        pComp = hal_malloc(sizeof(Plc));        if (pComp == NULL) {            rtapi_print_msg(RTAPI_MSG_ERR, "BOSS_PLC: ERROR: hal_malloc() failed\n");            hal_exit(component.id);            return(-1);        }        // Save pointer to device object.        component.plcTable[i] = pComp;        // Initialize device.        if(Plc_Init(pComp)){            hal_exit(component.id);            return(-1);        }        // Export pins, parameters, and functions.        if(Plc_Export(pComp, component.id, i)){            hal_exit(component.id);            return(-1);        }    }

⌨️ 快捷键说明

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