def on_go_baf(self): """Do a back-and-forth move.""" p1 = self.ui.posSpinBox_baf1.value() v1 = self.ui.velSpinBox_baf1.value() v2 = self.ui.velSpinBox_baf2.value() a1 = self.ui.accSpinBox_baf1.value() a2 = self.ui.accSpinBox_baf2.value() if self.ui.rbRelative_baf.isChecked(): relflag = "r" p2 = -p1 else: relflag = "" p2 = self.ui.posSpinBox_baf2.value() txt = "GLOBAL INT move\n" txt += "JERK({}) = 1\n".format(self.axis) txt += "move = 1\n" txt += "WHILE move\n" txt += " ACC({}) = {}\n".format(self.axis, a1) txt += " DEC({}) = {}\n".format(self.axis, a1) txt += " VEL({}) = {}\n".format(self.axis, v1) txt += " ptp/e{} {}, {}\n".format(relflag, self.axis, p1) txt += " ACC({}) = {}\n".format(self.axis, a2) txt += " DEC({}) = {}\n".format(self.axis, a2) txt += " VEL({}) = {}\n".format(self.axis, v2) txt += " ptp/e{} {}, {}\n".format(relflag, self.axis, p2) if not self.ui.checkBox_loop.isChecked(): txt += " move = 0\n" txt += "END\n" txt += "STOP\n" acsc.loadBuffer(self.hcomm, 19, txt, 512) acsc.runBuffer(self.hcomm, 19)
def start_motion(self): self.acsdaqthread.start() nbuf = 19 acsc.loadBuffer(self.hc, nbuf, self.acs_prg, 2048) acsc.enable(self.hc, 4) acsc.runBuffer(self.hc, nbuf) prgstate = acsc.getProgramState(self.hc, nbuf) while prgstate == 3: time.sleep(0.3) prgstate = acsc.getProgramState(self.hc, nbuf) self.acsdaqthread.stop() self.daqthread.clear() self.runfinished.emit()
def test_upload_prg(): """Test that a program can be uploaded and run in the simulator.""" hc = acsc.openCommDirect() txt = "enable 0\nVEL(0) = 1333\nptp 0, 1.33\nSTOP" acsc.loadBuffer(hc, 19, txt, 64) acsc.runBuffer(hc, 19) time.sleep(0.2) vel = acsc.getVelocity(hc, 0) pos = acsc.getRPosition(hc, 0) print("Position:", pos) print("Velocity:", vel) assert vel == 1333.0 assert pos == 1.33 acsc.closeComm(hc)
def start_motion(self): self.acsdaqthread.start() nbuf = 19 acsc.loadBuffer(self.hc, nbuf, self.acs_prg, 2048) acsc.enable(self.hc, 4) acsc.enable(self.hc, 5) acsc.runBuffer(self.hc, nbuf) prgstate = acsc.getProgramState(self.hc, nbuf) while prgstate == 3: time.sleep(0.3) prgstate = acsc.getProgramState(self.hc, nbuf) self.acsdaqthread.stop() if self.nidaq: self.daqthread.clear() print("NI tasks cleared") if self.fbg: self.fbgthread.stop() if self.vectrino: if self.settling: # Wait 10 minutes to measure tank settling time print("Waiting 10 minutes") t0 = time.time() dt = 0.0 while not self.aborted and dt < 600: time.sleep(0.5) dt = time.time() - t0 if self.recordvno: self.vec.stop_disk_recording() self.vec.stop() self.vec.disconnect() print("Tow finished") if self.vectrino: if self.vec.state == "Not connected": self.vecstatus = "Vectrino disconnected " print("Resetting Vectrino") self.reset_vec() self.towfinished.emit()
def run(self): if self.makeprg: self.makedaqprg() acsc.loadBuffer(self.hc, 19, self.prg, 1024) acsc.runBuffer(self.hc, 19) collect = acsc.readInteger(self.hc, acsc.NONE, "collect_data") while collect == 0: time.sleep(0.01) collect = acsc.readInteger(self.hc, acsc.NONE, "collect_data") while self.collectdata: time.sleep(self.sleeptime) t0 = acsc.readReal(self.hc, acsc.NONE, "start_time") newdata = acsc.readReal(self.hc, acsc.NONE, "data", 0, 2, 0, self.dblen//2-1) t = (newdata[0] - t0)/1000.0 self.data["time"] = np.append(self.data["time"], t) self.data["carriage_vel"] = np.append(self.data["carriage_vel"], newdata[1]) self.data["turbine_rpm"] = np.append(self.data["turbine_rpm"], newdata[2]) time.sleep(self.sleeptime) newdata = acsc.readReal(self.hc, acsc.NONE, "data", 0, 2, self.dblen//2, self.dblen-1) t = (newdata[0] - t0)/1000.0 self.data["time"] = np.append(self.data["time"], t) self.data["time"] = self.data["time"] - self.data["time"][0] self.data["carriage_vel"] = np.append(self.data["carriage_vel"], newdata[1]) self.data["turbine_rpm"] = np.append(self.data["turbine_rpm"], newdata[2])
# Create an ACSPL+ program to load into the controller prg = prgs.ACSPLplusPrg() prg.declare_2darray("global", "real", "data", 2, dblen) prg.addline("global real foo") prg.addline("foo = 6.5") prg.addline("ENABLE 0") prg.add_dc("data", dblen, sr, "TIME, FVEL(0)", "/c") for n in xrange(3): prg.addptp(0, 10000, "/e") prg.addptp(0, 0, "/e") prg.addline("WAIT 10000") prg.addline("STOPDC") prg.addstopline() acsc.setAcceleration(hc, 0, 10000) acsc.loadBuffer(hc, 0, prg, 1024) acsc.runBuffer(hc, 0) astate = acsc.getAxisState(hc, 0) #print astate for n in xrange(3): time.sleep(sleeptime) newdata = acsc.readReal(hc, acsc.NONE, "data", 0, 1, 0, dblen/2-1) print acsc.readInteger(hc, acsc.NONE, "S_DCN") t = np.append(t, newdata[0]) data = np.append(data, newdata[1]) time.sleep(sleeptime) newdata = acsc.readReal(hc, acsc.NONE, "data", 0, 1, dblen/2, dblen-1) t = np.append(t, newdata[0]) data = np.append(data, newdata[1])
then uploading it to the controller and running it. """ from __future__ import division, print_function from acspy import acsc import time #file = open("test/test.prg", "w+") acs_prg = """ ENABLE 1""" + \ """ VEL(1) = 1000 PTP/r 1, -900 STOP """ #file.write(acs_prg) #file.close() print(acs_prg) hc = acsc.openCommDirect() acsc.loadBuffer(hc, 0, acs_prg, 512) acsc.enable(hc, 0) #acsc.LoadBuffersFromFile(hc, "test/test.prg") acsc.runBuffer(hc, 0) time.sleep(1) print(acsc.getRPosition(hc, 1)) print(acsc.getMotorState(hc, 1)) acsc.closeComm(hc)
# Create an ACSPL+ program to load into the controller prg = prgs.ACSPLplusPrg() prg.declare_2darray("global", "real", "data", 2, dblen) prg.addline("global real foo") prg.addline("foo = 6.5") prg.addline("ENABLE 0") prg.add_dc("data", dblen, sr, "TIME, FVEL(0)", "/c") for n in range(3): prg.addptp(0, 10000, "/e") prg.addptp(0, 0, "/e") prg.addline("WAIT 10000") prg.addline("STOPDC") prg.addstopline() acsc.setAcceleration(hc, 0, 10000) acsc.loadBuffer(hc, 0, prg, 1024) acsc.runBuffer(hc, 0) astate = acsc.getAxisState(hc, 0) #print astate for n in range(3): time.sleep(sleeptime) newdata = acsc.readReal(hc, acsc.NONE, "data", 0, 1, 0, dblen / 2 - 1) print(acsc.readInteger(hc, acsc.NONE, "S_DCN")) t = np.append(t, newdata[0]) data = np.append(data, newdata[1]) time.sleep(sleeptime) newdata = acsc.readReal(hc, acsc.NONE, "data", 0, 1, dblen / 2, dblen - 1) t = np.append(t, newdata[0]) data = np.append(data, newdata[1])
""" This is a test for generating an ACSPL+ program then uploading it to the controller and running it. """ from acspy import acsc import time #file = open("test/test.prg", "w+") acs_prg = """ ENABLE 1""" + \ """ VEL(1) = 1000 PTP/r 1, -900 STOP """ #file.write(acs_prg) #file.close() print acs_prg hc = acsc.openCommDirect() acsc.loadBuffer(hc, 0, acs_prg, 512) acsc.enable(hc, 0) #acsc.LoadBuffersFromFile(hc, "test/test.prg") acsc.runBuffer(hc, 0) time.sleep(1) print acsc.getRPosition(hc, 1) print acsc.getMotorState(hc, 1) acsc.closeComm(hc)