| ApossC SDK V01.15

CAN_MultipleAx_DS402_ProfilePositionMode-ppm-Test.mc
#include "..\..\..\SDK\SDK_ApossC.mc"
// Set the node ids of the all nodes in the network
long busIds[] = {1, 4};
long numberOfBusIds = arraylen(busIds);
void errorHandler();
void faultMonitoring();
void posAbsStartForAllNodes(long pos);
void posRelStartForAllNodes(long distance);
void verifyAllNodesStateAchieved(long state);
void verfiyAllNodesTargetReached();
long main(void)
{
long handle;
long actState=0;
long idIndex;
//Reset CAN Bus 1
handle = DefCanOut(0, 2);
CanOut(handle, 0, 0x8100);
//Reset CAN Bus 2
handle = DefCanOut(100000, 2);
CanOut(handle, 0, 0x8100);
//Wait until nodes have been resetted
Delay(2000);
ErrorClear();
//set errorHandler for master
InterruptSetup(ERROR, errorHandler);
//Monitior the Fault bit in the status word of the slave, all 25ms
InterruptSetup(PERIOD, faultMonitoring, 25);
//----------------------------------------------------------------
// Application Setup
//----------------------------------------------------------------
for(idIndex = 0; idIndex < numberOfBusIds; idIndex++)
{
//Set the mode of operation to PPM
sdkDS402_SetOpartionMode(busIds[idIndex], DS402_OP_PPM);
actState = sdkDS402_GetActDriveState(busIds[idIndex]);
if(actState == DS402_DRIVE_STATE_SWITCH_ON_DISABLED)
{
sdkDS402_TransitionToState(busIds[idIndex], DS402_DRIVE_STATE_READY_TO_SWITCH_ON);
}
//Set acceleration, deceleration and velocity
sdkDS402_SetProfileMovementParameter(busIds[idIndex], 1000, 1000, 500);
//Set the deccelation for quick stop
sdkDS402_SetQuickStopDeceleration(busIds[idIndex], 5000);
}
verifyAllNodesStateAchieved(DS402_DRIVE_STATE_READY_TO_SWITCH_ON);
//----------------------------------------------------------------
// End of Application Setup
//----------------------------------------------------------------
//Transition to drive state 'Operation enabled'
for(idIndex = 0; idIndex < numberOfBusIds; idIndex++)
{
//Transition to drive state 'Operation enabled'
sdkDS402_TransitionToState(busIds[idIndex], DS402_DRIVE_STATE_OPERATION_ENABLED);
}
verifyAllNodesStateAchieved(DS402_DRIVE_STATE_OPERATION_ENABLED);
while(1)
{
//Start absolute positioning to pos 100000 qc
posAbsStartForAllNodes(100000);
//Wait until the target position has been reached
verfiyAllNodesTargetReached();
//Start relative positioning of -100000 qc
posRelStartForAllNodes(-100000);
//Wait until the target position has been reached
verfiyAllNodesTargetReached();
}
return(1);
}
void posAbsStartForAllNodes(long pos)
{
long idIndex;
for(idIndex = 0; idIndex < numberOfBusIds; idIndex++)
{
//Start absolute positioning
sdkDS402_PPM_PosAbsStart(busIds[idIndex], pos, DS402_PPM_IMMEDIATELY);
}
}
void posRelStartForAllNodes(long distance)
{
long idIndex;
for(idIndex = 0; idIndex < numberOfBusIds; idIndex++)
{
//Start relative positioning of distance
sdkDS402_PPM_PosRelStart(busIds[idIndex], distance, DS402_PPM_IMMEDIATELY);
}
}
void verifyAllNodesStateAchieved(long state)
{
long idIndex;
long actState;
long result;
while(result != 1)
{
result = 1;
for(idIndex = 0; idIndex < numberOfBusIds; idIndex++)
{
actState = sdkDS402_GetActDriveState(busIds[idIndex]);
result = (actState == state) && result;
}
}
}
void verfiyAllNodesTargetReached()
{
long idIndex;
long result;
print("Wait until all nodes target is reached");
while(result != 1)
{
result = 1;
for(idIndex = 0; idIndex < numberOfBusIds; idIndex++)
{
result = sdkDS402_PPM_TargetReached(busIds[idIndex]) && result;
}
}
}
void quickStopAllNodes()
{
long idIndex;
for(idIndex = 0; idIndex < numberOfBusIds; idIndex++)
{
sdkDS402_QuickStop(busIds[idIndex]);
}
}
void faultMonitoring()
{
long idIndex;
for(idIndex = 0; idIndex < numberOfBusIds; idIndex++)
{
long statusWord = sdkDS402_ReadStatusWord(busIds[idIndex]);
if(statusWord.i[DS402_SW_BIT_FAULT])
{
errorHandler();
}
}
}
void errorHandler()
{
long axeNbr = ErrorAxis();
long errNbr = ErrorNo();
long errInfoNbr = ErrorInfo();
long statusWord, idIndex, sdoAbortCode;
//Stop all nodes
quickStopAllNodes();
print("-----------------------------------------------------------");
printf("Error %d: ",errNbr);
sdkErrorPrint_ApossIdeErrorDescription(errNbr);
print();
print("...Info: ",errInfoNbr, " AxisNo: ", axeNbr);
print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
print();
switch(errNbr)
{
case F_CANIO:
printf("SDO Abort Code 0x%lX: ", sdoAbortCode );
sdkErrorPrint_SdoErrorDescription(SYS_PROCESS(SYS_CANOM_SDOABORT));
print();
print("Check Can baudrate & Can bus id");
}
if(axeNbr == 0xFF && errNbr != F_CANIO)
{
//The error is not releated to a certain axis
for(idIndex = 0; idIndex < numberOfBusIds; idIndex++)
{
statusWord = sdkDS402_ReadStatusWord(busIds[idIndex]);
if(statusWord.i[DS402_SW_BIT_FAULT])
{
print();
printf("Bus Id %d, Slave device is in fault state\n", busIds[idIndex]);
if(statusWord.i[DS402_SW_PPM_BIT_FOLLWING_ERROR])
{
print("...Following Error");
}
//Reset the fault
sdkDS402_ResetFault(busIds[idIndex]);
}
}
}
ErrorClear();
print();
print(" There is no error handlig → Exit()");
print("-----------------------------------------------------------");
Exit(0);
}
sdkDS402_ReadStatusWord
long sdkDS402_ReadStatusWord(long busId)
DS 402 State-Machine functions.
Definition: SDK_Amplifier_DS402_StateMachine.mc:33
sdkDS402_ResetFault
void sdkDS402_ResetFault(long busId)
Reset fault.
Definition: SDK_Amplifier_DS402_StateMachine.mc:574
sdkDS402_PPM_PosRelStart
long sdkDS402_PPM_PosRelStart(long busId, long pos, long startImmediately)
Start relative positioning.
Definition: SDK_Amplifier_DS402_StateMachine.mc:819
DS402_DRIVE_STATE_SWITCH_ON_DISABLED
#define DS402_DRIVE_STATE_SWITCH_ON_DISABLED
Definition: SDK_Amplifier_DS402_StateMachine.mh:61
sdkDS402_GetActDriveState
long sdkDS402_GetActDriveState(long busId)
Get the actual drive state.
Definition: SDK_Amplifier_DS402_StateMachine.mc:83
SYS_CANOM_SDOABORT
#define SYS_CANOM_SDOABORT
Last CANopen SDO abort code.
Definition: SdoDictionary.mh:491
sdkDS402_TransitionToState
long sdkDS402_TransitionToState(long busId, long newState)
Transition to another state.
Definition: SDK_Amplifier_DS402_StateMachine.mc:230
sdkErrorPrint_SdoErrorDescription
void sdkErrorPrint_SdoErrorDescription(long errorCode)
Prints a error description for SDO abort codes.
Definition: SDK_Error_Description.mc:290
sdkDS402_SetProfileMovementParameter
void sdkDS402_SetProfileMovementParameter(long busId, long acc, long dec, long velocity)
Set quick stop deceleration DS402_QUICK_STOP_DECELERATION(0x6085)
Definition: SDK_Amplifier_DS402_StateMachine.mc:488
sdkDS402_SetQuickStopDeceleration
void sdkDS402_SetQuickStopDeceleration(long busId, long dec)
Set quick stop deceleration DS402_QUICK_STOP_DECELERATION(0x6085)
Definition: SDK_Amplifier_DS402_StateMachine.mc:476
DS402_PPM_IMMEDIATELY
#define DS402_PPM_IMMEDIATELY
Definition: SDK_Amplifier_DS402_StateMachine.mh:192
DS402_SW_BIT_FAULT
#define DS402_SW_BIT_FAULT
Definition: SDK_Amplifier_DS402_StateMachine.mh:100
DS402_OP_PPM
#define DS402_OP_PPM
Definition: SDK_Amplifier_DS402_StateMachine.mh:120
sdkDS402_PPM_PosAbsStart
long sdkDS402_PPM_PosAbsStart(long busId, long pos, long startImmediately)
Start absolute positioning.
Definition: SDK_Amplifier_DS402_StateMachine.mc:797
SYS_PROCESS
#define SYS_PROCESS(parno)
System Process Data: Setter.
Definition: SdoDictionary.mh:271
DS402_DRIVE_STATE_OPERATION_ENABLED
#define DS402_DRIVE_STATE_OPERATION_ENABLED
Definition: SDK_Amplifier_DS402_StateMachine.mh:64
DS402_DRIVE_STATE_READY_TO_SWITCH_ON
#define DS402_DRIVE_STATE_READY_TO_SWITCH_ON
Definition: SDK_Amplifier_DS402_StateMachine.mh:62
DS402_SW_PPM_BIT_FOLLWING_ERROR
#define DS402_SW_PPM_BIT_FOLLWING_ERROR
Definition: SDK_Amplifier_DS402_StateMachine.mh:111
sdkDS402_PPM_TargetReached
long sdkDS402_PPM_TargetReached(long busId)
Checks whether the target was reached.
Definition: SDK_Amplifier_DS402_StateMachine.mc:836
sdkDS402_QuickStop
void sdkDS402_QuickStop(long busId)
Execute quick stop.
Definition: SDK_Amplifier_DS402_StateMachine.mc:544
sdkErrorPrint_ApossIdeErrorDescription
void sdkErrorPrint_ApossIdeErrorDescription(long errorCode)
Prints a error description for ApossIDE errors.
Definition: SDK_Error_Description.mc:25
sdkDS402_SetOpartionMode
void sdkDS402_SetOpartionMode(long busId, long operationMode)
Profile Mode functions.
Definition: SDK_Amplifier_DS402_StateMachine.mc:508

Data Sheets | Released Software | Software Manuals | Hardware Manuals | Maxon Shop

Maxon Support Center