Xeryon Python Library

Controlling our stages in Python is very easy thanks to our Python library. This library handles all of the communication between the computer and the controller. It also provides simple functions to control different stages. The library is compact and easy to use. Let’s have a look.

Download the Xeryon Python & Matlab Library

Setup

Initialisation

The first step is to initialise the system and import the library:

>> from Xeryon import *
>> controller  = Xeryon("COM11", 115200)           # Setup serial communication (COM-port, baudrate)
>> axisX       = controller.addAxis(Stage.XLS_312) # Add all axis and specify the correct stage.

It’s very easy to use multiple stages, just select the correct stage resolution.

System startup

The second step is to start the system. This command initiates the communication between the computer and the controller and configures the correct settings.

>> controller.start()

Find index

The last step of the setup is finding the index for each axis which is an obligatory step. Finding the index makes sure that the encoder knows at which position it is located.

>> axisX.findIndex()

Do you have multiple axes? It is easy to send commands to all the axis in the system by looping through them:

>> for axis in controller.getAllAxis():
>> axis.findIndex()

Now the setup is done and the system can be used.

Basic Control

It is really easy to control the system. If you want to move an axis to a specific position (= the desired position DPOS) just type the following and the stage will start moving:

>> axisX.setDPOS(10)

But what does “position 10” mean? All the positions and speeds in this library are expressed in the “current selected units”. By default, these units are in mm. So setDPOS(10) moves the stage to position “10 mm from the index point”.

Changing the units is very easy, just type:

>> axisX.setUnits( Units.mu )

This changes the units to micrometers. Notice that the units are specific for each axis.

By running the following command, the stage will position itself to -5 micrometer.

>> axisX.setDPOS(-5)

The controller sends feedback back to the computer. It can, for example, send the encoder position “EPOS”. The library reads incoming data and converts it into the current units. This all happens in the background. To read the data, just type:

>> axisX.getEPOS()
>> axisX.getDPOS()

The library also provides the function: step( value ). The name explains itself, it steps a certain amount of units. This function also just works wth the current units, so in this case it will be micrometers. By running the code below, the stage will first do a step of 5 mu and followed by a step of -10 mu.

>> axisX.step(5)
>> axisX.step(-10)

Speed control

Controlling the speed is very easy:

>> axisX.setSpeed(10)

This command will set the speed for this stage to 10 mu/s. Notice that the given value is always expressed in the current units.If you want to change the current units to mm and set the speed of the stage to 10 mm/s, use the following command:

>> axisX.setUnits(Units.mm)
>> axisX.setSpeed(10)

Scanning

Scanning is continuously moving with a fixed speed. Scanning can be done continuously, until there is a stop command:

>> axisX.startScan(-1) # The argument takes a negative or positive value, to control the direction.
>> time.sleep(1)  # Sleep 1 second.
>> axisX.stopScan() # Stop scanning.

But it is also possible to scan for a certain amount of seconds:

>> axisX.startScan(1, 2) # Scan for 2 seconds.

Controller feedback

The controller gives a lot of feedback. All this data is processed in the background, and always accessible. For example, the controller always sends a status (“STAT”) back. The definition of these status bits are explained in the datasheet.

All the status bits are simple Boolean functions in our library:

>> axisX.isForceZero()
>> axisX.isMotorOn()
>> axisX.isClosedLoop()
>> axisX.isEncoderAtIndex()
>> axisX.isEncoderValid()
>> axisX.isSearchingIndex()
>> axisX.isPositionReached()
>> axisX.isEncoderError()
>> axisX.isScanning()
>> axisX.isAtLeftEnd()
>> axisX.isAtRightEnd()
>> axisX.isErrorLimit()
>> axisX.isSearchingOptimalFrequency()

The biggest advantage of using our Python library is the ease with which you can capture and process data. Just use the function

>> axis.startLogging()
>> axis.stopLogging().

The function stopLogging() returns all the collected data.

Stopping

To close the program, run the controller.stop() command. This will reset the stage to its home position and shut down the communication.

Example

The code below is an example usage of these functions. It starts by defining the correct units and resetting the stage to its home position. Then it increases the speed to 120 mm/s and starts logging the data. The stage will then make a very small movement of 0.01 mm and stops collecting the data. Finally the stage will go back to home with its initial speed.

>> axisX.setUnits(Units.mm)
>> axisX.setSpeed(50)
>> axisX.setDPOS(0)
>> axisX.setSpeed(120)
>> axisX.startLogging()
>> axisX.step(0.01)
>> logs = axisX.endLogging()
>> axisX.setSpeed(50)
>> axisX.setDPOS(0)

The variable ‘logs’ contains all the collected data. A simple way to represent that data is by using the library ‘matplotlib’ and making a graph of the data. Notice that the data given back is always in encoder positions. Don’t worry, just use the following function to convert encoder units into mm:

>> axis.convertEncoderUnitsToUnits( value, Units.mm)

The reverse function also exists.

>> from matplotlib import pyplot as plt
>> unit_converted_epos = [] >> for index in range(0, len(logs["EPOS"])):
>>   unit_converted_epos.append(axisX.convertEncoderUnitsToUnits(logs["EPOS"][index],Units.mm))
>> plt.plot(unit_converted_epos)
>> plot.show()

The result is a simple graph of the encoder position throughout the movement of 0.01 mm with a speed of 120 mm/s.

An overview of the most used functions:

Class Xeryon:

start()
Start the communication, read the settings file and send the settings to the controller.
stop()
Move all the stages to their home position and close the communication.
reset()
Move all the stages to their home position and resend the settings.
getAllAxis()
Return al list containing all the axis objects.

Class Axis:

findIndex()
Find the index of the stage..
setDPOS( value )
Set the desired position to a specific value.
getDPOS()
Return the current DPOS in the current units.
getEPOS()
Return the current EPOS in the current units.
setUnits()
Specify the units this stage now works in.
getUnit()
Return the units the axis is currently working in.
step( value )
Step a certain amount of units.
startLogging()
Start logging (capturing) data.
endLogging()
End logging (capturing) data and return the captured data.
setSetting(tag, value)
Set a specific setting. Tag’s and values can be found in the controller datasheet.
startScan( direction )
Move continuously with a constant speed in a specified direction (-1 or 1)
startScan( dir. , time )
Move a specific amount of seconds with a constant speed in a specified direction (-1 or 1).
stopScan()
Stop scanning.
setSpeed( value )
Set speed in current units.

Matlab

Prefer to work in Matlab? No problem!

Our python library also works within Matlab so everything explained above is exactly the same in Matlab. We include an example program in Matlab, so you can start experimenting right away.

Explainer video