#include "..\..\..\SDK\SDK_ApossC.mc"
#define M_AX_0 0 // Axis module number - DS402 Master
#define M_AX_1 1 // Axis module number - DS402 Master
#define M_AX_2 2 // Axis module number - DS402 Master
#define M_AX_3 3 // Axis module number - DS402 Master
#define S_AX_0 0 // Axis module number - DS402 Slave
#define S_AX_1 1 // Axis module number - DS402 Slave
#define S_AX_2 2 // Axis module number - DS402 Slave
#define S_AX_3 3 // Axis module number - DS402 Slave
#define DRIVE_BUSID1 3 // The CAN drive busId of the MiniMACS6
#define PDO_S_AX_0 1 // Used PDO number
#define PDO_S_AX_1 2 // Used PDO number
#define PDO_S_AX_2 3 // Used PDO number
#define PDO_S_AX_3 4 // Used PDO number
#define AXIS_ENCRES 4*256 // Resolution of the encoder for position feed back in increments (quadcounts)
#define AXIS_POSENCREV 1 // Number of revolutions of the motor
#define AXIS_POSENCQC AXIS_ENCRES // Number of quadcounts in POSENCREV revolutions
#define AXIS_POSFACT_Z 1 // Number of revolutions of the input shaft
#define AXIS_POSFACT_N 1 // Number of revolutions of the output shaft in POSFACT_Z revolutions of the input shaft
#define AXIS_FEEDREV 1 // Number of revolutions of the gear box output shaft
#define AXIS_FEEDDIST 360 // Distance travelled (in user units) in FEEDREV revolutions of the gear box output shaft [mm]
#define AXIS_MAX_RPM 5500 // Maximum velocity in RPM
#define AXIS_VELRES 100 // Velocity resolution, Scaling used for the velocity and acceleration/deceleration commands, default
#define AXIS_RAMPTYPE RAMPTYPE_JERKLIMITED // Defines the ramptype
#define AXIS_RAMPMIN 20000 // Maximum acceleration
#define AXIS_JERKMIN 1000 // Minimum time (ms) required before reaching the maximum acceleration
#define AXIS_TRACKERR 0 // There is also a following error on DS402 Slave, could be very high ond the MACS
#define SLAVE_TORQUE_CONST 15700 // Represents the motor’s torque constant uNm/A
#define SLAVE_MOT_RATED_TORQUE 135 // Motor rated torque mNm
#define AXIS_KPROP 0
#define AXIS_KINT 0
#define AXIS_KDER 0
#define AXIS_KILIM 0
#define AXIS_KILIMTIME 0
#define AXIS_BANDWIDTH 1000
#define AXIS_FFVEL 1000
#define AXIS_KFFAC 0
#define AXIS_KFFDEC 0
#define DS402_AXESOFFSET 0x800
long main(void) {
long i, retval;
long homingStateAx_0=0,homingStateAx_1=0,homingStateAx_2=0,homingStateAx_3=0;
print("-------------------------------------------------------------------------");
print(" Test application CANopen Master - MiniMACS6 DS402 Slave");
print("-------------------------------------------------------------------------");
ErrorClear();
AmpErrorClear(AXALL);
InterruptSetup(ERROR, ErrorHandler);
{
print("New Baudrate: 1MBaud");
CanOpenRestart();
Delay(500);
}
for (i = M_AX_0; i <= M_AX_3; i++)
{
AXIS_VELRES,
AXIS_MAX_RPM,
AXIS_RAMPTYPE,
AXIS_RAMPMIN,
AXIS_JERKMIN,
AXIS_TRACKERR
);
AXIS_POSENCREV,
AXIS_POSENCQC,
AXIS_POSFACT_Z,
AXIS_POSFACT_N,
AXIS_FEEDREV,
AXIS_FEEDDIST
);
AXIS_KPROP,
AXIS_KINT,
AXIS_KDER,
AXIS_KILIM,
AXIS_KILIMTIME,
AXIS_BANDWIDTH,
AXIS_FFVEL,
AXIS_KFFAC,
AXIS_KFFDEC
);
SdoWrite( DRIVE_BUSID1, 0x6076 + DS402_AXESOFFSET*i, 00, SLAVE_MOT_RATED_TORQUE);
print("Setup axis parameter: ", i);
}
print("\nDS402 MiniMACS6 Homing:");
for (i = M_AX_0; i <= M_AX_3; i++)
{
SdoWrite( DRIVE_BUSID1, 0x6098 + DS402_AXESOFFSET*i, 0, 37);
SdoWrite( DRIVE_BUSID1, 0x607C + DS402_AXESOFFSET*i, 0, 0);
}
retval=0;
while(retval!=0x0F)
{
}
print("");
print("-----------------------------------------------------------");
print(" Set torque in CST Mode ");
print("----------------------------------------------------------- \n");
AxisControl(M_AX_0, ON,M_AX_1, ON,M_AX_2, ON,M_AX_3, ON);
for(i=10;i>=0;i--)
{
print("Set target torque → positive");
Delay(4000);
print("Set target torque → negative");
Delay(4000);
print("Set target torque → zero");
Delay(2000);
print(i, " repetitions to go \n");
}
AxisControl(M_AX_0, OFF);
AxisControl(M_AX_0, ON,M_AX_1, ON,M_AX_2, ON,M_AX_3, ON);
print("Drive Ready");
while(1)
{
print("Start, move to target position - 10 revolutions");
AxisPosAbsStart( M_AX_0, 10*AXIS_FEEDDIST,
M_AX_1, 10*AXIS_FEEDDIST,
M_AX_2, 10*AXIS_FEEDDIST,
M_AX_3, 10*AXIS_FEEDDIST);
AxisWaitReached(M_AX_0,M_AX_1,M_AX_2,M_AX_3);
print("Target position is reached \n");
print("Start, back to start position");
AxisPosAbsStart( M_AX_0, 0,
M_AX_1, 0,
M_AX_2, 0,
M_AX_3, 0);
AxisWaitReached(M_AX_0,M_AX_1,M_AX_2,M_AX_3);
print("Start position is reached");
print(i-1, " repetitions to go \n");
}
print("Program done, Axis OFF ");
AxisControl(AXALL, OFF);
return(0);
}
void ErrorHandler(void)
{
long axeNbr = ErrorAxis();
long errNbr = ErrorNo();
long errInfoNbr = ErrorInfo();
AxisControl(AXALL,OFF);
switch(errNbr)
{
case F_AMP: if( axeNbr==M_AX_0 ||axeNbr==M_AX_1 || axeNbr==M_AX_2 || axeNbr==M_AX_3 )
{
print("DS402 Slave Error");
print("Error Axis: ", axeNbr ," ErrorCode: 0x", radixstr(SdoRead(DRIVE_BUSID1,0x603F,0x00),16));
Delay(5000);
AmpErrorClear(axeNbr);
}
else
{
print("ErrorNo: ",errNbr," info: ",errInfoNbr, " AxisNo: ", axeNbr);
}
break;
case F_CANIO: print("ErrorNo: ",errNbr," info: ",errInfoNbr);
print("Check Can baudrate & Can bus id");
break;
default: print("ErrorNo: ",errNbr," info: ",errInfoNbr, " AxisNo: ", axeNbr);
}
ErrorClear();
print(""); print(" There is no error handlig → Exit()");
Exit(0);
}