This script implements a custom stall detection algorithm. The purpose of using this script is to fully customize the stall detection voltage threshold and time. Furthermore, this script can trigger an emergency stop only for the affected channel, allowing the other channel to continue operating normally. This is useful for applications where the two motors perform separate functions.


Disclaimer


This script is provided as a sample and has not been validated for any specific use.

It is the customer's responsibility to thoroughly test and evaluate the script before using it in any application.

Roboteq does not assume any liability for errors or issues that may arise from its use. Use at your own risk.



The script follows: 


 

'*******************************

'     Custom Stall Detection   

'*******************************

 

'Description:

'-------------

' This script is used to implement a custom stall detection, where the applied 

' Amount of power and time are fully configurable by the user. Additionally, 

' the egergency stop that will be trigger in response to the fault, will be 

' channel specific. 

 

'Disclaimer:

'-------------

' This script is provided as a sample and has not been validated for any specific use.

' It is the customer's responsibility to thoroughly test and evaluate the script before using it in any application.

' Roboteq does not assume any liability for errors or issues that may arise from its use. Use at your own risk.

 

'Use:

'-------------

' The script can be parametrize by setting the STALL_POWER and STALL_TIME parameters.

' If an error is detected, the power to the specific channel will be cut. The channek without error will 

' continue its operation. 

' The firmware implemented stall detection must be disabled, as the script will take over.

' To clear the fault, the controller or the script must be reset and an emergency stop release command (MG)

' Must be given. 

 

 

option explicit

 

#define STALL_TIME 5000     'Time without a feedback counter value change that will trigger the error. Value is expressed in milliseconds (ms).

#define STALL_POWER 100     'Threshold of PWM voltage (motor power parameter) that will trigger the error. 1000 is 100% PWM.

#define CH1 1                'Change to 0 to disable the protection on that channel

#define CH2 1                  'Change to 0 to disable the protection on that channel

#define COUNTER _C           'Use _C for encoder, _CB for brushless and _CSS for SSI

#define STALL_THRESHOLD 10  'the minumum counter counts difference that will be considered stall

 

 

start:

 

dim time as integer   'general time variable

dim time1 as integer  'variable to measure the stall time for channel 1 

dim time2 as integer  'variable to measure the stall time for channel 1 

dim counter1[2as integer 'array to store the channel 1 counter values

dim counter2[2as integer 'array to store the channel 1 counter values

 

time 0

time1 0

time2 0

counter1[0] = 0

counter1[1] = 0

counter2[0] = 0

counter2[1] = 0

 

if time 'check the counter value every 10 samples to allow for some movement 

    

        counter1[0] = getvalue(COUNTER,1'get current counter value

        counter2[0] = getvalue(COUNTER,2'get current counter value

        time 'max value is 9 where the second sample will be taken.

        

end if

 

 

if CH1 'Channel 1 check

    

        if ((getvalue(_P,1) >= STALL_POWERand (abs(counter1[0] - counter1[1]) >= STALL_THRESHOLD)) 'Stall condition. voltage > threshold1 and time > threshold2

        

            time1++ 'increase the stall timer.

            

        else

        

            time1 'if motor is moving, reset the timer.

            

        end if    

        

        if time1 STALL_TIME 'The stall persists for more than the defined time 

        

            setcommand(_EX,2'Trigger Emergency stop to channel 1

                

        end if

 

end if

 

 

if CH2 'Channel 2 check

    

        if ((getvalue(_P,2) >= STALL_POWERand (abs(counter2[0] - counter2[1]) >= STALL_THRESHOLD)) 'Stall condition. voltage > threshold1 and time > threshold2

        

            time2++ 'increase the stall timer.

            

        else

        

            time2 'if motor is moving, reset the timer.

            

        end if    

        

        if time2 STALL_TIME 'The stall persists for more than the defined time 

        

            setcommand(_EX,3'Trigger Emergency stop to channel 2

                

        end if

 

end if

 

 

wait(1'1KHz script loop

 

if time 'at 0 take the first sample

    

    counter1[1] = getvalue(COUNTER,1)

    counter2[1] = getvalue(COUNTER,2)

    

end if

 

time ++ 

 

goto start