| ApossC SDK V01.15

CAN_1Ax_DS402_ProfileVelocityMode-pvm-Test.mc
#include "..\..\..\SDK\SDK_ApossC.mc"
// Bus settings
#define SLAVE_CAN_BUSID 1
long waitTransitionToState(long busId, long targetState, long timeout);
void errorHandler();
void faultMonitoring();
long main(void)
{
long handle, i;
long actState=0;
//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 the node has 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
//----------------------------------------------------------------
//Set the mode of operation to PVM
sdkDS402_SetOpartionMode(SLAVE_CAN_BUSID, DS402_OP_PVM);
//Get the actual DS402 state machnie state, and set it
actState = sdkDS402_GetActDriveState(SLAVE_CAN_BUSID);
if(actState == DS402_DRIVE_STATE_SWITCH_ON_DISABLED)
{
//change the state to 'Ready to switch on', and verify the the state was achieved with infinite timeout (-1)
sdkDS402_WaitTransitionToState(SLAVE_CAN_BUSID, DS402_DRIVE_STATE_READY_TO_SWITCH_ON, -1);
}
//Set acceleration, deceleration
sdkDS402_SetProfileAcceleration(SLAVE_CAN_BUSID, 2000);
sdkDS402_SetProfileDeceleration(SLAVE_CAN_BUSID, 2000);
//Set the deccelation for quick stop
sdkDS402_SetQuickStopDeceleration(SLAVE_CAN_BUSID, 5000);
//----------------------------------------------------------------
// End of Application Setup
//----------------------------------------------------------------
//Transition to drive state 'Operation enabled'
sdkDS402_WaitTransitionToState(SLAVE_CAN_BUSID, DS402_DRIVE_STATE_OPERATION_ENABLED, -1);
sdkDS402_Print_StatusWord(SLAVE_CAN_BUSID);
Delay(1000);
for(i = 0; i < 2; i++)
{
//Set target velocity to 200rpm
sdkDS402_PVM_SetTargetVelocity(SLAVE_CAN_BUSID, 200);
//Start continuous velocity movment
sdkDS402_PVM_CvelStart(SLAVE_CAN_BUSID);
//Wait until target velocity is reached
sdkDS402_PVM_WaitTargetReached(SLAVE_CAN_BUSID, -1);
Delay(1500);
//Set target velocity to 200rpm
sdkDS402_PVM_SetTargetVelocity(SLAVE_CAN_BUSID, 100);
//Start continuous velocity movment
sdkDS402_PVM_CvelStart(SLAVE_CAN_BUSID);
//Wait until target velocity is reached
sdkDS402_PVM_WaitTargetReached(SLAVE_CAN_BUSID, -1);
Delay(1500);
//Stop
sdkDS402_Halt(SLAVE_CAN_BUSID);
Delay(500);
//Set target velocity to 500rpm
sdkDS402_PVM_SetTargetVelocity(SLAVE_CAN_BUSID, 500);
//Start continuous velocity movment
sdkDS402_PVM_CvelStart(SLAVE_CAN_BUSID);
//Wait until target velocity is reached
sdkDS402_PVM_WaitTargetReached(SLAVE_CAN_BUSID, -1);
Delay(1500);
//Stop continuous velocity movment
sdkDS402_PVM_CvelStop(SLAVE_CAN_BUSID);
Delay(500);
}
//Set target velocity to 1000rpm
sdkDS402_PVM_SetTargetVelocity(SLAVE_CAN_BUSID, 1000);
//Start continuous velocity movment
sdkDS402_PVM_CvelStart(SLAVE_CAN_BUSID);
//Wait until target velocity is reached
sdkDS402_PVM_WaitTargetReached(SLAVE_CAN_BUSID, -1);
Delay(2000);
//Quick Stop
sdkDS402_QuickStop(SLAVE_CAN_BUSID);
return(1);
}
void faultMonitoring()
{
long statusWord = sdkDS402_ReadStatusWord(SLAVE_CAN_BUSID);
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
sdkDS402_QuickStop(SLAVE_CAN_BUSID);
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
statusWord = sdkDS402_ReadStatusWord(SLAVE_CAN_BUSID);
if(statusWord.i[DS402_SW_BIT_FAULT])
{
print();
printf("Bus Id %d, Slave device is in fault state\n", SLAVE_CAN_BUSID);
if(statusWord.i[DS402_SW_PPM_BIT_FOLLWING_ERROR])
{
print("...Following Error");
}
//Reset the fault
sdkDS402_ResetFault(SLAVE_CAN_BUSID);
}
}
ErrorClear();
print();
print(" There is no error handlig → Exit()");
print("-----------------------------------------------------------");
Exit(0);
}
sdkDS402_Print_StatusWord
void sdkDS402_Print_StatusWord(long busId)
Print the status word.
Definition: SDK_Amplifier_DS402_StateMachine.mc:588
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
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
sdkErrorPrint_SdoErrorDescription
void sdkErrorPrint_SdoErrorDescription(long errorCode)
Prints a error description for SDO abort codes.
Definition: SDK_Error_Description.mc:290
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
sdkDS402_Halt
void sdkDS402_Halt(long busId)
Stop the motor.
Definition: SDK_Amplifier_DS402_StateMachine.mc:557
DS402_SW_BIT_FAULT
#define DS402_SW_BIT_FAULT
Definition: SDK_Amplifier_DS402_StateMachine.mh:100
sdkDS402_PVM_WaitTargetReached
long sdkDS402_PVM_WaitTargetReached(long busId, long timeout)
Wait until target is reachd.
Definition: SDK_Amplifier_DS402_StateMachine.mc:976
sdkDS402_PVM_CvelStart
long sdkDS402_PVM_CvelStart(long busId)
Start continuous velocity (PVM)
Definition: SDK_Amplifier_DS402_StateMachine.mc:904
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
sdkDS402_SetProfileDeceleration
void sdkDS402_SetProfileDeceleration(long busId, long dec)
Set the profile deceleration DS402_PROFILE_DECELERATION(0x6084)
Definition: SDK_Amplifier_DS402_StateMachine.mc:401
sdkDS402_SetProfileAcceleration
void sdkDS402_SetProfileAcceleration(long busId, long acc)
Profile Mode settings.
Definition: SDK_Amplifier_DS402_StateMachine.mc:389
DS402_SW_PPM_BIT_FOLLWING_ERROR
#define DS402_SW_PPM_BIT_FOLLWING_ERROR
Definition: SDK_Amplifier_DS402_StateMachine.mh:111
sdkDS402_QuickStop
void sdkDS402_QuickStop(long busId)
Execute quick stop.
Definition: SDK_Amplifier_DS402_StateMachine.mc:544
DS402_OP_PVM
#define DS402_OP_PVM
Definition: SDK_Amplifier_DS402_StateMachine.mh:121
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
sdkDS402_WaitTransitionToState
long sdkDS402_WaitTransitionToState(long busId, long targetState, long timeout)
Wait transition to another state.
Definition: SDK_Amplifier_DS402_StateMachine.mc:347
sdkDS402_PVM_SetTargetVelocity
void sdkDS402_PVM_SetTargetVelocity(long busId, long targetVelocity)
Profile Velocity Mode functions.
Definition: SDK_Amplifier_DS402_StateMachine.mc:888
sdkDS402_PVM_CvelStop
long sdkDS402_PVM_CvelStop(long busId)
Stop continuous velocity (PVM)
Definition: SDK_Amplifier_DS402_StateMachine.mc:935

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

Maxon Support Center