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

📄 main.cpp

📁 机械手IPC控制器伺服运动程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    stMacParam.dwPPR                     = pchannel->m_ppr; 
	stMacParam.dfPitch                   = 1;
	stMacParam.dfGearRatio               = 1;
	stMacParam.dfHighLimit               = 50000.0;
	stMacParam.dfLowLimit                = -50000.0; 
	stMacParam.dfHighLimitOffset         = 0;
	stMacParam.dfLowLimitOffset          = 0;
//	stMacParam.wPulseMode                = DDA_FMT_PD; 
//	stMacParam.wPulseWidth               = 100; 
//	stMacParam.wCommandMode              = pchannel->m_command;
	stMacParam.wPulseMode                = DDA_FMT_CW; 
	stMacParam.wPulseWidth               = 40; 
	stMacParam.wCommandMode              = 0;

    stMacParam.wPaddle                   = 0; // Reserved
	stMacParam.wOverTravelUpSensorMode   = 1; // +OT:Normal Close
	stMacParam.wOverTravelDownSensorMode = 1; // -OT:Normal Close
// Set Encoder Parameters
	stENCConfig.wType                    = ENC_TYPE_AB;
	stENCConfig.wAInverse                = _NO_;
	stENCConfig.wBInverse                = _NO_;
	stENCConfig.wCInverse                = _NO_;
	stENCConfig.wABSwap                  = _NO_;
	stENCConfig.wInputRate               = 4; // Set Encoder Input Rate : x4
// Set Home Return Parameters
	stHomeConfig.wMode                   = pchannel->m_mode;   
    stHomeConfig.wDirection              = pchannel->m_direction; // 0:+Dir. ,1:-Dir.
 	stHomeConfig.wSensorMode             = 0; // Normal Open
	stHomeConfig.nIndexCount             = pchannel->m_index;  
	stHomeConfig.dfAccTime               = pchannel->m_acc; // ms
	stHomeConfig.dfDecTime               = pchannel->m_dec; // ms
	stHomeConfig.dfHighSpeed             = pchannel->m_highspd; // mm/s
	stHomeConfig.dfLowSpeed              = pchannel->m_lowspd;  // mm/s
	stHomeConfig.dfOffset                = pchannel->m_offset;
