def __init__(self): QDialog.__init__(self) # setup UI self.form = QFormLayout(self) self.editPosition = QLineEdit('') self.form.addRow(QLabel('Position'), self.editPosition) self.editVelocity = QLineEdit('') self.form.addRow(QLabel('Velocity'), self.editVelocity) # configure network (take first available servo) self._net, self._servo = il.lucky(il.NET_PROT.EUSB) # create data model model = QStandardItemModel() pos = QStandardItem() vel = QStandardItem() model.appendRow([pos, vel]) # configure and start watcher self._watcher = RegisterWatcher(self._servo) self._watcher.add(POS_ACT, 500, pos) self._watcher.add(VEL_ACT, 100, vel) self._watcher.start(100) # map model fields to widgets self._mapper = QDataWidgetMapper() self._mapper.setModel(model) self._mapper.addMapping(self.editPosition, 0) self._mapper.addMapping(self.editVelocity, 1) self._mapper.toFirst()
def slave_connection(): # Connection servo = None # r = il.servo.servo_is_connected("192.168.2.22", port_ip=1061, protocol=2) # print("Result: ", r) # return r try: net, servo = il.lucky(il.NET_PROT.ETH, "eve-net_1.6.1.xdf", address_ip='192.168.2.22', port_ip=1061, protocol=1) # print(r) print("GAS") except Exception as e: print("Error trying to connect to the servo.", str(e)) if servo is not None: regg = servo.dict.get_regs(1)['COMMU_ANGLE_OFFSET'] print(servo.dict.subnodes) print('COMMU_ANGLE_OFFSET 1:', servo.raw_read('COMMU_ANGLE_OFFSET', subnode=1)) print(servo.dict.get_regs(1)['COMMU_ANGLE_OFFSET'].range) print('CL_CUR_B_REF_VALUE 1:', servo.raw_read('CL_CUR_B_REF_VALUE', subnode=1), 'A') print(servo.dict.get_regs(1)['CL_CUR_B_REF_VALUE'].range) print('CL_VEL_REF_VALUE 1:', servo.raw_read('CL_VEL_REF_VALUE', subnode=1), 'A') print(servo.dict.get_regs(1)['CL_VEL_REF_VALUE'].range)
def test_read_write(): net, servo = il.lucky(il.NET_PROT.MCB, "xcore-enums.xml") print("TESTING U32 REGISTER:") print("=====================") for i in range(0, 6): servo.dict_load("xcore-enums-1.xml") servo.dict_storage_write() print("Print brake post delay register") value = servo.raw_read("BRAKE_POST_DELAY") print("READED: "+str(value)) rand_integer = random.randint(0, 65) servo.raw_write("BRAKE_POST_DELAY", rand_integer, True) print(str(rand_integer)+" WRITTEN") try: servo.dict_storage_read() dict = servo.dict dict.save("xcore-enums-1.xml") except: print("ERROR saving new dict") print("==============================") print("TESTING FLOAT REGISTER:") print("=====================") for i in range(0, 6): servo.write('DICT._ACCESS_PASSWORD', 0x65766173) servo.dict_load("xcore-enums-1.xml") servo.dict_storage_write() print("Print brake post delay register") value = round(servo.raw_read("ANGLE_OFFSET"), 6) print("READED: " + str(value)) rand_float = round(random.uniform(0.0, 1.0), 6) servo.raw_write("ANGLE_OFFSET", rand_float, True) print(str(rand_float) + " WRITTEN") try: servo.dict_storage_read() dict = servo.dict dict.save("xcore-enums-1.xml") except: print("ERROR saving new dict") print("==============================") try: input("Press ENTER") except SyntaxError: pass print("Stopping...")
def slave_connection(ip): servo = None try: _, servo = il.lucky(il.NET_PROT.ETH, "eve-xcr_1.5.2.xdf", address_ip=ip, port_ip=1061) except: print("There was an error while scanning the network") return servo
def slave_connection(ip): servo = None try: _, servo = il.lucky( il.NET_PROT.ETH, "../../resources/dictionaries/eve-net_1.7.1.xdf", address_ip=ip, port_ip=1061, protocol=2) except Exception as e: print("There was an error while scanning the network") return servo
def monitoring(): # Connection servo = None try: _, servo = il.lucky(il.NET_PROT.ETH, "summit.xml", address_ip='192.168.2.22', port_ip=1061) except Exception as e: print("Error trying to connect to the servo.", str(e)) if servo is not None: # Configure monitoring parameters servo.net.monitoring_remove_all_mapped_registers() servo.write('MONITOR_TRIGGER_REPETITIONS', 1) # Configure monitoring SOC NO TRIGGER and EOC to the number of samples servo.write('MONITOR_SOC_TYPE', 0) servo.write('MONITOR_EOC_TYPE', 3) servo.write('MONITOR_TRIGGER_DELAY_SAMPLES', 1) servo.write('MONITOR_WINDOW_SAMPLES', 1000) # Monitoring temperature readings monitoring_data = [] mapped_reg = servo.dict.regs['BUS_VOLTAGE_READINGS'].address dtype = servo.dict.regs['BUS_VOLTAGE_READINGS'].dtype.value servo.net.monitoring_set_mapped_register(0, mapped_reg, dtype) # Enable monitoring servo.net.monitoring_enable() # Check monitoring status monitor_status = servo.raw_read('CCP_STATUS') if (monitor_status & 0x1) != 1: print("ERROR MONITOR STATUS: ", monitor_status) read_process_finished = False first_data_entry = True while not read_process_finished: try: monit_nmb_blocks = servo.raw_read('MONITOR_NUMBER_CYCLES') print("MONITOR NUMBER BLOCKS ", monit_nmb_blocks) if not read_process_finished: if first_data_entry: max_data_value = monit_nmb_blocks first_data_entry = False servo.net.monitoring_read_data() register = servo.dict.regs['BUS_VOLTAGE_READINGS'].dtype tmp_monitor_data = servo.net.monitoring_channel_data( 0, register) monitoring_data = monitoring_data + tmp_monitor_data if len(monitoring_data) >= 1001: np.resize(monitoring_data, 1001) read_process_finished = True except Exception as e: print("Error:", str(e)) print("BUS_VOLTAGE_READINGS:", monitoring_data) servo.net.monitoring_disable()
def run_example_eth_monitor(): protocol = il.NET_PROT.ETH ip = "192.168.2.5" net, servo = il.lucky(protocol, "xcore-enums.xml", ip) net.net_mon_stop() net.net_mon_status(on_evt) sleep(5) r = net.net_mon_stop() print(r) while True: sleep(0.5)
def run_example(): print("Run Example") GENERATOR_GAIN_REG = il.Register(identifier=str('GENERATOR_GAIN'), address=0x0382, dtype=il.REG_DTYPE.FLOAT, access=il.REG_ACCESS.RW) print("Generator gain identifier" + GENERATOR_GAIN_REG.identifier) net, servo = il.lucky(il.NET_PROT.MCB) servo.raw_write(GENERATOR_GAIN_REG, 1.666) print(servo.raw_read(GENERATOR_GAIN_REG)) servo.raw_write(GENERATOR_GAIN_REG, 0.123) print(servo.raw_read(GENERATOR_GAIN_REG)) servo.raw_write(GENERATOR_GAIN_REG, -0.123) print(servo.raw_read(GENERATOR_GAIN_REG))
def main(): # setup network and connect to the first available device net, servo = il.lucky(il.NET_PROT.EUSB) servo.units_vel = il.SERVO_UNITS_VEL.RPS # configure monitor (trigger: 90% of the target velocity) monitor = il.Monitor(servo) monitor.configure(t_s=T_S, max_samples=MAX_SAMPLES) monitor.ch_configure(0, VEL_ACT) monitor.trigger_configure(il.MONITOR_TRIGGER.POS, source=VEL_ACT, th_pos=VEL_TGT_VAL * 0.9) # enable servo in PV mode servo.disable() servo.mode = il.SERVO_MODE.PV servo.enable() # start monitor, set target velocity monitor.start() servo.velocity = VEL_TGT_VAL # wait until acquisition finishes monitor.wait(MONITOR_TIMEOUT) t, d = monitor.data servo.disable() # plot the obtained data plt.rc('font', family='serif') plt.stem(t, d[0]) plt.title('Actual Velocity') plt.xlabel('Time (ms)') plt.ylabel('Velocity (rps)') d_min = np.min(d[0]) d_max = np.max(d[0]) offset = 0.05 plt.ylim([d_min * (1 - offset), d_max * (1 + offset)]) plt.show()
def loadServos(self): model = QStandardItemModel() net, servo = il.lucky(il.NET_PROT.ETH, "../../resources/dictionaries/eve-net_1.7.1.xdf", address_ip='192.168.2.22', port_ip=1061, protocol=2) if net is not None and servo is not None: item = QStandardItem('0x{:02x} ({})'.format(1, "Everest")) item.setData(servo, Qt.UserRole) image = QImage(join(_RESOURCES, 'images', 'eve-xcr.png')) item.setData(QPixmap.fromImage(image), Qt.DecorationRole) model.appendRow([item]) self.cboxServos.setModel(model)
def load_save_config(): # Connection servo = None try: _, servo = il.lucky(il.NET_PROT.ETH, "summit.xml", address_ip='192.168.2.22', port_ip=1061) except Exception as e: print("Error trying to connect to the servo.", str(e)) if servo is not None: # Get the current drive config servo.dict_storage_read() new_dict = servo.dict new_dict.save('new_dict.xml') print("new_dict.xml created") # Load and save it again to the drive servo.dict_load('new_dict.xml') servo.dict_storage_write() print("new_dict.xml loaded")
def init_variables(self): # Get the dictionary path to load dictionary_path = join(dirname(realpath(__file__)), 'resources', 'summit.xml') # Create the net and servo try: _, self.__servo = il.lucky(il.NET_PROT.ETH, dictionary_path, self.__ip, port_ip=self.__port) except Exception as e: print("Error trying to connect to the drive.", str(e)) sys.stdout.flush() sys.exit(0) sys.stdout.flush() # Init read thread self.__read_thread = ReadThread(self, self.__servo, self.__refresh_time, self.__close_activated) for register_to_read in self.__registers_to_read: self.__registers_data[register_to_read] = Value('d', 0) self.__read_thread.add_task( register_to_read, self.__registers_data[register_to_read]) # Init write thread # Create the csv file to log the data self.__data_log_file = open('./outputs/data_log.csv', 'w', newline='') self.__data_log_writer = csv.writer(self.__data_log_file, delimiter=";") # Set headers to the csv headers = ['Timestamp'] for register_to_read in self.__registers_to_read: headers.append( self.__servo.dict.regs[register_to_read].labels["en_US"]) self.__data_log_writer.writerow(headers) self.__log_data_thread = LogDataThread( self.__servo, self.__refresh_time, self.__registers_data, self.__registers_to_read, self.__ready_to_read, self.__data_log_file, self.__data_log_writer, self.__close_activated) self.__log_data_thread.start()
def __init__(self): QDialog.__init__(self) # setup UI self.form = QFormLayout(self) self.editPosition = QLineEdit('') self.form.addRow(QLabel('Position'), self.editPosition) self.editVelocity = QLineEdit('') self.form.addRow(QLabel('Velocity'), self.editVelocity) # configure network (take first available servo) self._net, self._servo = il.lucky( il.NET_PROT.ETH, "../../resources/dictionaries/eve-net_1.7.1.xdf", address_ip='192.168.2.22', port_ip=1061, protocol=2) # create data model model = QStandardItemModel() pos = QStandardItem() vel = QStandardItem() model.appendRow([pos, vel]) # configure and start watcher self._watcher = RegisterWatcher(self._servo) self._watcher.add(POS_ACT, 1000, pos) self._watcher.add(VEL_ACT, 1000, vel) self._watcher.start(100) # map model fields to widgets self._mapper = QDataWidgetMapper() self._mapper.setModel(model) self._mapper.addMapping(self.editPosition, 0) self._mapper.addMapping(self.editVelocity, 1) self._mapper.toFirst()