Documentation Home Page RT-LAB Home Page
Pour la documentation en FRANÇAIS, utilisez l'outil de traduction de votre navigateur Chrome, Edge ou Safari. Voir un exemple.

Using Aliases in RT-LAB



NOTE that the documentation below covers Aliases in RT-LAB and how they are used through the RT-LAB API with Python scripting.

Related, see also:

RT-LAB API Documentation

Using 2017 Aliases in RT-LAB


What They Are & How to Use Them

Aliases in RT-LAB have been provided with usability and error-proofing in mind. In the same way that a computer desktop shortcut can refer, or point to, a pre-assigned folder, aliases in RT-LAB point towards long paths and potentially complex or confusing signal names.

Signal paths and signals can then be referred to in a dependable, repeatable way that remains constant, and makes complex, changing information easier for users to use--for example, when being called from a Python script.


Aliases may be of use in any of the following situations:

  • Users have a long variable path and similarly-named signals they're watching, and would like to have a simpler, shorthand, less error-prone way of referring to these signals (and their paths) in the RT-LAB interface and through Python scripting
  • Users work on a simulator or target whose hardware and/or LabVIEW interfaces are changed frequently, or which has multiple users, and they'd like quick, easy access to their variables in a way that remains constant despite other changes to their environment
  • Users write and assemble Python scripts in advance, and need to know they can call the signal of their choice reliably when automated scripts are run, without requiring updates to signals and their paths



Note that aliases in RT-LAB are simply another way of referring to a signal (and its accompanying path, as a shortcut) and do not have any input or influence on the logic of the software, the model or the simulation itself.



Viewing & Renaming Aliases in Quick project > rtdemo1

  • Start RT-LAB with Quick Project > rtdemo1, and expand the folders Quick Project, then Models, then rtdemo-01, then Aliases.
  • Note that by default, some aliases have been created: in the screen shot below left, they are called Kd, Ki, Kp, etc.
  • Ensure the Variables Table tab is open in the lower right of the interface, and drag and drop Kd from Aliases to the Variables Table.
  • Note that, as below at right, the Alias shows its Name in the model (Gain), its Path, the Alias itself (Kd), and the current Value of the alias.
  • Click the Alias name in the Alias column, and change the name to Kd_rtdemo1_KdGain
  • Click Enter or click away from the field to save.
  • Note the Alias' name in the Aliases column in the left treeview navigation has been changed.
  • Click the new Alias name in the treeview, then Show in > Properties, as below, to expose its various properties.

Variables Table showing Name, Path and Alias, with its Value, when an Alias is dragged and dropped into the Variables Table.

Variables Table with Alias name being edited.

Right-clicking the new Alias name and then Show in > Properties....

...Leads to viewing its Properties in the Properties Table, below.

Creating an Alias

To create an Alias:

  • Select a signal by expanding folders from Quick Project > Models > rtdemo1 > sm_computation > any variable > any signal.
  • Right-click the desired signal > Set alias
  • Type a name for your Alias (in this case, AUDIO_GAIN) and click OK
  • Note that the Alias for Gain > Signal 1, named AUDIO_GAIN, now appears in the list of Aliases.


Right-Click Functionality with Aliases

Right-clicking an Alias provides the following functionalities:

  • Show in Variable Viewer: Allows user to edit value of variable manually.
  • Show in Properties: Shows in Properties Table, as above.
  • Set Alias: When grayed out, this function is not available.
    • Set Alias is available, for example, when expanding an sm_computation folder all the way down to the signal level.
    • Use Set Alias then to assign an Alias to a Signal through the Set Alias dialog box, see right.
  • Delete: Deletes the Alias without affecting the underlying signal or model
  • Rename: Renames the Alias
  • Properties: Displays the Alias' properties in the Properties Table.

Note that if you receive the error dialog below, it is because that Alias name has been used already.


Alias Use with LabVIEW



See LabVIEW Documentation | RT-LAB v.11.3.x and up for basic use of LabVIEW panels.

A reminder that RT-LAB output signals must be connected to LabVIEW indicators, while RT-LAB control signals and parameters must be connected to LabVIEW controls.



Aliases are used in LabVIEW in order to display information in the LabVIEW interface more cleanly, and allow customization for your particular case. For example, if you're testing audio through the LabView GUI, you may wish to use the word 'Volume' on an interface control or display rather than 'Gain'.

Displaying an Alias on a LabVIEW Control

