esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#%TITLE% MICOS.MAC
#%NAME%
#   Macro motors controller for Micos motors
#
#%CATEGORY% Positioning
#
#%DESCRIPTION%
#   The macro set offers the possibility to set-up a Micos motor
#   a SPEC "harware macro-motor".
#
#   The macro-motor controller is called "micos_mot".
#
#   Only one device can be configfured :(
#
#%EXAMPLE%
#%DL%
#%DT%  micos_mot_setup mix id13/micos/x %DD%
#      Set-up the micos macro motor with the mnemonic "mix"
#
#%DT%  micos_config mix %DD%
#      Macro to set acceleration, velocity, window_size and settling_time
#      parameters for a micos motor.
#
#%XDL%
#
#%END%


# for cprint
jtdo("spec_utils")


######################################################################
##############################          ##############################
##############################  SETUP   ##############################
##############################          ##############################
######################################################################


#%UU% <motor_mnemonic> <device_name>
#%MDESC%
#    Calls set-up of micos macro motor.
def micos_mot_setup '{

    local _mot_mne _dev

    _mot_mne = "$1"
    _dev     = "$2"

    _micos_mot_setup(_mot_mne, _dev)
}'


#%UU% (<motor_mnemonic> <device_name>)
#%MDESC%
#    Set-up of micos macro motor.
# The given device is linked to the given mnemonic.
def _micos_mot_setup(mot_mne, dev) '{

    global MICOS_MOT
    global ESRF_ERR
    global ESRF_ERR_MSG
    global MICOS_MOT_ERROR

    MICOS_MOT_ERROR = "WARNING, error on reading micos macro motor"

    MICOS_MOT[mot_mne]["dev_name"] = dev
}'


#%UU%
#%MDESC%
#    Resets the micos controller (after a cut-off of air compressed for example).
def micos_reset '{
    local _ans

    _ans = esrf_io(MICOS_MOT["$1"]["dev_name"], "DevReset")
}'


#%UU%
#%MDESC%
#   Removes globals.
def micos_mot_unsetup '{
    unglobal MICOS_MOT
    unglobal MICOS_MOT_ERROR
}'



######################################################################
###############################        ###############################
###############################  INFO  ###############################
###############################        ###############################
######################################################################


#%UU%
#%MDESC%
#    Prints information about configured micos device.
def micos_show '{
    print "--------------============ MICOS ================-----------------"

    print esrf_io(MICOS_MOT["srot"]["dev_name"], "DevStatus")

    printf ("Velocity : %s\n",     esrf_io(MICOS_MOT["srot"]["dev_name"], "DevReadVelocity"))
    printf ("Acceleration : %s\n", esrf_io(MICOS_MOT["srot"]["dev_name"], "DevReadAcceleration"))
    printf ("RAW Position : %s\n", esrf_io(MICOS_MOT["srot"]["dev_name"], "DevReadPosition"))
    printf ("HoldCurr : %s\n",     esrf_io(MICOS_MOT["srot"]["dev_name"], "DevGetHoldCurr"))
    printf ("CloseLoop : %s\n",    esrf_io(MICOS_MOT["srot"]["dev_name"], "DevGetCloseLoop"))

    print "\\------------------------------------------------------------------/"
}'




######################################################################
############################               ###########################
############################  MACRO MOTOR  ###########################
############################               ###########################
######################################################################


#%IU% (<mot_num>, <type>, <unit>, <module>, <channel>)
#%MDESC%
#    Macro motor configuration.
def micos_mot_config(mot_num, type, unit, module, channel) '{

    # print "--micos_mot_config--mot-num=" mot_num

    if (whatis("MICOS_MOT") && 0x8000000){
        cprint( "==MICOS==:  setup\n", 2)
    }
    else{
        cprint( "==MICOS==: not setup\n", 1)
        return ".error."
    }

    return 0
}'


