Commit 05eb4263 authored by bliss administrator's avatar bliss administrator
Browse files

Add activate and deactivate debug options

parent 8eee1233
...@@ -2,7 +2,7 @@ from bliss.common.standard import * ...@@ -2,7 +2,7 @@ from bliss.common.standard import *
from bliss.common.axis import * from bliss.common.axis import *
from bliss.common.cleanup import * from bliss.common.cleanup import *
from bliss.setup_globals import * from bliss.setup_globals import *
from bliss.common.log import * import logging
import sys import sys
import time import time
import random import random
...@@ -11,157 +11,197 @@ import gevent ...@@ -11,157 +11,197 @@ import gevent
### ---------- Log solution 2: Allows to activate debug for all functions in module
module_logger = logging.getLogger('cal')
handler = logging.StreamHandler()
handler.setLevel("DEBUG")
formatter = logging.Formatter("%(levelname)s -- %(funcName)s -- %(message)s")
handler.setFormatter(formatter)
module_logger.addHandler(handler)
module_logger.propagate = False
debug_activated =[]
###
def init_sx(): def init_sx():
sx.limits(low_limit=-100,high_limit=100) try:
######### LIMIT - logger = logging.getLogger('cal.init_sx')
print("Moving to hard limit -")
startm = time.time() sx.limits(low_limit=-100,high_limit=100)
sx.hw_limit(-1,wait=False)
######### LIMIT -
logger.info("Moving to hard limit -")
gevent.sleep(1) start = time.time()
sys.stdout.write("Searching limit- ...") sx.hw_limit(-1,wait=False)
sys.stdout.flush()
_status = sx.state()
while _status == "MOVING":
_status = sx.state()
sys.stdout.write('x')
sys.stdout.flush()
gevent.sleep(1) gevent.sleep(1)
logger.info("Searching limit- ...")
_status = sx.state()
while _status == "MOVING":
_status = sx.state()
if logger.getEffectiveLevel() > 0 and logger.getEffectiveLevel() < 30:
sys.stdout.write('.')
sys.stdout.flush()
gevent.sleep(1)
print(".\n") if logger.getEffectiveLevel() > 0 and logger.getEffectiveLevel() < 30:
print("lim- found !\n") sys.stdout.write('.\n')
sys.stdout.flush()
print("x Time to found lim-: "+str(time.time()-startm)) logger.info("lim- found !\n")
# hardware synchronization logger.info("Time to found lim-: "+str(time.time()-start) + "\n")
sx.sync_hard()
# hardware synchronization
sx.sync_hard()
_myposn = sx.position() _myposn = sx.position()
print("Hard limit - value: %f" % (_myposn)) logger.info("Hard limit - value: %f" % (_myposn))
######### LIMIT + ######### LIMIT +
print("Moving to hard limit +") logger.info("Moving to hard limit +")
sx.hw_limit(1,wait=False) sx.hw_limit(1,wait=False)
gevent.sleep(1)
sys.stdout.write("Searching limit+ ...")
sys.stdout.flush()
_status = sx.state()
while _status == "MOVING":
_status = sx.state()
sys.stdout.write('x')
sys.stdout.flush()
gevent.sleep(1) gevent.sleep(1)
logger.info("Searching limit+ ...")
_status = sx.state()
while _status == "MOVING":
_status = sx.state()
if logger.getEffectiveLevel() > 0 and logger.getEffectiveLevel() < 30:
sys.stdout.write('.')
sys.stdout.flush()
gevent.sleep(1)
print(".\n") if logger.getEffectiveLevel() > 0 and logger.getEffectiveLevel() < 30:
print("lim+ found !\n") sys.stdout.write('.\n')
sys.stdout.flush()
print("x Time to found lim+: "+str(time.time()-startm)) logger.info("lim+ found !\n")
# hardware synchronization logger.info("Time to found lim+: "+str(time.time()-start) + "\n")
sx.sync_hard()
# hardware synchronization
sx.sync_hard()
_myposp = sx.position() _myposp = sx.position()
print("Hard limit + value: %f" % (_myposp)) logger.info("Hard limit + value: %f" % (_myposp))
mid = (_myposp - _myposn) / 2.0 + _myposn mid = (_myposp - _myposn) / 2.0 + _myposn
print("moving to middle position %f\n" % (mid)) logger.info("moving to middle position %f\n" % (mid))
umv(sx,mid) umv(sx,mid)
print("reseting sx to 0\n") logger.info("reseting sx to 0\n")
sx.dial(0) sx.dial(0)
sx.position(0) sx.position(0)
slp = (_myposp - _myposn) / 2.0 - 0.05 slp = (_myposp - _myposn) / 2.0 - 0.05
print("reseting sx limits to hard limits +/- 0.05\n") logger.info("reseting sx limits to hard limits +/- 0.05\n")
sx.limits(low_limit=-slp,high_limit=slp) sx.limits(low_limit=-slp,high_limit=slp)
print("x Time end: "+str(time.time()-startm)) logger.info("Time end: "+str(time.time()-start))
except:
sx.stop()
#logger.setLevel("NOTSET")
# search for SY pos and neg limits and reset dial to 0 in the middle of them. # search for SY pos and neg limits and reset dial to 0 in the middle of them.
def init_sy(): def init_sy():
sy.limits(low_limit=100,high_limit=-100) try:
######### LIMIT - logger = logging.getLogger('cal.init_sy')
print("Moving to hard limit -")
startm = time.time() sy.limits(low_limit=100,high_limit=-100)
sy.hw_limit(-1,wait=False)
######### LIMIT -
logger.info("Moving to hard limit -")
gevent.sleep(1)
sys.stdout.write("Searching limit- ...") start = time.time()
sys.stdout.flush() sy.hw_limit(-1,wait=False)
_status = sy.state()
while _status == "MOVING":
_status = sy.state()
sys.stdout.write('y')
sys.stdout.flush()
gevent.sleep(1) gevent.sleep(1)
logger.info("Searching limit- ...")
_status = sy.state()
while _status == "MOVING":
_status = sy.state()
if logger.getEffectiveLevel() > 0 and logger.getEffectiveLevel() < 30:
sys.stdout.write('.')
sys.stdout.flush()
gevent.sleep(1)
print(".\n") if logger.getEffectiveLevel() > 0 and logger.getEffectiveLevel() < 30:
print("lim- found !\n") sys.stdout.write('.\n')
sys.stdout.flush()
print("y Time to found lim-: "+str(time.time()-startm)) logger.info("lim- found !\n")
# hardware synchronization logger.info("Time to found lim-: "+str(time.time()-start) + "\n")
sy.sync_hard()
# hardware synchronization
sy.sync_hard()
_myposn = sy.position() _myposn = sy.position()
print("Hard limit - value: %f" % (_myposn)) logger.info("Hard limit - value: %f" % (_myposn))
######### LIMIT + ######### LIMIT +
print("Moving to hard limit +") logger.info("Moving to hard limit +")
sy.hw_limit(1,wait=False) sy.hw_limit(1,wait=False)
gevent.sleep(1)
sys.stdout.write("Searching limit+ ...")
sys.stdout.flush()
_status = sy.state()
while _status == "MOVING":
_status = sy.state()
sys.stdout.write('y')
sys.stdout.flush()
gevent.sleep(1) gevent.sleep(1)
logger.info("Searching limit+ ...")
_status = sy.state()
while _status == "MOVING":
_status = sy.state()
if logger.getEffectiveLevel() > 0 and logger.getEffectiveLevel() < 30:
sys.stdout.write('.')
sys.stdout.flush()
gevent.sleep(1)
print(".\n") if logger.getEffectiveLevel() > 0 and logger.getEffectiveLevel() < 30:
print("lim+ found !\n") sys.stdout.write('.\n')
sys.stdout.flush()
print("y Time to found lim+: "+str(time.time()-startm)) logger.info("lim+ found !\n")
# hardware synchronization logger.info("Time to found lim+: "+str(time.time()-start) + "\n")
sy.sync_hard()
# hardware synchronization
sy.sync_hard()
_myposp = sy.position() _myposp = sy.position()
print("Hard limit + value: %f" % (_myposp)) logger.info("Hard limit + value: %f" % (_myposp))
mid = (_myposp - _myposn) / 2.0 + _myposn mid = (_myposp - _myposn) / 2.0 + _myposn
print("moving to middle position %f\n" % (mid)) logger.info("moving to middle position %f\n" % (mid))
umv(sy,mid) umv(sy,mid)
print("reseting sy to 0\n") logger.info("reseting sy to 0\n")
sy.dial(0) sy.dial(0)
sy.position(0) sy.position(0)
slp = (_myposp - _myposn) / 2.0 - 0.05 slp = (_myposp - _myposn) / 2.0 - 0.05
print("reseting sy limits to hard limits +/- 0.05\n") logger.info("reseting sy limits to hard limits +/- 0.05\n")
sy.limits(low_limit=-slp,high_limit=slp) sy.limits(low_limit=-slp,high_limit=slp)
print("y Time end: "+str(time.time()-startm)) logger.info("Time end: "+str(time.time()-start))
except:
sy.stop()
#logger.setLevel("NOTSET")
# search for YROT pos and neg limits and reset dial to 0 in the middle of them. # search for YROT pos and neg limits and reset dial to 0 in the middle of them.
...@@ -323,47 +363,61 @@ def init_hr_z0(): ...@@ -323,47 +363,61 @@ def init_hr_z0():
def init_simot(): def init_simot():
lim_p = simot.limits()[1] try:
simot.limits(low_limit=-100,high_limit=lim_p) logger = logging.getLogger("init_simot")
lim_p = simot.limits()[1]
simot.limits(low_limit=-100,high_limit=lim_p)
######### LIMIT - ######### LIMIT -
print("Moving to hard limit -") logger.debug("Moving to hard limit -")
simot.hw_limit(-1,wait=False) simot.hw_limit(-1,wait=False)
gevent.sleep(1)
sys.stdout.write("Searching limit- ...")
sys.stdout.flush()
_status = simot.state()
while _status == "MOVING":
_status = simot.state()
sys.stdout.write('.')
sys.stdout.flush()
gevent.sleep(1) gevent.sleep(1)
logger.debug("Searching limit- ...")
#sys.stdout.write("Searching limit- ...")
#sys.stdout.flush()
_status = simot.state()
while _status == "MOVING":
_status = simot.state()
if logger.getEffectiveLevel() == 10:
sys.stdout.write('.')
sys.stdout.flush()
gevent.sleep(1)
print(".\n") if logger.getEffectiveLevel() == 10:
print("lim- found !\n") sys.stdout.write('.\n')
sys.stdout.flush()
# hardware synchronization logger.debug("lim- found !\n")
simot.sync_hard()
_myposn = simot.position()
print("Hard limit - value: %f" % (_myposn))
cal_pos = 0.0
sln = cal_pos + 0.05
print("reseting simot1 to %f\n" % (cal_pos))
simot.dial(cal_pos)
simot.position(cal_pos)
print("moving to calibration position %f\n" % (cal_pos + 10.0)) # hardware synchronization
umvr(simot,10.0) simot.sync_hard()
print("reseting simot1 limit- to hard limit + 0.05\n") _myposn = simot.position()
simot.limits(low_limit=sln,high_limit=lim_p)
logger.debug("Hard limit - value: %f" % (_myposn))
cal_pos = 0.0
sln = cal_pos + 0.05
logger.debug("reseting simot1 to %f\n" % (cal_pos))
simot.dial(cal_pos)
simot.position(cal_pos)
logger.debug("moving to calibration position %f\n" % (cal_pos + 10.0))
umvr(simot,10.0)
logger.debug("reseting simot1 limit- to hard limit + 0.05\n")
simot.limits(low_limit=sln,high_limit=lim_p)
except:
# reset logging level = NOTSET
logger.setLevel("NOTSET")
simot.stop()
simot.dial(0)
simot.position(0)
finally:
logger.setLevel("NOTSET")
def calib_motors(*argv): def calib_motors(*argv):
...@@ -398,4 +452,67 @@ def test_stability(): ...@@ -398,4 +452,67 @@ def test_stability():
mvr(sy,-1.0*random.randrange(10,90)*0.01) mvr(sy,-1.0*random.randrange(10,90)*0.01)
calib_motors(init_sx, init_sy) calib_motors(init_sx, init_sy)
print("----- Loop "+str(i)+" ---- time for this loop is " + str(time.time()-time_start) + " ----- Time: "+str(datetime.datetime.now())) print("----- Loop "+str(i)+" ---- time for this loop is " + str(time.time()-time_start) + " ----- Time: "+str(datetime.datetime.now()))
def activate_debug(func_name=None):
"""
This allows to display all debug messages contained in a function
with solution 1 can activate debug locally only
with solution 2 can activate debug locally (for one method) AND globaly (for all the module)
"""
# --------------- Log solution 1
## creation of a stream handler object
#handler = logging.StreamHandler()
#handler.setLevel("DEBUG")
## creation of a formatter object to modify output stream format
#formatter = logging.Formatter("%(levelname)s -- %(name)s -- %(message)s")
#handler.setFormatter(formatter)
## creation of a logger with the name transmitted by the user
#logger = logging.getLogger(func_name.__name__)
## test to verify that debug is not already activated
#if logger.handlers == []:
#logger.addHandler(handler)
## by default logging level is "WARNING"
#logger.setLevel("DEBUG")
## deactivate root logger output
#logger.propagate = False
# --------------- Log solution 2
global debug_activated
if func_name:
module_logger.getChild(func_name.__name__).setLevel("DEBUG")
debug_activated.append(func_name.__name__)
else:
module_logger.setLevel("DEBUG")
def deactivate_debug(func_name=None):
# --------------- Log solution 1
#logger = logging.getLogger(func_name.__name__)
#logger.setLevel("NOTSET")
# --------------- Log solution 2
global debug_activated
if func_name:
module_logger.getChild(func_name.__name__).setLevel("WARNING")
else:
for func in debug_activated:
module_logger.getChild(func).setLevel("NOTSET")
module_logger.setLevel("NOTSET")
debug_activated = []
def test_debug():
"""
This allows to filter outputs on console in order to display info about one motor only
"""
try:
activate_debug(init_sx)
calib_motors(init_sx,init_sy)
except:
deactivate_debug(init_sx)
finally:
deactivate_debug(init_sx)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment