Scope



In some cases a user might want to perform a certain action, like activating a digital output or to send log messages to a master device, when a specific motor status flag is active. For instance, we want to see if Amps Limit is being reached too often, indicating that the load is excessive or that the Amps Limit setting should be higher.


To achieve this, we use bitwise operation on the Motor Status Flag register


getValue(_FM , cc) , where cc is the motor channel in question


The reply of this query is : 


FM = f1 + f2*2 + f3*4 + ... + fn*2n-1


where each status fn is defined in the RoboteQ controllers user manual v3.0, in table 15-15 : 





The script that follows detects which status is active and the user can then add commands. The user also has to define the motor channel and the status which will be detected.



Important Disclaimer :


RoboteQ offers this script as an example, and will not be held responsible for its operation or potential misuse. The user should validate its functionalities thoroughly priot to using this script in their application.



The script



' MicroBasic script for Roboteq controllers

' General script to detect a specified motor status

 

' DISCLAIMER : RoboteQ offers this script as an example, and will not be held responsible

' for its operation or potential misuse. The user should validate its functionalities

' thoroughly prior to using this script in their application.

 

' User should replace x in CHECKED_STATUS with the appropriate value

' Status Flag Reference (corresponding to the bit in the status register):

' 1 - AmpLim (Current limit) - Bit 0

' 2 - Stall (Stall detection) - Bit 1

' 4 - Loop Error (Loop error detection) - Bit 2

' 8 - SafeStop (Safety Stop action) - Bit 3

' 16 - FwdLimit (Forward limit switch action) - Bit 4

' 32 - RevLimit (Reverse limit switch action) - Bit 5

' 64 - AmpTrig (Amps trigger threshold) - Bit 6

' 128 - FETs Off (Power MOSFETs floated due to error) - Bit 7

#define CHECKED_STATUS x

#define CHANNEL y

dim motorStatus as integer

 

top: ' Start of the main loop

 

     ' Get the motor status flags for Motor 1

    motorStatus getvalue(_MOTFLAGCHANNEL

 

     ' Check if the specified status bit is set

     if (motorStatus and CHECKED_STATUS) <> then 

         ' Specified status condition detected for Motor 1

         print("Motor 1 status condition detected for flag "CHECKED_STATUS"\n")     

         'DO ACTIONS....

         '.....            

     else

         ' Specified status condition not present for Motor 1

         print("Motor 1 status condition not detected for flag "CHECKED_STATUS"\n")

         'DO ACTIONS....

         '.....    

     end if

 

     ' Small delay before next check

     wait(2

 

goto top ' Repeat the loop