def __init__(self, *args, **kwargs): super().__init__() self.r = RsdRedis() self.ui = Ui_MainWindow() self.ui.setupUi(self) # setup logo logo = QtGui.QImage('logo.jpg') self.ui.label_10.setPixmap(QtGui.QPixmap.fromImage(logo)) # state subscriber self.state_change.connect(self.on_state_change) self.r.subscribe("state_changed", self.state_change.emit) self.on_state_change((None, S.ABORTED)) # button callbacks self.ui.stopButton.clicked.connect( lambda: self.r.publish("action", A.STOP)) self.ui.pauseButton.clicked.connect( lambda: self.r.publish("action", A.HOLD)) self.ui.startButton.clicked.connect( lambda: self.r.publish("action", A.START)) self.ui.resetButton.clicked.connect( lambda: self.r.publish("action", A.RESET)) # OEE - https://www.oee.com/calculating-oee.html self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.on_timer_timeout) self.timer.start(500)
def __init__(self, debug=False): super().__init__() self.should_stop = False self.debug = debug self.r = RsdRedis() self.state = self.r.get("state") if self.state is None: self.state = S.ABORTED self.t = None
def _test(): lt = LightTower(debug=True) lt.start(blocking=False) r = RsdRedis() for state in light_config.keys(): time.sleep(3) r.publish("state_changed", (None, state)) lt.stop()
class LightTower: odd = False def __init__(self, debug=False): super().__init__() self.should_stop = False self.debug = debug self.r = RsdRedis() self.state = self.r.get("state") if self.state is None: self.state = S.ABORTED self.t = None def set_state(self, data): old_state, new_state = data self.state = new_state print("STATE:", STATES[new_state]) def start(self, blocking=True): assert self.t is None sub = self.r.subscribe("state_changed", self.set_state) def loop(): while not self.should_stop: self.set_lights() time.sleep(.5) self.r.unsubscribe(sub) self.t = threading.Thread(target=loop) self.t.start() if blocking: self.t.join() return self def set_lights(self): state = self.state if state is None: state = S.STOPPED l_conf = light_config[state] condition = (SOLID, FLASH) if self.odd else (SOLID,) lights_on = [l_conf.get(color, OFF) in condition for color in COLORS] self.odd = not self.odd if self.debug: print(STATES[state], "ODD" if self.odd else "EVEN", lights_on) else: for output_id, light_on in enumerate(lights_on): self.r.publish("setStandardDigitalOut", (output_id, light_on)) def stop(self): self.should_stop = True self.t.join() def __del__(self): self.stop()
#!/usr/bin/python3 from rsd.robot.robot import Robot from rsd.utils.rsd_redis import RsdRedis from rsd import conf from rsd.mes import Mes from rsd.robot import q from rsd.vision.vision_client import VisionClient from rsd.robot.path import find_nearest, find_path from rsd.packml.packml import PackMLActions as A from rsd.mir.mir import Mir redis = RsdRedis() robot = Robot(redis) mes = Mes(conf.MES_SERVER_URL) vis = VisionClient() mir = Mir(9, 11, "G9_mission") mir.remove_old_missions() redis.set("current_order", None) # We don't know the position of the robot. # Find the closest q and move a clear path from there to IDLE. robot.release() q_s, dist = find_nearest(robot.get_q()) clear_path = find_path(q_s, q.IDLE) assert clear_path robot.move(*clear_path) orders_ready = False
def __init__(self, r: RsdRedis = RsdRedis()): self.r = r self.ur_ctrl = RTDEControlInterface(conf.UR_IP)
class MainWindow(QtWidgets.QMainWindow, QObject): state_change = Signal(tuple) state = None light_tower_odd = False uptime = 0. runtime = 0. def __init__(self, *args, **kwargs): super().__init__() self.r = RsdRedis() self.ui = Ui_MainWindow() self.ui.setupUi(self) # setup logo logo = QtGui.QImage('logo.jpg') self.ui.label_10.setPixmap(QtGui.QPixmap.fromImage(logo)) # state subscriber self.state_change.connect(self.on_state_change) self.r.subscribe("state_changed", self.state_change.emit) self.on_state_change((None, S.ABORTED)) # button callbacks self.ui.stopButton.clicked.connect( lambda: self.r.publish("action", A.STOP)) self.ui.pauseButton.clicked.connect( lambda: self.r.publish("action", A.HOLD)) self.ui.startButton.clicked.connect( lambda: self.r.publish("action", A.START)) self.ui.resetButton.clicked.connect( lambda: self.r.publish("action", A.RESET)) # OEE - https://www.oee.com/calculating-oee.html self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.on_timer_timeout) self.timer.start(500) @Slot(tuple) def on_state_change(self, data): old_state, self.state = data self.ui.packmlStateLabel.setText(STATES[self.state]) @Slot() def on_timer_timeout(self): self.uptime += .5 if self.state == S.EXECUTE: self.runtime += .5 uptime_string = convert_from_seconds_to_timestamp(self.uptime) runtime_string = convert_from_seconds_to_timestamp(self.runtime) self.ui.uptimeLabel.setText(uptime_string) self.ui.runtimeLabel.setText(runtime_string) self.total_count = self.r.get("total_count") self.update_OEE() self.update_order_status() self.update_light_tower() self.update_warnings() def update_order_status(self): orders_packed = self.r.get("total_count") order = self.r.get("current_order") or { "blue": 0, "red": 0, "yellow": 0, "id": "no order" } remaining_bricks = self.r.get("remaining_bricks") or { "blue": 0, "red": 0, "yellow": 0 } self.ui.ordersPackedLabel.setText(str(orders_packed)) self.ui.orderIDLabel.setText(str(order["id"])) self.ui.numBlueLabel.setText( str(order["blue"] - remaining_bricks["blue"]) + "/" + str(order["blue"])) self.ui.numRedLabel.setText( str(order["red"] - remaining_bricks["red"]) + "/" + str(order["red"])) self.ui.numYellowLabel.setText( str(order["yellow"] - remaining_bricks["yellow"]) + "/" + str(order["yellow"])) def update_light_tower(self): conf = light_tower.light_config[self.state] cond = (light_tower.FLASH, light_tower.SOLID) if self.light_tower_odd else ( light_tower.SOLID, ) self.light_tower_odd = not self.light_tower_odd on = [ conf.get(c, light_tower.OFF) in cond for c in light_tower.COLORS ] # g, y, r binary_str = "".join([str(int(b)) for b in reversed(on)]) # r, y, g img_path = "tower_states/{}.png".format(binary_str) img = QtGui.QImage(img_path) img = img.scaled(183, 281, aspectRatioMode=QtCore.Qt.KeepAspectRatio, transformMode=QtCore.Qt.SmoothTransformation) self.ui.lightTowerStatus.setPixmap(QtGui.QPixmap.fromImage(img)) def update_OEE(self): # Availability: availability = self.runtime / max(self.uptime, 1e-6) self.ui.availabilityLabel.setText("%0.2f" % availability) # Performance: total_count = self.r.get("total_count") or 0 ideal_cycle_time = 180 / 4 # 4 orders take 180 seconds approximately performance = ideal_cycle_time * total_count / max(self.runtime, 1e-6) self.ui.performanceLabel.setText("%0.2f" % performance) # Quality: good_count = total_count quality = good_count / (total_count or 1) self.ui.qualityLabel.setText("%0.2f" % quality) # OEE: OEE = availability * performance * quality self.ui.OEELabel.setText("%0.2f" % OEE) def update_warnings(self): w = Warnings(self.r) warnings = w.get_all_warnings() lines = ["Warnings:"] if warnings else [] for key, val in warnings.items(): lines.append("{}: {}".format(key, val)) text = "\n".join(lines) self.ui.warningLabel.setText(text)
#!/usr/bin/python3 from functools import partial from rtde_io import RTDEIOInterface from rtde_receive import RTDEReceiveInterface from rsd.utils.rsd_redis import RsdRedis from rsd import conf from rsd.utils.function_queue import FunctionQueue r = RsdRedis() ur_rcv = RTDEReceiveInterface(conf.UR_IP) ur_io = RTDEIOInterface(conf.UR_IP) io_fq = FunctionQueue() rcv_fq = FunctionQueue() # io r.subscribe("setStandardDigitalOut", partial(io_fq, ur_io.setStandardDigitalOut)) r.subscribe("setSpeedSlider", partial(io_fq, ur_io.setSpeedSlider)) r.service("setStandardDigitalOut", partial(io_fq, ur_io.setStandardDigitalOut)) r.service("setSpeedSlider", partial(io_fq, ur_io.setSpeedSlider)) # recv r.service("getActualQ", partial(rcv_fq, lambda x: ur_rcv.getActualQ())) r.service("getSafetyMode", partial(rcv_fq, lambda x: ur_rcv.getSafetyMode())) r.service("getRobotModes", partial(rcv_fq, lambda x: ur_rcv.getRobotModes()))