#include "..\..\..\SDK\SDK_ApossC.mc"
#define C_AXIS1 0 // Axis module number
#define C_AXIS2 1 // Axis module number
#define C_AXIS3 2 // Axis module number
#define C_AXIS1_POLARITY 0 // Definition of the polarity 0: Normal, 1: Inverse
#define C_AXIS2_POLARITY 0 // Definition of the polarity 0: Normal, 1: Inverse
#define C_AXIS3_POLARITY 0 // Definition of the polarity 0: Normal, 1: Inverse
#define C_DRIVE_BUSID1 1000001 // The driveBusId is 1000000 plus the EtherCAT slave position in the bus
#define C_DRIVE_BUSID2 1000002 // The driveBusId is 1000000 plus the EtherCAT slave position in the bus
#define C_DRIVE_BUSID3 1000003 // The driveBusId is 1000000 plus the EtherCAT slave position in the bus
#define C_EC_CYCLE_TIME 1 // Cycletime in milliseconds
#define C_EC_OFFSET 1 // Shift offset
#define C_PDO_NUMBER 1 // Used PDO number
#define C_AXIS_ENCRES 4*1600 // Resolution of the encoder for position feed back in increments (quadcounts)
#define C_AXIS_POSENCREV 1 // Number of revolutions of the motor
#define C_AXIS_POSENCQC C_AXIS_ENCRES // Number of quadcounts in POSENCREV revolutions
#define C_AXIS_POSFACT_Z 1 // Number of revolutions of the input shaft
#define C_AXIS_POSFACT_N 1 // Number of revolutions of the output shaft in POSFACT_Z revolutions of the input shaft
#define C_AXIS_FEEDREV 1 // Number of revolutions of the gear box output shaft
#define C_AXIS_FEEDDIST C_AXIS_ENCRES // Distance travelled (in user units) in FEEDREV revolutions of the gear box output shaft [mm]
#define C_AXIS_MAX_RPM 2000 // Maximum velocity in RPM
#define C_AXIS_VELRES 100 // Velocity resolution, Scaling used for the velocity and acceleration/deceleration commands, default
#define C_AXIS_RAMPTYPE RAMPTYPE_JERKLIMITED // Defines the ramptype
#define C_AXIS_RAMPMIN 800 // Maximum acceleration
#define C_AXIS_JERKMIN 1000 // Minimum time (ms) required before reaching the maximum acceleration
#define C_AXIS_TRACKERR 0 // There is also a following error on EPOS4, could be set to zero on the MACS
#define C_AXIS_KPROP 0
#define C_AXIS_KINT 0
#define C_AXIS_KDER 0
#define C_AXIS_KILIM 0
#define C_AXIS_KILIMTIME 0
#define C_AXIS_BANDWIDTH 1000
#define C_AXIS_FFVEL 1000
#define C_AXIS_KFFAC 0
#define C_AXIS_KFFDEC 0
long axis[] = {C_AXIS1, C_AXIS2, C_AXIS3};
long busIds[] = {C_DRIVE_BUSID1, C_DRIVE_BUSID2, C_DRIVE_BUSID3};
long numberOfAxis = arraylen(busIds);
long main(void) {
long slaveCount, i,retval, axisIndex;
long homingStateAx_0=0,homingStateAx_1=0,homingStateAx_2=0;
print("-----------------------------------------------------------");
print(" Test application EtherCAT Master with 3 EPOS4 drive");
print("-----------------------------------------------------------");
ErrorClear();
AmpErrorClear(C_AXIS1);
AmpErrorClear(C_AXIS2);
AmpErrorClear(C_AXIS3);
InterruptSetup(ERROR, ErrorHandler);
ECatMasterCommand(0x1000, 0);
print("slavecount: ",slaveCount);
for (i = 1; i <= 3; i++) {
}
for(axisIndex = 0; axisIndex < numberOfAxis; axisIndex++ )
{
C_AXIS_VELRES,
C_AXIS_MAX_RPM,
C_AXIS_RAMPTYPE,
C_AXIS_RAMPMIN,
C_AXIS_JERKMIN,
C_AXIS_TRACKERR
);
C_AXIS_POSENCREV,
C_AXIS_POSENCQC,
C_AXIS_POSFACT_Z,
C_AXIS_POSFACT_N,
C_AXIS_FEEDREV,
C_AXIS_FEEDDIST
);
C_AXIS_KPROP,
C_AXIS_KINT,
C_AXIS_KDER,
C_AXIS_KILIM,
C_AXIS_KILIMTIME,
C_AXIS_BANDWIDTH,
C_AXIS_FFVEL,
C_AXIS_KFFAC,
C_AXIS_KFFDEC
);
}
ErrorClear();
for(axisIndex = 0; axisIndex < numberOfAxis; axisIndex++ )
{
print(
"...: EPOS4 Homing AxisNo: ",axis,
" - Homing methode: ",SdoRead(busIds[axisIndex],
EPOS4_HOMING_METHOD,0));
}
retval=0;
while(retval!=7)
{
}
AxisControl(C_AXIS1,ON, C_AXIS2,ON, C_AXIS3,ON);
print("-----------------------------------------------------------");
print(" Movement in CSP Mode ");
print("----------------------------------------------------------- \n");
Vel(C_AXIS1, 40, C_AXIS2, 40, C_AXIS3, 40);
Acc(C_AXIS1, 30, C_AXIS2, 30, C_AXIS3, 30);
Dec(C_AXIS1, 30, C_AXIS2, 30, C_AXIS3, 30);
for(i=10;i>=0;i--)
{
print("Start, move to target position");
AxisPosAbsStart( C_AXIS1, 20000 , C_AXIS2, 20000, C_AXIS3, 20000 );
AxisWaitReached(C_AXIS1,C_AXIS2,C_AXIS3);
print("Target position is reached \n");
print("Start, back to start position");
AxisPosAbsStart( C_AXIS1, 0, C_AXIS2, 0, C_AXIS3, 0);
AxisWaitReached(C_AXIS1,C_AXIS2,C_AXIS3);
print("Start position is reached");
print(i, " repetitions to go \n");
}
AxisControl(AXALL, OFF);
RecordStop(0, 0);
print("Program done, Axis OFF ");
return(0);
}
void ErrorHandler(void)
{
long axeNbr = ErrorAxis();
long errNbr = ErrorNo();
long errInfoNbr = ErrorInfo();
long sdoAbortCode, eposErr;
AxisControl(AXALL,OFF);
switch(errNbr)
{
printf("Error Axis: %d, Epos4 Error 0x%lX: ", axeNbr , eposErr);
print();
AmpErrorClear(axeNbr);
break;
case F_CANIO: print("ErrorNo: ",errNbr," SlaveAddr(info): ",errInfoNbr);
ECatMasterInfo(0x1000, 22, sdoAbortCode);
printf("SDO Abort Code EtherCAT 0x%lX\n", sdoAbortCode);
break;
default: print("ErrorNo: ",errNbr," info: ",errInfoNbr, " AxisNo: ", axeNbr);
}
ErrorClear();
print(""); print(" There is no error handlig → Exit()");
Exit(0);
}