예제 #1
0
    def festo_move(self, targetpos: int, speed: float, relative=0) -> None:
        """
        Moves the FESTO stage to the "targetpos" with "speed"
            !!! to use this function see the instructions in the FESTO section in __init__ !!!

            1) writes "targetpos" and "speed" to the T7's data registers
            2) the LUA script takes care of the movement

            *) if the movement is to be relative to current position use 'relative' = 1
        """
        # relative function
        if relative == 1:
            if self.currentpos + targetpos < 0:
                print("NEEDLE->festo_move: Warning, currentpos is below 0")
            elif self.currentpos + targetpos > 50:
                print(
                    "NEEDLE->festo_move: Warning, currentpos is going past 50")
            targetpos = self.currentpos + targetpos

        ljm.eWriteAddress(self.FESTO_handle, self.targetpos_addr,
                          self.f_datatype, targetpos)
        ljm.eWriteAddress(self.FESTO_handle, self.speed_addr, self.f_datatype,
                          speed)

        self.currentpos = targetpos
예제 #2
0
    def ping_DAC(self, address, v, time_delay=0):
        """
        Sends a quick signal in the adress, used to communicate with the hydra harp
        """

        dataType = self.FLOAT32
        ljm.eWriteAddress(self.handle, address, dataType, v)
        time.sleep(time_delay)
        ljm.eWriteAddress(self.handle, address, dataType, 0)
예제 #3
0
    def set_output(self, ID, v):
        #Sets the output of the TICDAC to a value between +/- 10
        #ID specifies which port the output is on

        if np.abs(v) < 10:
            dataType = self.FLOAT32
            ljm.eWriteAddress(self.handle, ID, dataType, v)

        else:
            print("Error: voltage limit exceded (you idiot)")
예제 #4
0
"""
Demonstrates how to use the labjack.ljm.eWriteAddress (LJM_eWriteAddress)
function.

"""

from labjack import ljm


# Open first found LabJack
handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY")
#handle = ljm.openS("ANY", "ANY", "ANY")

