def test_write_real(): print("Testing acsc.writeReal") hc = acsc.openCommDirect() varname = "SLLIMIT1" val = 3.14 acsc.writeReal(hc, varname, val) valread = acsc.readReal(hc, None, varname) acsc.closeComm(hc) print("Input value:", val) print("Value read:", valread) assert valread == val print("PASS")
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)
import numpy as np import time import matplotlib.pyplot as plt plt.close("all") dblen = 100 sr = 200.0 sleeptime = dblen/sr/2*1.05 t = np.array([]) data = np.array([]) # Connect to controller hc = acsc.openCommDirect() # 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()
def connect(self, address=None): if self.contype == "simulator": self.hc = acsc.openCommDirect() elif self.contype == "ethernet": self.hc = acsc.openCommEthernetTCP(address="10.0.0.100", port=701)
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)
def connect(self, address="10.0.0.100", port=701): if self.contype == "simulator": self.hc = acsc.openCommDirect() elif self.contype == "ethernet": self.hc = acsc.openCommEthernetTCP(address=address, port=port)
def __init__(self, parent=None): QtGui.QMainWindow.__init__(self) self.ui = Ui_MainWindow() self.ui.setupUi(self) # Set up some parameters self.axis = 5 self.homecounter = 0 self.jogmode = False self.leftlimit = 24.9 self.platform = 9.0 self.override = False self.axis_enabled = False # Set maximum velocities to 2 m/s self.ui.velSpinBox.setMaximum(2.0) self.ui.velSpinBox_baf1.setMaximum(2.0) self.ui.velSpinBox_baf2.setMaximum(2.0) # Set initial states of all buttons self.ui.rbAbsolute.setEnabled(False) self.ui.rbAbsolute_baf.setEnabled(False) self.ui.enableAxis.setEnabled(False) self.ui.actionRunHoming.setEnabled(False) self.ui.dock_jog.setEnabled(False) self.ui.groupBox_shortcuts.setEnabled(False) self.ui.tabWidgetMode.setEnabled(False) self.ui.toolBar_Jog.setEnabled(False) self.ui.enableAxis.setIcon(QIcon()) self.ui.posSpinBox.setMinimum(-self.leftlimit) self.ui.posSpinBox.setMaximum(self.leftlimit) self.ui.posSpinBox_baf1.setMinimum(-self.leftlimit) self.ui.posSpinBox_baf1.setMaximum(self.leftlimit) self.ui.posSpinBox_baf2.setMinimum(-self.leftlimit) self.ui.posSpinBox_baf2.setMaximum(self.leftlimit) self.ui.posSpinBox_baf2.setDisabled(True) # Add some labels to the status bar self.hlabel = QLabel() self.hlabel.setText("Not homed ") self.ui.statusBar.addWidget(self.hlabel) self.poslabel = QLabel() self.poslabel.setText("Pos. (m): ") self.ui.statusBar.addWidget(self.poslabel) self.vellabel = QLabel() self.vellabel.setText("Vel. (m/s): ") self.ui.statusBar.addWidget(self.vellabel) # Add a button to the toolbar self.ui.toolBar_Jog.addWidget(self.ui.pbJogPlus) self.ui.toolBar_Jog.addWidget(self.ui.pbJogMinus) self.ui.pbJogMinus.setFixedHeight(27) self.ui.pbJogPlus.setFixedHeight(27) self.ui.pbJogMinus.setFixedWidth(32) self.ui.pbJogPlus.setFixedWidth(32) self.ui.dock_jog.close() # Set up timers self.timer_slow = QTimer() self.timer_slow.timeout.connect(self.on_timer_slow) self.timer_fast = QTimer() self.timer_fast.timeout.connect(self.on_timer_fast) # Connect to the controller self.simulator = False self.retry = True if self.simulator: self.hcomm = acsc.openCommDirect() else: self.hcomm = acsc.openCommEthernetTCP("10.0.0.100", 701) # If connection fails, bring up error message box while self.hcomm == acsc.INVALID and self.retry: msgtxt = "Unable to connect to controller.\n\n" msgtxt += "Check that controller is powered-on and " msgtxt += "SPiiPlus User Mode Driver is running." c_err_box = QMessageBox() c_err_box.setIcon(QMessageBox.Critical) c_err_box.setWindowIcon(QIcon(':/icons/tow_icon.svg')) c_err_box.setWindowTitle("Connection Error") c_err_box.setText(msgtxt) c_err_box.setStandardButtons(QMessageBox.Retry | QMessageBox.Abort) c_err_box.setDefaultButton(QMessageBox.Retry) c_err_box.addButton("Use &Simulator", QMessageBox.AcceptRole) ret = c_err_box.exec_() if ret == QMessageBox.Retry: if self.simulator: self.hcomm = acsc.openCommDirect() else: self.hcomm = acsc.openCommEthernetTCP("10.0.0.100", 701) elif ret == QMessageBox.Abort: self.connectfail = True self.retry = False self.timer_fast.start(10) elif ret == QMessageBox.AcceptRole: self.simulator = True self.hcomm = acsc.openCommDirect() if self.hcomm != acsc.INVALID: self.timer_slow.start(150) self.timer_fast.start(50) self.ui.enableAxis.setEnabled(True) self.ui.actionRunHoming.setEnabled(True) # Register the emergency stop button acsc.registerEmergencyStop() # Make sure jog program is not running acsc.stopBuffer(self.hcomm, 5) # Create the jog group action group self.offset_group = QActionGroup(self) self.ui.traverseOff.setActionGroup(self.offset_group) self.ui.traverse1m.setActionGroup(self.offset_group) self.ui.traverse2m.setActionGroup(self.offset_group) self.ui.traverse3m.setActionGroup(self.offset_group) self.ui.traverse4m.setActionGroup(self.offset_group) self.traverse_offset_actions = {"off": self.ui.traverseOff, "1m": self.ui.traverse1m, "2m": self.ui.traverse2m, "3m": self.ui.traverse3m, "4m": self.ui.traverse4m} # Create TCP server for remote control remoteserver = QtNetwork.QTcpServer() print(str(remoteserver.serverAddress().toString())) # Connect signals and slots self.connectslots() # Load settings self.load_settings()