Commit bea716fe authored by Yoann Sallaz Damaz's avatar Yoann Sallaz Damaz
Browse files

new inclino

parent 9151231b
......@@ -6,7 +6,7 @@ import time
def set_text(e, text):
e["text"]=text
class WAGOTEST(Frame):
class wago_test_pneumatique(Frame):
def __init__(self):
super().__init__()
......@@ -163,7 +163,7 @@ def main():
root = Tk()
root.geometry("800x170")
app = WAGOTEST()
app = wago_test_pneumatique()
root.mainloop()
......
"""
Inclinometer in 4-20mA control by a 750-473 card
yml configuration example:
plugin: bliss
name: inclinoNew1
package: bm07.inclino_FIP
class: inclino_FIP
wago: $wcd07g
logical_device : inclino1
sign: -1
offset: 0
"""
from bliss.common.logtools import *
import time
class inclino_FIP:
def __init__(self, name, config):
self.name = name
self.wago = config["wago"]
self.logical_device = config["logical_device"]
self.sign = config["sign"]
self.offset = config["offset"]
self.channel = self.wago.controller.devname2key(self.logical_device)
def read(self):
log_debug(self, "Inclino read()")
return self.sign*((self.wago.controller.client_read_input_registers(self.channel,"H")& 0xFFF8)*0.9765625/1000)+self.offset
def __info__(self):
register = self.wago.controller.client_read_input_registers(self.channel,"H")
XFU = self.wago.controller.client_read_input_registers(self.channel,"H") & 0x07
raw = self.wago.controller.client_read_input_registers(self.channel,"H") & 0xFFF8
info_string = f"'{self.name}` Inclino_FIP from wago:\n"
info_string += f" Wago = {self.wago.name}\n"
info_string += f" Logical device = {self.logical_device}\n"
info_string += f' Unit = degree\n'
info_string += f' Sign = {self.sign}\n'
info_string += f' Offset = {self.offset}\n'
info_string += f" register value = {register}\n"
info_string += f" XFU = {XFU}\n"
info_string += f" raw value = {raw}\n"
info_string += f" value = {self.read()} deg\n"
return info_string
\ No newline at end of file
from bliss.controllers.motor import CalcController
from bliss.common.logtools import *
from bliss import global_map
from bliss.controllers.tango_attr_as_counter import tango_attr_as_counter
from bm07 import inclino_FIP
#from bliss import global_map
#from bliss.controllers.tango_attr_as_counter import tango_attr_as_counter
from math import asin,sin
class bragg(CalcController):
def __init__(self, *args, **kwargs):
CalcController.__init__(self, *args, **kwargs)
inclino_name = self.config.get("inclino")
self.slope_source = float(self.config.get("slope_source"))
for counter in global_map.get_counters_iter():
if inclino_name == counter.name:
self.inclino = counter
break
self.inclinoM1 = self.config.get("inclino", inclino_FIP)
self.slope_source = self.config.get("slope_source", float)
def initialize_axis(self, axis):
CalcController.initialize_axis(self, axis)
axis.no_offset = True
def calc_from_real(self, positions_dict):
bragg_angle = -self.slope_source + 2*self.inclino.value + positions_dict["beta"]
bragg_angle = -self.slope_source + 2*self.inclinoM1.read() + positions_dict["beta"]
return {"calc_brag": bragg_angle}
def calc_to_real(self, positions_dict):
real_pos = self.slope_source - 2*self.inclino.value + positions_dict["calc_brag"]
real_pos = self.slope_source - 2*self.inclinoM1.read() + positions_dict["calc_brag"]
return {"beta": real_pos}
class mirrorup(CalcController):
......@@ -47,22 +44,24 @@ class mirrorup(CalcController):
class inclino(tango_attr_as_counter):
def __init__(self, name, config):
tango_attr_as_counter.__init__(self, name, config)
self.offset = float(config.get("offset"))
self.sign = float(config.get("sign"))
#class inclino(tango_attr_as_counter):
# def __init__(self, name, config):
# tango_attr_as_counter.__init__(self, name, config)
# self.offset = float(config.get("offset"))
# self.sign = float(config.get("sign"))
def convert_func(self, raw_value):
# reecriture de cette fonction pour prendre en compte le signe et l'offset
"""
Apply to the <raw_value>:
* conversion_factor
* formatting
"""
log_debug(self, "raw_value=%s", raw_value)
attr_val = raw_value * self.conversion_factor
formated_value = float(
self.format_string % attr_val if self.format_string else attr_val
)
return self.sign*(formated_value-self.offset)
# def convert_func(self, raw_value):
# # reecriture de cette fonction pour prendre en compte le signe et l'offset
# """
# Apply to the <raw_value>:
# * conversion_factor
# * formatting
# """
# log_debug(self, "raw_value=%s", raw_value)
# attr_val = raw_value * self.conversion_factor
# formated_value = float(
# self.format_string % attr_val if self.format_string else attr_val
# )
# return self.sign*(formated_value-self.offset)
\ No newline at end of file
......@@ -465,12 +465,11 @@ def mesure_bend_M2_sans_M2(Min, Max, nbPoint):
def mesure_beam_oscill_fluo3(nbimages,Name):
positions = []
for i in range(0,nbimages):
#saveMonitorsImage("0001","utz_%f"%pos)
#saveMonitorsImage("0001","utz_%f"%pos)
urllib.request.urlretrieve("http://bm07recorder.esrf.fr:7006/jpg/image.jpg", "/tmp/pictures/test.jpg")
picpos = analyseImg()
positions.append(picpos)
print (picpos)
#time.sleep(0.3)
picpos = analyseImg()
positions.append(picpos)
print (picpos)
var = np.var(positions)
print("Vertical Pic Position Variance = %f"%var)
......@@ -588,3 +587,11 @@ def delta_utx_utz_fixed_height(relMoveh, sourceAngle_uRad=0):
delta_utx = L2 *cos(braggrad)
return (delta_utx, delta_utz)
def md2_wakeup():
motlist = [omega, kappa, phi, x, y, z, xomega, zomega]
for sign in [1,-1]:
for mot in motlist:
mot.move(mot.position+sign*0.1, wait=False)
while any(mot.is_moving for mot in motlist):
sleep(0.1)
\ No newline at end of file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from bliss.controllers.motor import CalcController
from bliss.common.utils import object_method
from bliss.common import *
import math
from bliss.config.static import get_config
class pseudo_gonio(CalcController):
def __init__(self, *args, **kwargs):
CalcController.__init__(self, *args, **kwargs)
def initialize_axis(self, axis):
CalcController.initialize_axis(self, axis)
axis.no_offset = True
def calc_from_real(self, positions_dict):
calc_dict = dict()
omegarad = math.radians(positions_dict["omega"])
verticalpos = positions_dict["x"] * math.sin(-omegarad) + positions_dict["z"] * math.cos(-omegarad)
calc_dict.update({"sample_vertical": (verticalpos)})
return calc_dict
def calc_to_real(self, positions_dict):
real_dict = dict()
omegarad = math.radians(positions_dict["omega"])
vert = positions_dict["sample_vertical"]
hor = sampx * math.cos(omegarad) + sampy * math.sin(omegarad)
x = vert * math.sin(-omegarad) + hor * math.cos(-omegarad)
z = vert * math.cos(-omegarad) - hor * math.sin(-omegarad)
real_dict.update({"x": x, "z": z})
return real_dict
......@@ -29,7 +29,9 @@ def reset_pos_pos(mot):
print("Fail")
def reset_pos(self):
if self.config.get("ref") == 'lim-':
if self.name=="omega":
self.home()
elif self.config.get("ref") == 'lim-':
print("Search for lim-")
reset_pos_neg(self)
else:
......
from tkinter import *
from functools import partial
from pyModbusTCP.client import ModbusClient
import time
class wago_test_pneumatique_class(Frame):
def __init__(self):
super().__init__()
self.initUI()
self.connected=False
self.c=None
self.poll()
def poll(self):
self.read_from_wago()
self.master.update_idletasks()
self.master.after_idle(self.poll)
def initUI(self):
self.master.title("Test WAGO Pneumatique")
frame1 = Frame(self)
frame1.pack(fill=X)
lblIP = Label(frame1, text="IP ou Hostname")
lblIP.pack(side=LEFT, padx=5, pady=5)
self.connectbtn = Button(frame1,text="Connecter", command=self.connection)
self.connectbtn.pack(side=RIGHT, padx=5)
self.entryPORT = Entry(frame1)
self.entryPORT.insert(END,"502")
self.entryPORT.pack(padx=5, side=RIGHT)
lblPORT = Label(frame1, text="Port")
lblPORT.pack(side=RIGHT, padx=5, pady=5)
self.entryIP = Entry(frame1)
self.entryIP.insert(END,"160.103.127.26")
self.entryIP.pack(fill=X, padx=5, expand=True)
self.frame2 = Frame(self, relief=RAISED, borderwidth=1)
for i in range(0,8+1+4):
if i==8:
weight=5
else:
weight=1
self.frame2.columnconfigure(i, pad=0, weight=weight)
for i in range(0,1+2+2):
self.frame2.rowconfigure(i, pad=3)
self.stateOn=[]
self.stateOff=[]
idx=0
for i in range(0,8+1+4):
if i!=8:
lblChan = Label(self.frame2, text=str(i))
lblChan.grid(row=0,column=i, sticky="n")
self.stateOn.append(Canvas(self.frame2, bg="black", height=10, width=10))
self.stateOn[-1].grid(row=1,column=i, sticky="n")
self.stateOff.append(Canvas(self.frame2, bg="black", height=10, width=10))
self.stateOff[-1].grid(row=2,column=i, sticky="n")
on_with_arg = partial(self.enable, idx)
btnOn = Button(self.frame2, text="ON", width=5, command=on_with_arg)
btnOn.grid(row=3,column=i, sticky="n")
off_with_arg = partial(self.disable, idx)
btnOff = Button(self.frame2, text="OFF", width=5, command=off_with_arg)
btnOff.grid(row=4,column=i,sticky="n")
idx+=1
self.frame2.pack(fill=X)
for child in self.frame2.winfo_children():
child.configure(state='disable')
frame = Frame(self)
frame.pack(fill=BOTH, expand=True)
self.pack(fill=BOTH, expand=True)
self.status = Label(self)
self.status.pack(side=LEFT, padx=5, pady=5, fill=X, expand=True)
def display_enabled(self,channel):
self.stateOn[channel].config(bg="green")
self.stateOff[channel].config(bg="black")
def display_disabled(self,channel):
self.stateOn[channel].config(bg="black")
self.stateOff[channel].config(bg="red")
def enable(self,channel):
try:
if(self.connected):
self.c.write_single_coil(channel,1)
except Exception as e:
self.status["text"]=e
def disable(self,channel):
try:
if(self.connected):
self.c.write_single_coil(channel,0)
except Exception as e:
self.status["text"]=e
def read_from_wago(self):
try:
if self.connected:
values=self.c.read_coils(512,12)
for i in range(0,len(values)):
if values[i]:
self.display_enabled(i)
else:
self.display_disabled(i)
except Exception as e:
self.status["text"]=e
def connection(self):
IP=self.entryIP.get()
PORT=self.entryPORT.get()
if not self.connected:
try:
self.c = ModbusClient(IP,int(PORT), timeout=2)
if not self.c.is_open():
if not self.c.open():
self.status["text"]="unable to connect to "+IP+":"+PORT
else:
self.connected=True
else:
self.connected=True
except Exception as e:
self.status["text"]=e
if self.connected:
self.status["text"]="Connection OK"
self.connectbtn['text']="Deconnecter"
self.entryIP.config(state='disabled')
self.entryPORT.config(state='disabled')
for child in self.frame2.winfo_children():
child.configure(state='normal')
else:
self.c.close()
self.status["text"]="Deconnection"
self.connectbtn['text']="Connecter"
self.entryIP.config(state='normal')
self.entryPORT.config(state='normal')
self.connected=False
for child in self.frame2.winfo_children():
child.configure(state='disabled')
for child in self.stateOn:
child.config(bg="black")
for child in self.stateOff:
child.config(bg="black")
def wago_test_pneumatique():
root = Tk()
root.geometry("800x170")
app = wago_test_pneumatique_class()
root.mainloop()
if __name__ == '__main__':
wago_test_pneumatique()
\ No newline at end of file
from pyModbusTCP.client import ModbusClient
import time
c = ModbusClient('wcd07g.esrf.fr')
while True:
# open or reconnect TCP to server
if not c.is_open():
if not c.open():
print("unable to connect to "+SERVER_HOST+":"+str(SERVER_PORT))
# if open() is ok, read register (modbus function 0x03)
if c.is_open():
# read 10 registers at address 0, store result in regs list
regs = c.read_holding_registers(0, 2)
# if success display registers
if regs:
XFU0 = regs[0] & 0x07
value0 = regs[0] & 0xFFF8
XFU1 = regs[1] & 0x07
value1 = regs[1] & 0xFFF8
print("%f(%d) %f(%d)"%(value0*0.9765625/1000, XFU0, value1*0.9765625/1000, XFU1))
# sleep 2s before next polling
time.sleep(2)
Supports Markdown
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