//  Data Setting
	MCC_SetMacParam(&stMacParam, 0, 0);      //  mechanism parameters are the same for all axes
	MCC_SetEncoderConfig(&stENCConfig, 0, 0);//  encoder configures are the same for all axes
	MCC_SetHomeConfig(&stHomeConfig, 0, CARD_INDEX);  //  go-home configures are the same for all axes
    unit0=pchannel->m_pitch*pchannel->m_gear/4.0;
    if(pchannel->m_swap==0) unit0a=1;
    else unit0a=-1;
    MXSOT_Plus=pchannel->m_highlimit;
    MXSOT_Minus=pchannel->m_lowlimit;
	MX_AccTime=pchannel->m_highoffset;
    MX_DecTime=pchannel->m_lowoffset;
    ServoLagMX=pchannel->m_gain;
	  }
	}

    if(m_channels.Lookup(1, pchannel)) {
      if(pchannel) {    
// MZ 
// Set Mechanism Parameters
    stMacParam.wPosToEncoderDir          = pchannel->m_pos;
	stMacParam.wRPM                      = pchannel->m_rpm;
    stMacParam.dwPPR                     = pchannel->m_ppr; 
	stMacParam.dfPitch                   = 1;
	stMacParam.dfGearRatio               = 1;
	stMacParam.dfHighLimit               = 50000.0;
	stMacParam.dfLowLimit                = -50000.0; 
	stMacParam.dfHighLimitOffset         = 0;
	stMacParam.dfLowLimitOffset          = 0;
//	stMacParam.wPulseMode                = DDA_FMT_PD; 
//	stMacParam.wPulseWidth               = 100; 
//	stMacParam.wCommandMode              = pchannel->m_command;
	stMacParam.wPulseMode                = DDA_FMT_CW; 
	stMacParam.wPulseWidth               = 40; 
	stMacParam.wCommandMode              = 0;
    stMacParam.wPaddle                   = 0; // Reserved
	stMacParam.wOverTravelUpSensorMode   = 1; // +OT:Normal Close
	stMacParam.wOverTravelDownSensorMode = 1; // -OT:Normal Close
// Set Encoder Parameters
	stENCConfig.wType                    = ENC_TYPE_AB;
	stENCConfig.wAInverse                = _NO_;
	stENCConfig.wBInverse                = _NO_;
	stENCConfig.wCInverse                = _NO_;
	stENCConfig.wABSwap                  = _NO_;
	stENCConfig.wInputRate               = 4; // Set Encoder Input Rate : x4
// Set Home Return Parameters
	stHomeConfig.wMode                   = pchannel->m_mode;   
    stHomeConfig.wDirection              = pchannel->m_direction; // 0:+Dir. ,1:-Dir.
 	stHomeConfig.wSensorMode             = 0; // Normal Open
	stHomeConfig.nIndexCount             = pchannel->m_index;  
	stHomeConfig.dfAccTime               = pchannel->m_acc; // ms
	stHomeConfig.dfDecTime               = pchannel->m_dec; // ms
	stHomeConfig.dfHighSpeed             = pchannel->m_highspd; // mm/s
	stHomeConfig.dfLowSpeed              = pchannel->m_lowspd;  // mm/s
	stHomeConfig.dfOffset                = pchannel->m_offset;
//  Data Setting
	MCC_SetMacParam(&stMacParam, 1, 0);      //  mechanism parameters are the same for all axes
	MCC_SetEncoderConfig(&stENCConfig, 1, 0);//  encoder configures are the same for all axes
	MCC_SetHomeConfig(&stHomeConfig, 1, CARD_INDEX);  //  go-home configures are the same for all axes
    unit1=pchannel->m_pitch*pchannel->m_gear/4.0;
    if(pchannel->m_swap==0) unit1a=1;
    else unit1a=-1;
	MZSOT_Plus=pchannel->m_highlimit;
    MZSOT_Minus=pchannel->m_lowlimit;
	MZ_AccTime=pchannel->m_highoffset;
    MZ_DecTime=pchannel->m_lowoffset;
    ServoLagMZ=pchannel->m_gain;
	  }
	}

    if(m_channels.Lookup(2, pchannel)) {
      if(pchannel) {    
// Y 
// Set Mechanism Parameters
    stMacParam.wPosToEncoderDir          = pchannel->m_pos;
	stMacParam.wRPM                      = pchannel->m_rpm;
    stMacParam.dwPPR                     = pchannel->m_ppr; 
	stMacParam.dfPitch                   = 1;
	stMacParam.dfGearRatio               = 1;
	stMacParam.dfHighLimit               = 50000.0;
	stMacParam.dfLowLimit                = -50000.0; 
	stMacParam.dfHighLimitOffset         = 0;
	stMacParam.dfLowLimitOffset          = 0;
//	stMacParam.wPulseMode                = DDA_FMT_PD; 
//	stMacParam.wPulseWidth               = 100; 
//	stMacParam.wCommandMode              = pchannel->m_command;
	stMacParam.wPulseMode                = DDA_FMT_CW; 
	stMacParam.wPulseWidth               = 40; 
	stMacParam.wCommandMode              = 0;
    stMacParam.wPaddle                   = 0; // Reserved
	stMacParam.wOverTravelUpSensorMode   = 1; // +OT:Normal Close
	stMacParam.wOverTravelDownSensorMode = 1; // -OT:Normal Close
// Set Encoder Parameters
	stENCConfig.wType                    = ENC_TYPE_AB;
	stENCConfig.wAInverse                = _NO_;
	stENCConfig.wBInverse                = _NO_;
	stENCConfig.wCInverse                = _NO_;
	stENCConfig.wABSwap                  = _NO_;
	stENCConfig.wInputRate               = 4; // Set Encoder Input Rate : x4
// Set Home Return Parameters
	stHomeConfig.wMode                   = pchannel->m_mode;   
    stHomeConfig.wDirection              = pchannel->m_direction; // 0:+Dir. ,1:-Dir.
 	stHomeConfig.wSensorMode             = 0; // Normal Open
	stHomeConfig.nIndexCount             = pchannel->m_index;  
	stHomeConfig.dfAccTime               = pchannel->m_acc; // ms
	stHomeConfig.dfDecTime               = pchannel->m_dec; // ms
	stHomeConfig.dfHighSpeed             = pchannel->m_highspd; // mm/s
	stHomeConfig.dfLowSpeed              = pchannel->m_lowspd;  // mm/s
	stHomeConfig.dfOffset                = pchannel->m_offset;
//  Data Setting
	MCC_SetMacParam(&stMacParam, 2, 0);      //  mechanism parameters are the same for all axes
	MCC_SetEncoderConfig(&stENCConfig, 2, 0);//  encoder configures are the same for all axes
	MCC_SetHomeConfig(&stHomeConfig, 2, CARD_INDEX);  //  go-home configures are the same for all axes
    unit2=pchannel->m_pitch*pchannel->m_gear/4.0;
    if(pchannel->m_swap==0) unit2a=1;
    else unit2a=-1;
	YSOT_Plus=pchannel->m_highlimit;
    YSOT_Minus=pchannel->m_lowlimit;
	Y_AccTime=pchannel->m_highoffset;
    Y_DecTime=pchannel->m_lowoffset;
    ServoLagMSY=pchannel->m_gain;
	  }
	}

    if(m_channels.Lookup(3, pchannel)) {
      if(pchannel) {    
// SX
// Set Mechanism Parameters
    stMacParam.wPosToEncoderDir          = pchannel->m_pos;
	stMacParam.wRPM                      = pchannel->m_rpm;
    stMacParam.dwPPR                     = pchannel->m_ppr; 
	stMacParam.dfPitch                   = 1;
	stMacParam.dfGearRatio               = 1;
	stMacParam.dfHighLimit               = 50000.0;
	stMacParam.dfLowLimit                = -50000.0; 
	stMacParam.dfHighLimitOffset         = 0;
	stMacParam.dfLowLimitOffset          = 0;
//	stMacParam.wPulseMode                = DDA_FMT_PD; 
//	stMacParam.wPulseWidth               = 100; 
//	stMacParam.wCommandMode              = pchannel->m_command;
	stMacParam.wPulseMode                = DDA_FMT_CW; 
	stMacParam.wPulseWidth               = 40; 
	stMacParam.wCommandMode              = 0;
    stMacParam.wPaddle                   = 0; // Reserved
	stMacParam.wOverTravelUpSensorMode   = 1; // +OT:Normal Close
	stMacParam.wOverTravelDownSensorMode = 1; // -OT:Normal Close
// Set Encoder Parameters
	stENCConfig.wType                    = ENC_TYPE_AB;
	stENCConfig.wAInverse                = _NO_;
	stENCConfig.wBInverse                = _NO_;
	stENCConfig.wCInverse                = _NO_;
	stENCConfig.wABSwap                  = _NO_;
	stENCConfig.wInputRate               = 4; // Set Encoder Input Rate : x4
// Set Home Return Parameters
	stHomeConfig.wMode                   = pchannel->m_mode;   
    stHomeConfig.wDirection              = pchannel->m_direction; // 0:+Dir. ,1:-Dir.
 	stHomeConfig.wSensorMode             = 0; // Normal Open
	stHomeConfig.nIndexCount             = pchannel->m_index;  
	stHomeConfig.dfAccTime               = pchannel->m_acc; // ms
	stHomeConfig.dfDecTime               = pchannel->m_dec; // ms
	stHomeConfig.dfHighSpeed             = pchannel->m_highspd; // mm/s
	stHomeConfig.dfLowSpeed              = pchannel->m_lowspd;  // mm/s
	stHomeConfig.dfOffset                = pchannel->m_offset;
//  Data Setting
	MCC_SetMacParam(&stMacParam, 3, 0);      //  mechanism parameters are the same for all axes
	MCC_SetEncoderConfig(&stENCConfig, 3, 0);//  encoder configures are the same for all axes
	MCC_SetHomeConfig(&stHomeConfig, 3, CARD_INDEX);  //  go-home configures are the same for all axes
    unit3=pchannel->m_pitch*pchannel->m_gear/4.0;
    if(pchannel->m_swap==0) unit3a=1;
    else unit3a=-1;
	SXSOT_Plus=pchannel->m_highlimit;
    SXSOT_Minus=pchannel->m_lowlimit;
	SX_AccTime=pchannel->m_highoffset;
    SX_DecTime=pchannel->m_lowoffset;
    ServoLagSX=pchannel->m_gain;
	  }
	}

    if(m_channels.Lookup(4, pchannel)) {
      if(pchannel) {    
// SZ
// Set Mechanism Parameters
    stMacParam.wPosToEncoderDir          = pchannel->m_pos;
	stMacParam.wRPM                      = pchannel->m_rpm;
    stMacParam.dwPPR                     = pchannel->m_ppr; 
	stMacParam.dfPitch                   = 1;
	stMacParam.dfGearRatio               = 1;
	stMacParam.dfHighLimit               = 50000.0;
	stMacParam.dfLowLimit                = -50000.0; 
	stMacParam.dfHighLimitOffset         = 0;
	stMacParam.dfLowLimitOffset          = 0;
//	stMacParam.wPulseMode                = DDA_FMT_PD; 
//	stMacParam.wPulseWidth               = 100; 
//	stMacParam.wCommandMode              = pchannel->m_command;
	stMacParam.wPulseMode                = DDA_FMT_CW; 
	stMacParam.wPulseWidth               = 40; 
	stMacParam.wCommandMode              = 0;
    stMacParam.wPaddle                   = 0; // Reserved
	stMacParam.wOverTravelUpSensorMode   = 1; // +OT:Normal Close
	stMacParam.wOverTravelDownSensorMode = 1; // -OT:Normal Close
// Set Encoder Parameters
	stENCConfig.wType                    = ENC_TYPE_AB;
	stENCConfig.wAInverse                = _NO_;
	stENCConfig.wBInverse                = _NO_;
	stENCConfig.wCInverse                = _NO_;
	stENCConfig.wABSwap                  = _NO_;
	stENCConfig.wInputRate               = 4; // Set Encoder Input Rate : x4
// Set Home Return Parameters
	stHomeConfig.wMode                   = pchannel->m_mode;   
    stHomeConfig.wDirection              = pchannel->m_direction; // 0:+Dir. ,1:-Dir.
 	stHomeConfig.wSensorMode             = 0; // Normal Open
	stHomeConfig.nIndexCount             = pchannel->m_index;  
	stHomeConfig.dfAccTime               = pchannel->m_acc; // ms
	stHomeConfig.dfDecTime               = pchannel->m_dec; // ms
	stHomeConfig.dfHighSpeed             = pchannel->m_highspd; // mm/s
	stHomeConfig.dfLowSpeed              = pchannel->m_lowspd;  // mm/s
	stHomeConfig.dfOffset                = pchannel->m_offset;
//  Data Setting
	MCC_SetMacParam(&stMacParam, 4, 0);      //  mechanism parameters are the same for all axes
	MCC_SetEncoderConfig(&stENCConfig, 4, 0);//  encoder configures are the same for all axes
	MCC_SetHomeConfig(&stHomeConfig, 4, CARD_INDEX);  //  go-home configures are the same for all axes
    unit4=pchannel->m_pitch*pchannel->m_gear/4.0;
    if(pchannel->m_swap==0) unit4a=1;
    else unit4a=-1;
	SZSOT_Plus=pchannel->m_highlimit;
    SZSOT_Minus=pchannel->m_lowlimit;
	SZ_AccTime=pchannel->m_highoffset;
    SZ_DecTime=pchannel->m_lowoffset;
    ServoLagSZ=pchannel->m_gain;
	  }
	}

	//  set group parameters
	for (WORD wGroupIndex = 0;wGroupIndex < MAX_GROUP_NUM;wGroupIndex++)	
	stGroupConfig.nGroupUsed[wGroupIndex] = -1;//  disable all groups
//  Group 0 Setting
	stGroupConfig.nGroupUsed[GROUP_INDEX0]              =   0;		  //  enable group 0
	stGroupConfig.stGroupInfo[GROUP_INDEX0].nCardIndex  =   0;//  group 0 uses card 0
	stGroupConfig.stGroupInfo[GROUP_INDEX0].nChannel[0] =   0;		  //  group 0's axis 0 uses card 0's channel 0
	stGroupConfig.stGroupInfo[GROUP_INDEX0].nChannel[1] =  -1;		  //  group 0's axis 1 uses card 0's channel 1
	stGroupConfig.stGroupInfo[GROUP_INDEX0].nChannel[2] =   1;		  //  group 0's axis 1 uses card 0's channel 2
	stGroupConfig.stGroupInfo[GROUP_INDEX0].nChannel[3] =  -1;		  //  -1 means that group 0's axis 3 is disabled	
	stGroupConfig.stGroupInfo[GROUP_INDEX0].nChannel[4] =  -1;		  //  -1 means that group 0's axis 4 is disabled	
	stGroupConfig.stGroupInfo[GROUP_INDEX0].nChannel[5] =  -1;        //  -1 means that group 0's axis 5 is disabled	
	stGroupConfig.nGroupUsed[GROUP_INDEX1]              =   0;		  //  enable group 1