To display an Alias name on a LabVIEW control:

  • Note that the LabVIEW GUI item below, a slider, is labeled Slider.
  • Drag the alias windturbine from the Alias list towards the slider.
  • Note that the circled slash, as it is being dragged from the Alias list, means that it cannot be dropped there.
  • As you approach the Slider, drop the windturbine alias on the Slider when the + icon appears, meaning it can be dropped there.
  • Note that nothing happens immediately.
  • Right-click the word Slider and select Show in caption > Alias.
  • The words Slider and Alias are displayed on top of one another.
  • Right-click the text Slider/windturbine and select Show label, toggling it off so that the check mark no longer appears.

The text label Slider has now been replaced by the signal alias label windturbine.



Note that in other cases, the process may simply involve dragging an alias for a signal over the pre-existing LabVIEW GUI label.

The following numeric control GUI item, labeled Numeric, becomes OpComm simply by dragging the signal OpComm on top of it.

This is because Show in Caption > Alias is already on (check mark), and Show label is off.


See LabVIEW Documentation | RT-LAB v.11.3.x and up for more on use of LabVIEW panels.



Alias Use with Load/Save Configuration (Variables Table)



See Load/Save Configuration Documentation | RT-LAB 11.3.x and up for how to use Aliases with Load/Save Configuration.


The intent of the RT-LAB feature Load/Save Configuration is that you be able to view super sets of multiple signals together, and compare them to other super sets of signals, and swap them out easily and at will. Aliases make this even easier.

  • Say you want to observe various sets of Gain values in action for the sm_computation signals Gain Kd, Gain Ki, and Gain Kp.

  • Select sm_computation > Gain KD > signal1
Right-click > Set aliasName the alias GAIN_KD_1
  • Select sm_computation > Gain KI > signal1
Name the alias GAIN_KI_1
  • Select sm_computation > Gain KP > signal1
Name the alias GAIN_KP_1
  • The three signals now appear, under their new names, in the Aliases list.
  • CTRL-select the three Aliases you are interested in viewing, and drag them to the Variables Table.
  • Assign them the first set of values through the Variables Table. This is one loadable/savable configuration.
  • Using the same set of signals, set new Aliases for each one, and then give them each new values: this is the second super set of Aliases for Load/Save Configuration.
  • Proceed as usual following the directions for Load/Save Configuration Documentation | RT-LAB 11.3.x and up.


Using Aliases with Regular & Light API for Calls/Implementation in Python Scripting



For more on the RT-LAB Python API, see RT-LAB API Documentation


About Aliases in the RT-LAB Python API

Alias Naming & Alias Paths

The alias’s name is a non case-sensitive string that should be unique. It should not contain the following special characters: asterisk (*) and question mark (?). It consists of a path and a name, or a name only.

A path is an organizational unit, or container, used to organize aliases into a hierarchical structure, separated by slash (/) characters.

Below are examples of valid alias names:

  • myAliasName
  • /myPath/myAliasName

With Matlab/Simulink, the absolute path of a parameter is the concatenation of the path of the block that contains the parameter and the name of the parameter.

Below are examples of parameter’s paths of a SineWave block:

  • Subsystem/SineWave/Amplitude
  • Subsystem/SineWave/Frequency

By analogy, with Matlab/Simulink, the absolute path of a signal is the concatenation of the path of the block that outputs the signal and the signal’s label. If the label is empty in the Simulink model, the port’s name that outputs the signal is used instead of the label.

Below are examples of paths for a signal at the outport 1 of a SineWave block:

  • SubSystem/SineWave/MySignalLabel, or
  • SubSystem/SineWave/Port1



Note: Any of the following kind of signals can be referenced: control signals, acquisition signals, and dynamic signals.



Using Aliases Through the Regular RT-LAB API


 How to Open the RT-LAB Python Console


Starting the RT-LAB Python Console

  • Open a Python console in RT-LAB by clicking Run > Open Console.

  • A dialog box asks you to confirm your selection type.
  • Select Python console and click Ok.
  • At the prompt, type help(r) to get help. Note that 'r' is itself an alias for the RT-LAB API.
  • A list of commands appear for the RtlabApi under the header DATA.


RT-LAB API Syntax for Aliases: Examples

In the RT-LAB API, users will find syntax for common functions such as:

  • To get a list of active projects running with RT-LAB: RtlabApi.GetActiveProjects()
  • To get the number of days until the license expires: RtlabApi.GetRtlabLicenseExpirationDate()

However a subset of Python API calls exist solely for use with aliases.

Broadly there are two ways to use the RT-LAB API with aliases: the regular (below), and the light.

Regular RT-LAB API for use with Aliases



The regular API contains these calls and is used with the following syntax. Please use this link for further information on syntax or arguments.




NOTE: In the table below, (star) = Specifying a pattern ensures retrieval of only matching aliases. Wildcard characters (? *) may be used in the pattern.

