def test_set_trajectory(self): mypar = emotion.get_axis("mypar") mymot = emotion.get_axis("mymot") par_list = range(100) pos_list = range(100) mypar.set_parameter(par_list) mypar.set_trajectory(mymot, pos_list)
def test_set_trajectory_wrongrange(self): mypar = emotion.get_axis("mypar") mymot = emotion.get_axis("mymot") par_list = range(100) pos_list = range(10) mypar.set_parameter(par_list) self.assertRaises(ValueError, mypar.set_trajectory, mymot, pos_list)
def test_axes_creation(self): #log.level(log.INFO) mymot = emotion.get_axis("mot0") #log.level(log.ERROR) self.assertTrue(mymot) mymot2 = emotion.get_axis("mot1") self.assertTrue(mymot2)
def test_hardware_axes_preparation(self): # If motors are moving, the power can not be switched on # therefore hide exception mymot = emotion.get_axis("mymot") mymot2 = emotion.get_axis("mymot2") #mymot.controller.log_level(emotion.log.INFO) mymot.controller.stop(mymot) mymot2.controller.stop(mymot2) #mymot.controller.log_level(emotion.log.ERROR) # NOTE MP: 2015Mar17: the current eMotion doesn't call the # controller stop() if it doesn't know that a motion is taking # place on the hardware. Therefore bypass eMotion while mymot.state() == 'MOVING': gevent.sleep(0.1) while mymot2.state() == 'MOVING': gevent.sleep(0.1) # the IcePAP will move, therefore put it close to the # target position to avoid long wait mymot.dial(0) mymot.position(0) mymot2.dial(0) mymot2.position(0)
def test_group_move(self): robz = emotion.get_axis("robz") robz_pos = robz.position() roby = emotion.get_axis("roby") roby_pos = roby.position() self.assertEqual(self.grp.state(), "READY") target_robz = robz_pos + 50 target_roby = roby_pos + 50 self.grp.move( robz, target_robz, roby, target_roby, wait=False) self.assertEqual(self.grp.state(), "MOVING") self.assertEqual(robz.state(), "MOVING") self.assertEqual(roby.state(), "MOVING") self.grp.wait_move() self.assertEqual(robz.state(), "READY") self.assertEqual(roby.state(), "READY") self.assertEqual(self.grp.state(), "READY")
def test_static_move(self): roby = emotion.get_axis("roby") robz = emotion.get_axis("robz") p0 = self.grp.position() self.grp.rmove({ robz: 0, roby: 1}) self.assertEquals(self.grp.position()[robz], p0[robz]) self.assertEquals(self.grp.position()[roby], p0[roby]+1)
def testRealAxisIsRightObject(self): s1f = emotion.get_axis('s1f') m0 = emotion.get_axis('m0') s1ho = emotion.get_axis("s1ho") controller = s1ho.controller self.assertEquals(s1f.controller, m0.controller) self.assertEquals(s1f, controller.axes['s1f'])
def test_group_creation(self): # group creation mymot = emotion.get_axis("mymot") mymot2= emotion.get_axis("mymot2") mygrp = emotion.Group(mymot, mymot2) self.assertTrue(mygrp)
def test_load_trajectory(self): mypar = emotion.get_axis("mypar") mymot = emotion.get_axis("mymot") par_list = range(100) pos_list = [ x *10 for x in range(100) ] mypar.set_parameter(par_list) mypar.set_trajectory(mymot, pos_list) mypar.load()
def test_get_encoder(self): enc = emotion.get_encoder("m0enc") self.assertTrue(enc) self.assertEquals(enc.steps_per_unit, 50) m0 = emotion.get_axis("m0") self.assertEquals(m0.encoder, enc) m1 = emotion.get_axis("m1") self.assertEquals(m1.encoder, None)
def testVelocity(self): a1 = emotion.get_axis("a1") self.assertEquals(a1.velocity(1), 1) config_velocity = a1.config.get("velocity", int) self.assertEquals(a1.velocity(config_velocity), config_velocity) a2 = emotion.get_axis("a2") config_velocity = a2.config.get("velocity", int) self.assertEquals(a2.velocity(config_velocity), config_velocity)
def test_get_parameter_velocity(self): mypar = emotion.get_axis("mypar") mymot = emotion.get_axis("mymot") par_list = range(100) pos_list = range(100) mypar.set_parameter(par_list) mypar.set_trajectory(mymot, pos_list) mypar.load() vel = mypar.velocity()
def test_stop(self): roby = emotion.get_axis("roby") robz = emotion.get_axis("robz") self.assertEqual(robz.state(), "READY") self.grp.move({robz: 0, roby: 0}, wait=False) self.assertEqual(self.grp.state(), "MOVING") self.grp.stop() self.assertEqual(self.grp.state(), "READY") self.assertEqual(robz.state(), "READY") self.assertEqual(roby.state(), "READY")
def test_get_parameter_acctime(self): mypar = emotion.get_axis("mypar") mymot = emotion.get_axis("mymot") par_list = range(100) pos_list = range(100) mypar.set_parameter(par_list) mypar.set_trajectory(mymot, pos_list) mypar.load() acc = mypar.acctime()
def testPseudoAxisMove(self): s1b = emotion.get_axis("s1b") s1f = emotion.get_axis("s1f") s1hg = emotion.get_axis("s1hg") s1f.move(0) s1b.move(0) hgap = 0.5 s1hg.move(hgap) self.assertAlmostEquals(hgap, s1hg.position(), places=6)
def test_set_parameter_acctime(self): mypar = emotion.get_axis("mypar") mymot = emotion.get_axis("mymot") par_list = range(100) pos_list = range(100) mypar.set_parameter(par_list) mypar.set_trajectory(mymot, pos_list) mypar.load() acc = 0.250 self.assertEqual(mypar.acctime(acc), acc)
def test_group_get_position(self): # group creation mymot = emotion.get_axis("mymot") mymot2= emotion.get_axis("mymot2") mygrp = emotion.Group(mymot, mymot2) #mymot.controller.log_level(3) pos_list = mygrp.position() #mymot.controller.log_level(3) for axis in pos_list: self.assertEqual(axis.position(), pos_list[axis])
def testMovePseudo(self): m1 = emotion.get_axis("m1") m0 = emotion.get_axis("m0") p1 = m1.position() p0 = m0.position() m1.rmove(2) self.assertEquals(p1 + 2, m1.position()) self.assertEquals(m0.position(), p0 + 1) m1.rmove(-2) self.assertEquals(p0, m0.position()) self.assertEquals(m1.position(), p1)
def test_ctrlc(self): roby = emotion.get_axis("roby") robz = emotion.get_axis("robz") self.assertEqual(robz.state(), "READY") self.grp.rmove({robz: -10, roby: -10}, wait=False) time.sleep(0.01) self.grp._Group__move_task.kill(KeyboardInterrupt, block=False) self.assertRaises(KeyboardInterrupt, self.grp.wait_move) self.assertEqual(self.grp.state(), "READY") self.assertEqual(robz.state(), "READY") self.assertEqual(roby.state(), "READY")
def testMoveReal(self): m1 = emotion.get_axis("m1") m0 = emotion.get_axis("m0") p1 = m1.position() p0 = m0.position() m0.rmove(1) self.assertEquals(p0 + 1, m0.position()) self.assertEquals(m1.position(), p1 + 2) m0.rmove(-1) self.assertEquals(p0, m0.position()) self.assertEquals(m1.position(), p1)
def test_group_move(self): # group creation mymot = emotion.get_axis("mymot") mymot2= emotion.get_axis("mymot2") mygrp = emotion.Group(mymot, mymot2) pos_list = mygrp.position() pos_list[mymot] += 0.1 # waits for the end of motions mygrp.move(pos_list) self.assertEqual(mygrp.state(), "READY")
def testPosition(self): a1 = emotion.get_axis("a1") a2 = emotion.get_axis("a2") self.assertAlmostEqual(a2.position(), 0.2, places=5) for a in (a1, a2): p0 = a.position() target = p0 + 0.1 a.move(target) self.assertAlmostEqual(a.position(), target, places=5) a.move(p0 - 0.1) self.assertAlmostEqual(a.position(), p0 - 0.1, places=5)
def testSimultaneousMove(self): a1 = emotion.get_axis("a1") a2 = emotion.get_axis("a2") p1 = a1.position() p2 = a2.position() a1.rmove(0.1, wait=False) self.assertRaises(RuntimeError, a2.rmove, 0.1, wait=False) a1.wait_move() a2.wait_move() self.assertEquals(a1.position(), p1 + 0.1) self.assertEquals(a2.position(), p2) a1.rmove(-0.1) self.assertEquals(a1.position(), p1)
def test_bad_startone(self): roby = emotion.get_axis("roby") robz = emotion.get_axis("roby") roby.dial(0); roby.position(0) robz.dial(0); robz.position(0) try: roby.controller.set_error(True) self.assertRaises(RuntimeError, self.grp.move, { robz: 1, roby: 2 }) self.assertEquals(self.grp.state(), "READY") self.assertEquals(roby.position(), 0) self.assertEquals(robz.position(), 0) finally: roby.controller.set_error(False)
def initialize_axis(self, axis): """Axis initialization""" self.log_info("initialize_axis() called for axis %r" % axis.name) # Get the list of IcePAP axes axes_names = axis.config.get("axislist").split() if len(axes_names) == 0: raise ValueError('missing mandatory config parameter "axislist"') # Check the list of IcePAP axes dev = None for axis_name in axes_names: # Get EMotion axis object hw_axis = emotion.get_axis(axis_name) # Check that it's an IcePAP controlled one if type(hw_axis.controller).__name__ is not 'IcePAP': raise ValueError('invalid axis "%s", not an IcePAP'%axis_name) # Get underlying libicepap object axis_dev = hw_axis.controller.libdevice if dev is None: dev = axis_dev # Let's impone that the trajectories work only on the same system if axis_dev.hostname() != dev.hostname(): raise ValueError( 'invalid axis "%s", not on the same IcePAP'%axis_name) # At this point we have configuration # Create an empty libicepap trajectory object self.libtraj[axis] = libicepap.Trajectory(axis.name) # Keep a record of axes for axis_name in axes_names: self.axes_names.append(axis_name) hw_axis = emotion.get_axis(axis_name) self.axis_list[axis_name] = hw_axis # Keep a record of the IcePAP system for faster access self.libdevice = dev # Add new axis oject methods add_axis_method(axis, self.set_parameter) add_axis_method(axis, self.get_parameter) add_axis_method(axis, self.set_trajectory) add_axis_method(axis, self.drain) add_axis_method(axis, self.load) add_axis_method(axis, self.sync)
def test_maxee(self): m1 = emotion.get_axis("m1") m1.move(1) self.assertEquals(m1.position(), 1) m0 = emotion.get_axis("m0") m0.dial(0); m0.position(0) self.assertRaises(RuntimeError, m0.move, 1) enc = emotion.get_encoder("m0enc") enc.set(2) m0.move(2) self.assertEquals(m0.position(), 2)
def test_bad_startall(self): robz = emotion.get_axis("robz") robz2 = emotion.get_axis("robz2") robz2.dial(0); robz2.position(0) robz.dial(0); robz.position(0) grp = emotion.Group(robz, robz2) try: robz.controller.set_error(True) self.assertRaises(RuntimeError, grp.move, { robz: 1, robz2: 2}) self.assertEquals(grp.state(), "READY") self.assertEquals(robz2.position(), 0) self.assertEquals(robz.position(), 0) finally: robz.controller.set_error(False)
def test_group_stop(self): # group creation mymot = emotion.get_axis("mymot") mymot2= emotion.get_axis("mymot2") mygrp = emotion.Group(mymot, mymot2) pos_list = mygrp.position() pos_list[mymot] -= 0.1 # non blocking call mygrp.move(pos_list, wait=False) # waits for the end of motions mygrp.stop() self.assertEqual(mygrp.state(), "READY")
def test_move_done_event(self): res = {"ok": False} def callback(move_done, res=res): if move_done: res["ok"] = True roby = emotion.get_axis("roby") roby_pos = roby.position() robz = emotion.get_axis("robz") robz_pos = robz.position() event.connect(self.grp, "move_done", callback) self.grp.rmove({robz: 2, roby: 3}) self.assertEquals(res["ok"], True) self.assertEquals(robz.position(), robz_pos+2) self.assertEquals(roby.position(), roby_pos+3)
def test_axis_get_measured_position(self): roby = emotion.get_axis("roby") roby.custom_simulate_measured(True) _meas_pos = -1.2345 self.assertAlmostEqual( roby.measured_position(), _meas_pos, places=4, msg=None) roby.custom_simulate_measured(False)
def init(self): self.motorState = EmotionMotor.NOTINITIALIZED self.username = self.motor_name EmotionMotor.load_config(self.config_file) self.motor = emotion.get_axis(self.motor_name) self.connect(self.motor, "position", self.positionChanged) self.connect(self.motor, "state", self.updateState) self.connect(self.motor, "move_done", self._move_done)
def init(self): self.motorState = EmotionMotor.NOTINITIALIZED self.username = self.motor_name try: EmotionMotor.load_config(self.config_file) except AttributeError: emotion.config.set_backend("beacon") self.motor = emotion.get_axis(self.motor_name) self.connect(self.motor, "position", self.positionChanged) self.connect(self.motor, "state", self.updateState) self.connect(self.motor, "move_done", self._move_done)