#%IU%
#%MDESC%
# Entry point of macro motor controller.
# Called with different keys to handle motor actions.
#
def micos_mot_cmd(mot_num, what, p1, p2) '{
    local _mot

    _mot = motor_mne(mot_num)

    if (motnum == "..") {
        if (what == "position")     print " MICOSSSSSS PROBLEM position "
        if (what == "get_status")   print " MICOSSSSSS PROBLEM get_status"
        if (what == "start_one")    print " MICOSSSSSS PROBLEM start_one"
        if (what == "set_position") print " MICOSSSSSS PROBLEM set_position"
        if (what == "abort_one")    print " MICOSSSSSS PROBLEM abort_one"
        if (what == "velocity")     print " MICOSSSSSS PROBLEM velocity"
        if (what == "acceleration") print " MICOSSSSSS PROBLEM acceleration "
    }
    else{

        #-------------------------------------
        # "position" must return dial position (in integer steps)
        # parameters: none
        if (what == "position") {
            local _pos

            _pos = esrf_io (MICOS_MOT[_mot]["dev_name"], "DevReadPosition")
            return (_pos)
        }
        else{
            # do nothing
        }


        #-------------------------------------
        # "get_status" called during the motion, must return a bit mask
        # bits meaning: 0 if motor idle
        #               2 if motor moving
        #               4 if negative limit on
        #               8 if positive limit on
        # parameters:   none
        if (what == "get_status") {
            local _state
            local _ret

            ESRF_ERR = -1
            _state = esrf_io (MICOS_MOT[_mot]["dev_name"], "DevState")
            if (ESRF_ERR) {
                tty_cntl("md")
                print "\n <status>" MICOS_MOT_ERROR " " mot_num "\n\n"
                tty_cntl("me")
                print "    -- error is: -- " ESRF_ERR_MSG
            }

            #
            # DEVMOVING
            #
            if (_state == 9) {
                _ret |= 2
                return _ret
            }

            #
            # DEVALARM
            #
            if (_state == 45) {
                print
                print esrf_io (MICOS_MOT[_mot]["dev_name"], "DevStatus")
                print

                _ret |= 4
                return _ret
            }

            #
            # DEVFAULT
            #
            if (_state == 23) {
                print
                print esrf_io (MICOS_MOT[_mot]["dev_name"], "DevStatus")
                print
                return 0
            }

            return 0

        }
        else{
            # nothing
        }

        #-------------------------------------
        # "start_one"
        # parameters: p2 is relative motion, p1 is absolute requested position

        if (what == "start_one") {
            ESRF_ERR = -1
            esrf_io(MICOS_MOT[_mot]["dev_name"], "DevMoveAbsolute", p1)

            if (ESRF_ERR) {
                tty_cntl("md")
                print "\n <move> " MICOS_MOT_ERROR " " mot_num "\n\n"
                print ESRF_ERR_MSG
                print "Status is " esrf_io(MICOS_MOT[_mot]["dev_name"], "DevStatus")
                tty_cntl("me")
            }

        }
        else {
            # nothing
        }


        #-------------------------------------
        # "set_position" called on "set_dial motor newpos"
        # parameters: p1 is the new position
        #
        if (what == "set_position") {
            ESRF_ERR = -1
            esrf_io(MICOS_MOT[_mot]["dev_name"], "DevLoadPosition", p1)

            if (ESRF_ERR) {
                tty_cntl("md")
                print "\n" MICOS_MOT_ERROR " " mot_num "\n\n"
                tty_cntl("me")
            }
        }
        else {
            # nothing
        }

        #-------------------------------------
        # "abort_one" called on <Ctrl-C>
        #
        if (what == "abort_one") {
            ESRF_ERR = -1
            esrf_io(MICOS_MOT[_mot]["dev_name"], "DevAbort")
            if (ESRF_ERR) {
                tty_cntl("md")
                print "\n <abort> " MICOS_MOT_ERROR " " mot_num "\n\n"
                tty_cntl("me")
            }
        }

        # called on motor_par(xxx, "velocity", newval)
        if(what == "velocity") {
            # esrf_io(MICOS_MOT[_mot]["dev_name"], "DevSetVelocity",  velocity)
        }

        # called on motor_par(xxx,"velocity",newval)
        if(what == "acceleration") {
            # esrf_io(MICOS_MOT[_mot]["dev_name"], "DevSetAcceleration", acceleration)
        }
    }

}'




#%UU% [ motor_mnemonic ]
#%MDESC%
# Sets the acceleration and velocity of a motor.
#
def micos_config '{
    local _ret
    local _mot
    local double array _signals[10]
    local acceleration
    local velocity
    local window_size
    local settling_time
    local argin

    if ( $# != 1 ) {
         printf ("Usage: micos_config mnemonic\n")
         exit
    }
    else {
        _mot         = MICOS_MOT["$1"]["dev_name"]
        _ret = esrf_io (_mot, "DevReadSigValues", _signals)
        if ( _ret >= 0 ) {
            printf ("\nMotor parameters:\n")
            acceleration = getval("Acceleration[mm(deg)/:s2] ",_signals[2])
            velocity     = getval("Velocity[mm(deg)/s]       ",_signals[3])
            window_size  = getval("Window Size[mm(deg)]      ",_signals[4])
            settling_time= getval("Settling Time[sec]        ",_signals[5])
            printf ("\n")
        }
    }

    esrf_io(_mot, "DevSetAcceleration", acceleration)
    esrf_io(_mot, "DevSetVelocity",  velocity)

    argin[0] = window_size
    argin[1] = settling_time

    esrf_io(_mot, "DevSetWindow",    argin)
}'

#%MACROS%
#%IMACROS%
#%AUTHOR% J. MEYER / BLISS / ESRF
#%TOC%