def state(self): if self.is_moving: return AxisState("MOVING") grp_state = AxisState("READY") for i, (name, state) in enumerate([ (axis.name, axis.state()) for axis in self._axes.itervalues() ]): if state.MOVING: new_state = "MOVING" + " " * i grp_state.create_state( new_state, "%s: %s" % (name, grp_state._state_desc["MOVING"])) grp_state.set("MOVING") grp_state.set(new_state) for axis_state in state._current_states: if axis_state == "READY": continue new_state = axis_state + " " * i grp_state.create_state( new_state, "%s: %s" % (name, state._state_desc[axis_state])) grp_state.set(new_state) return grp_state
def state(self, axis): """ PM600 status = "abcdefgh" where: a is 0 = Busy or 1 = Idle b is 0 = OK or 1 = Error (abort, tracking, stall, timeout etc.) c is 0 = Upper hard limit is OFF or 1 = Upper hard limit is ON d is 0 = Lower hard limit is OFF or 1 = Lower hard limit is ON e is 0 = Not jogging or joystick moving or 1 = Jogging or joystick moving f is 0 = Not at datum sensor point or 1 = On datum sensor point g is 0 = Future use or 1 = Future use h is 0 = Future use or 1 = Future use """ log.debug("state() called") status = self.io_command("OS", axis.channel) log.debug("state() status:" + status) if status[1:2] == '1' or (status[2:3] == '1' and status[3:4] == '1'): log.debug("state() is fault") return AxisState("FAULT") if status[2:3] == '1': log.debug("state() is positive limit") return AxisState("LIMPOS") if status[3:4] == '1': log.debug("state() is negative limit") return AxisState("LIMNEG") if status[0:1] == '0': log.debug("state() is moving") return AxisState("MOVING") else: log.debug("state() is ready") return AxisState("READY")
def home_state(self, axis): _home_query_cmd = "%sQF1" % axis.channel _ans = self._flexdc_query(_home_query_cmd) if _ans == "1": return AxisState("MOVING") else: return AxisState("READY")
def state(self, axis): _state = self.axis_proxy.state() if _state == DevState.ON: return AxisState("READY") elif _state == DevState.MOVING: return AxisState("MOVING") else: return AxisState("READY")
def state(self, axis): if self._get_closed_loop_status(axis): if self._get_on_target_status(axis): return AxisState("READY") else: return AxisState("MOVING") else: raise RuntimeError("closed loop disabled")
def state(self, axis): sta = self._write_read(axis, "STA", eol='\r\n>', raw=True) for line in sta.split("\n"): if line.startswith(axis.driver): status_byte = int(line.split("=")[-1], 16) if status_byte & 0x0000001: return AxisState("MOVING") else: return AxisState("READY")
def test_from_current_states_str(): s = AxisState(("KAPUT", "auf"), "LIMNEG", "READY") states_str = s.current_states() t = AxisState(states_str) assert t.READY assert t._state_desc["KAPUT"] == "auf" assert t._state_desc["LIMNEG"] == "Hardware low limit active" assert s.current_states() == t.current_states() u = AxisState() v = AxisState(u.current_states()) assert u.current_states() == v.current_states()
def state(self, axis): elog.debug("in state(%s)" % axis.name) # _ref = self._get_referencing(axis) # if _ref == 0: # return AxisState(("UNREFERENCED","axis need to be referenced before a motion to be possible")) if self._get_on_target_status(axis): return AxisState("READY") else: return AxisState("MOVING")
def state(self, axis): # if self._get_closed_loop_status(axis): if self.closed_loop: # elog.debug("CLOSED-LOOP is active") if self._get_on_target_status(axis): return AxisState("READY") else: return AxisState("MOVING") else: elog.debug("CLOSED-LOOP is not active") return AxisState("READY")
def state(self, axis): sta = int(self._galil_query("TS%s" % axis.channel)) if sta & (1 << 7): return AxisState("MOVING") ''' elif sta & (1<<6): # on limit return elif sta & (1<<5): # motor off return AxisState("READY") ''' return AxisState("READY")
def _check_hw_limits(self, axis): ll, hl = self.__hw_limit pos = self.read_position(axis) if ll is not None and pos <= ll: return AxisState("READY", "LIMNEG") elif hl is not None and pos >= hl: return AxisState("READY", "LIMPOS") if self._hw_state == "OFF": return AxisState("OFF") else: s = AxisState(self._hw_state) s.set("READY") return s
def state(self, axis): elog.debug("axis.closed_loop for axis %s is %s" % (axis.name, axis.closed_loop)) if axis.closed_loop: if self._get_on_target_status(axis): return AxisState("READY") else: return AxisState("MOVING") else: elog.debug("CLOSED-LOOP is False") # ok for open loop mode... return AxisState("READY")
def __init__(self, *args, **kwargs): Controller.__init__(self, *args, **kwargs) self._axis_moves = {} self.__encoders = {} # Custom attributes. self.__voltages = {} self.__cust_attr_float = {} self.__error_mode = False self._hw_state = AxisState("READY") self.__hw_limit = (None, None) self._hw_state.create_state("PARKED", "mot au parking") # Access to the config. try: self.host = self.config.get("host") except: elog.debug("no 'host' defined in config for %s" % self.name) # Adds Mockup-specific settings. self.axis_settings.add('init_count', int) self.axis_settings.add('hw_position', float)
def test_custom_state(): s = AxisState() s.set("READY") s.create_state("PARKED", "here I am") s.set("PARKED") assert s.READY assert s == "PARKED"
def test_clear_state(): s = AxisState("READY") s.clear() assert s == "UNKNOWN" s.set("MOVING") assert s == "MOVING"
def state(self, axis): mot_num = axis.config.get("channel", int) #print 'calling state for',mot_num if self.usb_controller.curr_move and not self.usb_controller.curr_move.ready( ): return AxisState("MOVING") mot_group = self.usb_controller.read_mot_pos_status(mot_num) for mot, pos, state in mot_group: if mot == mot_num: if state & self.usb_controller.MOT_STA_MOV: return AxisState("MOVING") elif state & self.usb_controller.MOT_STA_LIMN: return AxisState("READY", "LIMNEG") elif state & self.usb_controller.MOT_STA_LIMP: return AxisState("READY", "LIMPOS") else: return AxisState("READY")
def state(self, axis): if self._axis_moves[axis]["end_t"] > time.time(): return AxisState("MOVING") else: self.read_position(axis, t=self._axis_moves[axis]["end_t"]) self._axis_moves[axis]["end_t"] = None self._axis_moves[axis]["delta"] = 0 return self._check_hw_limits(axis)
def test_mutually_exclusive(): s = AxisState() s.set("MOVING") assert s == "MOVING" assert not s.READY s.set("READY") assert s.READY assert not s.MOVING
def initialize(self): hostname = self.config.get("host") self._cnx = Command(hostname, 5000, eol='\n') self._icestate = AxisState() self._icestate.create_state("POWEROFF", "motor power is off") for codes in (self.STATUS_DISCODE, self.STATUS_MODCODE, self.STATUS_STOPCODE): for state, desc in codes.values(): self._icestate.create_state(state, desc)
def state(self, axis): status = self.protocol().system_status state = 'READY' if status.moving: state = 'MOVING' if not status.control: state = 'OFF' if status.error: state = 'FAULT' state = AxisState(state) return state
def state(self, axis): _ret = 0 # Motion Status : MS command # bit 0 : 0x01 : In motion. # bit 1 : 0x02 : In stop. # bit 2 : 0x04 : In acceleration. # bit 3 : 0x08 : In deceleration. # bit 4 : 0x10 : Waiting for input to start motion. # bit 5 : 0x20 : In PTP stop (decelerating to target). # bit 6 : 0x40 : Waiting for end of WT period. _ansMS = int(self._flexdc_query("%sMS" % axis.channel)) if(_ansMS & 0x01): _ret = AxisState("MOVING") else: _ret = AxisState("READY") elog.debug("state : %s" % _ret) return _ret
def motor_state(self, axis): _s = hex_to_int(self._axes_status[axis.channel]) elog.debug("axis %d status : %s" % (axis.channel, self._axes_status[axis.channel])) if self.s_is_parked(_s): return AxisState("OFF") # running means position is corrected, related to closed loop # we just check if target position was reached if self.s_is_closed_loop(_s): if self.s_is_position_reached(_s): return AxisState("READY") else: return AxisState("MOVING") else: if self.s_is_moving(_s): return AxisState("MOVING") else: return AxisState("READY")
def initialize(self): config = self.config.config_dict if get_comm_type(config) == UDP: opt = {'port': 5001, 'eol': ';'} else: # SERIAL opt = {'baudrate': 115200, 'eol': ';'} self._cnx = get_comm(config, **opt) self._elmostate = AxisState() for state, human in (('SLAVESWITCH', 'Slave switch activate'), ('INHIBITSWITCH', 'Inhibit switch active'), ('CLOSEDLOOPOPEN', 'Closed loop open'), ('DRIVEFAULT', 'Problem into the drive')): self._elmostate.create_state(state, human)
def state(self, axis): _ans = self.send(axis, "?STATE") if _ans == "READY": return AxisState("READY") elif _ans == "LWAITING": return AxisState("MOVING") elif _ans == "LRUNNING": return AxisState("MOVING") elif _ans == "PWAITING": return AxisState("MOVING") elif _ans == "PRUNNING": return AxisState("MOVING") else: return AxisState("FAULT")
def start_one(self, motion): self.log.info( '\n\n\n' + '###########################################################################\n' + '--PJ--start_one : motion: target_pos={0:g} delta={1:g}\n'.format( motion.target_pos, motion.delta) + '###########################################################################\n\n\n' ) if self._move_task is None or self._move_task.ready(): # To be sure state is correct even if movement hasn't started. self._hw_status = AxisState('MOVING') # Movement greenlet starting point. self._move_task = self._do_move(motion, wait=False) # At end of the move task, just call _move_done() function. self._move_task.link(self._move_done) else: raise RuntimeError("cannot move, previous task is not finished")
def state(self, axis): sta = self._execute(axis, "MD?") if sta == '0': return AxisState("MOVING") else: return AxisState("READY")
def home_state(self, axis): if (time.time() - self._axis_moves[axis]["home_search_start_time"]) > 2: return AxisState("READY") else: return AxisState("MOVING")
def state(self, axis): state = self._exporter.execute(self.state_cmd, axis.root_name) return AxisState(state.upper())
def state(self, axis): _ans = "whatever" if _ans == "moving": return AxisState("MOVING") else: return AxisState("READY")
def initialize_axis(self, axis): """ - Reads specific config - Adds specific methods - Switches piezo to ONLINE mode so that axis motion can be caused by move commands. Args: - <axis> Returns: - None """ elog.info("initialize_axis() called for axis %r" % axis.name) self._hw_status = AxisState("READY") """ Documentation uses the word AxisID instead of channel Note: any function used as axis method must accept axis as an argument! Otherwise you will see: TypeError: check_power_cut() takes exactly 1 argument (2 given) """ axis.channel = axis.config.get("channel", int) try: axis.paranoia_mode = axis.config.get( "paranoia_mode") # check error after each command except KeyError: axis.paranoia_mode = False self._gate_enabled = False # Updates cached value of closed loop status. axis.closed_loop = self._get_closed_loop_status(axis) self.check_power_cut() elog.debug("axis = %r" % axis.name) #elog.debug("axis.encoder = %r" % axis.encoder) #if axis.encoder: #elog.debug("axis = %r" % axis) #POSSIBLE DATA RECORDER TYPE axis.TARGET_POSITION_OF_AXIS = 1 axis.CURRENT_POSITION_OF_AXIS = 2 axis.POSITION_ERROR_OF_AXIS = 3 axis.CONTROL_VOLTAGE_OF_OUTPUT_CHAN = 7 axis.DDL_OUTPUT_OF_AXIS = 13 axis.OPEN_LOOP_CONTROL_OF_AXIS = 14 axis.CONTROL_OUTPUT_OF_AXIS = 15 axis.VOLTAGE_OF_OUTPUT_CHAN = 16 axis.SENSOR_NORMALIZED_OF_INPUT_CHAN = 17 axis.SENSOR_FILTERED_OF_INPUT_CHAN = 18 axis.SENSOR_ELECLINEAR_OF_INPUT_CHAN = 19 axis.SENSOR_MECHLINEAR_OF_INPUT_CHAN = 20 axis.SLOWED_TARGET_OF_AXIS = 22 #POSSIBLE DATA TRIGGER SOURCE axis.WAVEFORM = 0 axis.MOTION = 1 axis.EXTERNAL = 3 axis.IMMEDIATELY = 4 # supposed that we are on target on init axis._last_on_target = True