//  Group 1 Setting
	stGroupConfig.stGroupInfo[GROUP_INDEX1].nCardIndex  =   0;//  group 1 uses card 0
	stGroupConfig.stGroupInfo[GROUP_INDEX1].nChannel[0] =   3;		  //  group 1's axis 0 uses card 0's channel 3
	stGroupConfig.stGroupInfo[GROUP_INDEX1].nChannel[1] =  -1;		  //  group 1's axis 1 uses card 0's channel 4
	stGroupConfig.stGroupInfo[GROUP_INDEX1].nChannel[2] =   4;		  //  group 1's axis 0 uses card 0's channel 5
	stGroupConfig.stGroupInfo[GROUP_INDEX1].nChannel[3] =  -1;		  //  -1 means that group 1's axis 3 is disabled	
	stGroupConfig.stGroupInfo[GROUP_INDEX1].nChannel[4] =  -1;		  //  -1 means that group 1's axis 4 is disabled	
	stGroupConfig.stGroupInfo[GROUP_INDEX1].nChannel[5] =  -1;        //  -1 means that group 1's axis 5 is disabled	
	stGroupConfig.nGroupUsed[GROUP_INDEX2]              =   0;		  //  enable group 1
//  Group 2 Setting
	stGroupConfig.stGroupInfo[GROUP_INDEX2].nCardIndex  =   0;//  group 2 uses card 0
	stGroupConfig.stGroupInfo[GROUP_INDEX2].nChannel[0] =  -1;		  //  group 1's axis 0 uses card 0's channel 3
	stGroupConfig.stGroupInfo[GROUP_INDEX2].nChannel[1] =   2;		  //  group 1's axis 1 uses card 0's channel 4
	stGroupConfig.stGroupInfo[GROUP_INDEX2].nChannel[2] =  -1;		  //  group 1's axis 0 uses card 0's channel 5
	stGroupConfig.stGroupInfo[GROUP_INDEX2].nChannel[3] =  -1;		  //  -1 means that group 1's axis 3 is disabled	
	stGroupConfig.stGroupInfo[GROUP_INDEX2].nChannel[4] =  -1;		  //  -1 means that group 1's axis 4 is disabled	
	stGroupConfig.stGroupInfo[GROUP_INDEX2].nChannel[5] =  -1;        //  -1 means that group 1's axis 5 is disabled	
