Adding real elements

For the sake of demonstration, let’s suppose you want to integrate a slit with IcePAP-based motors into Sardana.

Before doing anything else you should check the Sardana plugins catalogue. There’s a high chance that somebody already wrote the plugin for your hardware. If not, you can write the plugin yourself.

Controllers

The controller is a Sardana object that handles the communication with the hardware (physical controller) or provides an abstraction layer (pseudo controller).

Before creating the controller instance you need to load the controller plugin class into the Sardana. To check if it is already loaded use the lsctrllib macro. If it is not, you will need to configure the controller plugin discovery path (PoolPath property) and either restart the Sardana server or call the addctrllib macro:

Pool_<ServerName>_<ServerNumber>.put_property({"PoolPath":["<Your controller dir path>"]})

Example:
Pool_demo1_1.put_property({"PoolPath":["/home/vagrant/controllers"]})

After that check again with the list macro if the controller class is present and if yes let’s continue…

To create a controller instance you can use defctrl macro:

defctrl <class> <name> <roles/properties>

The <class> parameter is a class name for your controller to use and <name> is the name of the new controller instance. Roles and properties are used to configure the controller.

For our IcePAP controller we will use two properties: Host and Port of our IcePAP system:

defctrl IcepapController ipap01 Host 10.0.0.30 Port 5000

Note

In order to use the controller you must define also a motor and use the created controller as a parameter

Hint

You can use the sar_info macro to see the roles and properties available for a controller class.

Note

To learn more about controllers see Controller overview.

Controller axes

Since single motor controller can have multiple axes corresponding to multiple motors, we will need to create the elements for these axes. This way the controller will know which motor to move.

With the defelem macro you can create any type of controller axis, not only motors:

defelem <name> <controller> <axis>

<name> is the element name, <controller> is the controller instance on which the element should be created and <axis> is the controller axis number.

Let’s add an axis to our IcePAP controller:

defelem mot01 ipap01 1

Motors

For creating motors you can also use defm macro instead of defelem. Its invocation is the same, it’s just a shortcut:

defm mot02 ipap01 2

Pseudomotors

To use our slit with more abstract interface we can use the Slit pseudomotor controller. To use it, just add the Slit controller with the defctrl macro:

defctrl Slit s0ctrl sl2t=mot01 sl2b=mot02 Gap=s0gap Offset=s0off

For the Slit controller we use roles. There are two types of roles:

  • physical roles - real motors, elements that already exist in Sardana

  • pseudo roles - abstract motors that will be created by pseudo controller

The Slit controller defines two physical roles: sl2t and sl2b, and two pseudo roles: Gap and Offset. Note the difference in syntax for passing roles and properties to the defctrl macro.

By this point your slit should be accesible from Sardana using real motors as well as abstract pseudomotor interface.

Note

To learn more about pseudo elements see Pseudo motor overview and Pseudo counter overview.

Elements configuration

Your newly created elements are ready to be used. But, there are plenty of additional configurations that will improve the usage experience.

Almost certainly you are using the Tango sardana server extension. So, in continuation we will refer to the Tango features and explain how to configure them.

Main attributes events

Each element has at least one main attribute e.g. motor’s position or experimental channel’s value. These attributes asynchronously notifies the interested clients about the value changes when an element is involved in a sardana action e.g. a motor is being moved or an experimental channel is acquiring. For that need sardana uses the Tango event system. In order to optimize the server - client communication, Tango will verify if the value changed enough in order to send the notification, if not, it will not send it. Note, that at the beginning and at the end of the action there will be at least one event regardless of the verification result. You can adjust the change criteria for each main attribute using the Tango attribute property abs_change e.g. using Jive:

../_images/jive_event_abs_change.png

Here is the list of the main attributes per element type:

Element type

Attribute(s)

Motor

position, dial position

PseudoMotor

position

CTExpChannel

value

ZeroDExpChannel

value

PseudoCounter

value

IORegister

value

Important

If you don’t configure the change criteria differently sardana will use default values which may not fit your use case. That’s why it is important to apply your own configurations. The default values can be accessed in Jive the same way as for changing them (explained above).

Measurement groups

To create a measurement group use defmeas macro:

defmeas <name> <channel_list>

This macro takes the name for the new meaasurement group and the list of experimetal channels as its arguments. The first channel must be a Sardana internal channel and at least one of the channels must be a Counter/Timer.

Example:

defmeas mntgrp01 ct01 ct02 ct03 ct04

Note

To learn more about measurement groups see Measurement group overview.

Removing elements

Each element can be removed using macro corresponding to the element type. For controllers use udefctrl. For controller axes use udefelem. For measurement groups use udefmeas.

Each of these macros takes the list of element names as the argument.

Remember that you cannot remove controllers with elements, so you must remove the elements prior to removing the controller.

Useful lists

To create a controller it’s useful to know which controller classes are available. To do this use lsctrllib macro. To see the created controllers use lsctrl. For lists of motors and experimental channels use lsm and lsexp respectively. You can display all measurement groups with lsmeas macro.

Each of these macros accepts regexp filter as the optional argument.

See also

The path Sardana uses for loading controller classes can be configured. See the Configuration section for details.