CallWhat it DoesSyntaxNotes
CreateAlias Creates an alias for a signal

RtlabApi.CreateAlias (aliasName, referencePath)


GetAliasDescription

Returns the set of information of aliases active for the current model.

aliasInfo = RtlabApi.GetAliasDescription(aliasNamePattern)

(star)

GetValueByAlias

Gets the values of one or more parameters (or signals) by specifying their alias names.

aliasNames = (aliasName1, aliasName2, ...)
aliasValues = RtlabApi.GetValueByAlias(aliasNames)
(aliasValue1, aliasValue2, ...) = aliasValues

The output contains one value for each alias.

LoadAlias

Loads a list of aliases in the current list of aliases.

status = LoadAlias(
fileName,
aliasNamePattern,
options)

The new list can replace the current list of aliases or it can be merged with the current list depending on the function's settings.

(star)

LoadAliasDescription

Loads a list of aliases.

aliasInfo = RtlabApi.LoadAliasDescription(fileName,
aliasNamePattern)
(aliasInfo1, aliasInfo2, ...) = aliasInfo
(aliasName, referencePath, referenceType, readOnly, exist, newAlias) = aliasInfo1

The new list isn’t merged to the current list of aliases or doesn’t replace the current list of aliases.
RemoveAliasRemove aliases from the current list of aliases currently associated with the active model.

RtlabApi.RemoveAlias(aliasNamePattern);

(star)
RenameAliasRenames an alias

RtlabApi.RenameAlias(aliasName,
newAliasName);

(star)
SaveAliasSave the current aliases list in the specified file.

RtlabApi.SaveAlias(fileName,
aliasNamePattern)

(star)
SetValueByAlias

Sets the values of one or more parameters (or signals) by specifying their alias names and
their values.

aliasNames = (aliasName1, aliasName2, ...)
aliasValues = (aliasValue1, aliasValue2, ...)
RtlabApi.SetValueByAlias(aliasNames,
aliasValues)

Note that if any of the aliases specified in the argument referenced a parameter, the parameter control is required. If any of the aliases specified in the argument referenced a control signal, the signal control is required.

RT-LAB's Light API for Python

At the Python console prompt, to initialize the Light RT-LAB API, copy and paste or type the following line: 

from rtlab.util.light import Log, Set, Get, Wait

A confirmation message appears and the RT-LAB Light API is initialized.

The four functions available through the RT-LAB Light API are as follows:

FunctionWhat it DoesSyntax
LogPrints text to a log file or to standard output (console)

Log(text)

Args: param1: Text to print

GetRetrieves signal value(s) from aliases

Get(*args)

Args: This function accepts 1 argument, a list of aliases or an alias.

SetAssigns signal value(s) to aliases

Set(*args)

Args:

This function accepts 1 or 2 input arguments, respectively a list of tuples (alias, value) or an alias and a value.

WaitSuspend execution for the given number of milliseconds, where 5000 = 5 seconds

Wait(period)

Args:
param1: Time to wait in milliseconds

## NOTE: This script should be used with the PID Example configuration 
## It shows how to use the Set function 
## Don't use the function: print. Use Log() instead, this prints in the console output window. 
## end also creates a log file in the model directory (model_name.txt) 
#new_kp = 100; #new_ki = 0; #new_kd = 0; 
#Set("Kp",new_kp); #Set("Ki",new_ki); #Set("Kd",new_kd); 
#Log("Gains ajusted to: Kp=%.1f Ki=%.1f Kd=%.1f" % ( new_kp, new_ki, new_kd ) ); 
#Perform a step on pos cmd 

Wait(3000);
Set("Reference", 20.0)
Wait(5000);
Set("Reference", 80.0)
Wait(5000);
Set("Reference", 20.0)
Wait(5000);
Set("Reference", 80.0)
Wait(5000);

Log("Log test")
#new_kp = 10; #new_ki = 1; #new_kd = 1; #Set("Kp",new_kp); #Set("Ki",new_ki); #Set("Kd",new_kd); 
#Log("Gains ajusted to: Kp=%.1f Ki=%.1f Kd=%.1f" % ( new_kp, new_ki, new_kd ) ); 
#Perform a step on pos cmd 

Wait(3000);
Set("Reference", 20.0)
Wait(5000);
Set("Reference", 80.0)
Wait(5000);
Set("Reference", 20.0)
Wait(5000);

OPAL-RT TECHNOLOGIES, Inc. | 1751, rue Richardson, bureau 1060 | Montréal, Québec Canada H3K 1G6 | opal-rt.com | +1 514-935-2323