// Group Data Setting
	MCC_SetGroupConfig(&stGroupConfig);	

	//  stCardConfig is used to set card's base address and card style, and set one card's attributes now
	stCardConfig[CARD_INDEX].wCardType    = 1;   //  0 : 4-axis ISA card
	stCardConfig[CARD_INDEX].wCardAddress = BASE_ADDRESS;//  base address, PCI card ignores this setting
	stCardConfig[CARD_INDEX].wIRQ_No      = IRQ_NO;      //  IRQ No., PCI card ignores this setting	
	nRet = MCC_InitSystem(INTERPOLATION_TIME,//  interpolation time interval
						  stCardConfig,
						  1);		         //  only use one card
	MCC_SetIncrease(GROUP_INDEX0); // Use increment coordinate mode
	MCC_SetIncrease(GROUP_INDEX1);
	MCC_SetIncrease(GROUP_INDEX2);
	MCC_EnableBlend(GROUP_INDEX0);
	MCC_EnableBlend(GROUP_INDEX1);
	MCC_EnableBlend(GROUP_INDEX2);
	MCC_SetServoOn(0, CARD_INDEX); // Set Channel 0 Servo On 	
	MCC_SetServoOn(1, CARD_INDEX); // Set Channel 1 Servo On 	
	MCC_SetServoOn(2, CARD_INDEX); // Set Channel 2 Servo On 	
	MCC_SetServoOn(3, CARD_INDEX); // Set Channel 3 Servo On 	
	MCC_SetServoOn(4, CARD_INDEX); // Set Channel 4 Servo On 
//	MCC_SetRIORoutineEx(RIO_ISR_Function, CARD_INDEX);//  link a interrupt service function for remote I/O set 0

⌨️ 快捷键说明

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