info = ljm.getHandleInfo(handle)
print("Opened a LabJack with Device type: %i, Connection type: %i,\n" \
    "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % \
    (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5]))

# Setup and call eWriteAddress to write a value to the LabJack.
address = 1000 # DAC0
dataType = ljm.constants.FLOAT32
value = 2.5 # 2.5 V
ljm.eWriteAddress(handle, address, dataType, value)

print("\neWriteAddress: ")
print("    Address - %i, data type - %i, value : %f" % \
    (address, dataType, value))

# Close handle
ljm.close(handle)
예제 #5
0
 def write(self, value, address, dtype=ljm.constants.FLOAT32):
     """
 To write data directly into a register
 """
     ljm.eWriteAddress(self.handle, address, dtype, value)
예제 #6
0
def updateEStop(eStop):
    ljm.eWriteAddress(handle, ESTOP_REG, 0, eStop)
예제 #7
0
def setHold(hold):
    ljm.eWriteAddress(handle, HOLD_REG, 0, hold)  #(USER_RAM2_U16)
예제 #8
0
def setHome():
    ljm.eWriteAddress(handle, RE_ZERO_TARGET_REG, 0,
                      1)  #signal to set new home (USER_RAM3_U16)
예제 #9
0
def moveTo(a):
    ljm.eWriteAddress(handle, TARGET_POSITION_REG, 2,
                      a)  #write the new position to USER_RAM0_I32
    ljm.eWriteAddress(handle, ENABLE_REG, 0,
                      1)  #Enable the drive (USER_RAM0_U16)
    print(a)
예제 #10
0
 def write(self,value,address,dtype=ljm.constants.FLOAT32):
   """
   To write data directly into a register
   """
   ljm.eWriteAddress(self.handle,address,dtype,value)
예제 #11
0
    def __init__(self, comport_arduino, startsteps, sensitivity, invertx: bool,
                 run_test: str):
        # Handle input parameters
        self.port = comport_arduino
        self.startcount = startsteps
        self.init_pos = 0
        self.sensitivity = float(sensitivity)
        if self.sensitivity > 1:
            self.sensitivity = 0.5
            logger.info("Invalid sensitivity entered: new value = {}".format(
                self.sensitivity))
        self.invert_x_axis = invertx
        self.test = run_test

        # Setup Arduino and Stepper Motors
        self.board = pyfirmata.Arduino(self.port)
        time.sleep(1)
        self.motors = []
        self.default_motor_setup()
        self.dirpull = {
            0: [0, 1],
            1: [0],
            2: [0, 3],
            3: [3],
            4: [2, 3],
            5: [2],
            6: [1, 2],
            7: [1],
        }

        self.dirpush = {
            0: [2, 3],
            1: [2],
            2: [1, 2],
            3: [1],
            4: [0, 1],
            5: [0],
            6: [0, 3],
            7: [3],
        }

        # motor vectors that code for the directions in the x-y space of the needle
        self.motorvec = {
            0: np.array([1, 1]),
            1: np.array([-1, 1]),
            2: np.array([-1, -1]),
            3: np.array([1, -1]),
        }
        """
        FESTO section
        !!! to use FESTO:    first upload "FESTO_controlv3.lua" to the T7 with Kipling 3 software
                            then close the connection with Kipling 3 software
        """
        # config
        self.config_object = ConfigParser()
        self.config_object.read('config.ini')
        festo = self.config_object["FESTO"]

        self.init_FESTO_pos = int(festo["initial_pos"])
        self.init_FESTO_speed = float(festo["initial_speed"])
        self.FESTO_stepsize = int(festo["step_size"])

        self.AIN0addr = 0  # position (0-10V)
        self.DAC0addr = 1000  # speed ref.signal (2.5V)
        self.DAC1addr = 1002  # speed out signal (-2.5 - 2.5V)
        self.initialpos_addr = 46000
        self.targetpos_addr = 46002
        self.speed_addr = 46004
        self.enable_addr = 46008
        self.f_datatype = ljm.constants.FLOAT32
        self.i_datatype = ljm.constants.UINT16

        self.offsetV = 2.5  # (offsetV+2.5V on DAC1 = 25 mm/s)
        self.offV = 0.0299544557929039  # low voltage that T7 can certainly output
        self.maxpos = 50  # mm
        self.minpos = 3  # mm
        self.currentpos = self.init_FESTO_pos

        try:
            FESTO_handle = ljm.openS("ANY", "USB", "ANY")
        except ljm.LJMError as error:
            FESTO_handle = None
            logger.error(
                "No FESTO_handle: thus not able to use the FESTO functions \n Error presented: "
                + str(error))

        if FESTO_handle is not None:
            self.FESTO_handle = FESTO_handle
            # Set initial positions (keep target pos at init_FESTO_pos at the start)
            ljm.eWriteAddress(self.FESTO_handle, self.initialpos_addr,
                              self.f_datatype, self.init_FESTO_pos)
            ljm.eWriteAddress(self.FESTO_handle, self.targetpos_addr,
                              self.f_datatype, self.init_FESTO_pos)
            # Set speed
            ljm.eWriteAddress(self.FESTO_handle, self.speed_addr,
                              self.f_datatype, self.init_FESTO_speed)
            logger.success(
                "FESTO connected, handle is available, init is set, current position ="
                + str(
                    ljm.eReadAddress(self.FESTO_handle, self.AIN0addr,
                                     self.f_datatype)))
            time.sleep(0.3)

            # Enable init LUA program
            ljm.eWriteAddress(self.FESTO_handle, self.enable_addr,
                              self.f_datatype, 1)
            logger.success("FESTO moving to initial position")
        else:
            logger.error(
                "Something went wrong when creating a FESTO Handle. Check if all adresses are correct in needle.py"
            )
            self.FESTO_handle = None