Design a widget to display the values of multiple motorsΒΆ

Introduction

This tutorial shows how to design a widget to display the values of multiple motors represented by the same node structure defined in the Motor object type. In particular, we want to display the speed and acceleration values of each motor.

Download the example projects from here.

Steps

  1. Create the Motor object type

  2. Create the objects for all motors of interest

  3. Set the graphical objects of the widget

  4. Set the alias in the widget

  5. In the widget, set up reading the speed and acceleration of the motors

  6. Create the widget for each motor

Create the Motor object type

  1. Create a new standard project.

  2. In the Model folder create an object and rename it Motor.

  3. In Motor create two Speed and Acceleration variables without assigning a value.

  4. To make Motor an object type, drag it into the Types panel, by convention specifically into the Model folder: a Motor(type) object , i.e. the new type, appears in the Model folder and Motor becomes an instance of it.

  5. Delete the Motor instance, no longer needed.

Create the objects for all motors of interest

  1. To create a new motor object, drag the Motor type from the Types panel Model folder into the Project panel Model folder.

  2. Rename the newly created object (e.g. Motor1) and set the values of its Speed and Acceleration properties.

  3. Repeat the two previous steps for each motor whose values we want to display.

  4. Repeat the procedure to create and configure a second object (Motor2).

Set the graphical objects of the widget

  1. In the UI folder, create a Project object (New > Containers > Panel) and rename it MotorWidget.

    Note

    the new panel is a type; in fact every graphical object directly created in the UI folder is a type.

  2. In MotorWidget create the following nodes:

    • A Circular Gauge object (New> Basic controls > Circular gauge), then rename it SpeedGauge.

    • A Linear Gauge object (New> Basic controls > Linear gauge), then rename it AccelerationGauge.

    • Four labels (New > Basic Controls > Label), then rename them SpeedLabel, SpeedValue, AccelerationLabel, AccelerationValue.

  3. Set the Speed string as value of the SpeedLabel label Text property.

  4. Set the Acceleration string as value of the AccelerationLabel label Text property.

  5. To change the layout of the widget, double-click MotorWidget: the editor opens, where the objects can be positioned as desired.

Set the alias in the widget

Now we need to set an alias in MotorWidget to enable the widget to read the variables of the instances of Motor.

  1. Click MotorWidget, then in the Properties panel click image1, Alias.

  2. Rename the alias Motor.

  3. Set the Kind property of the alias with the reference to Motor type. To do it, drag Motor (type) from the Model folder into the Kind property value field.

In the widget, set up reading the speed and acceleration of the motors

With the alias created in the previous step, in the widget it is now possible to set the dynamic links needed to read the speed and acceleration values of the different instances of Motor.

  1. Click SpeedGauge and in its Value property set a dynamic link with the Speed property of the Motor type, exploiting the alias ({Motor}.Speed).

  2. Click the SpeedValue label and in its Text property set the same link ({Motor}.Speed).

  3. Click AccelerationGauge and in its Value property set a dynamic link with the Acceleration property of the Motor type, exploiting the alias ({Motor}.Acceleration).

  4. Click the AccelerationValue label and set the same link ({Motor}.Acceleration) in its Text property.

This completes the graphical interface and the logics of the widget.

Create the widget for each motor

To graphically represent each motor, now the widget must be created and associated each instance with the relative motors to read the specific speed and acceleration values.

  1. To create the widget, drag the MotorWidget type from the Types panel User interface folder into the MainWindow object in the UI folder.

  2. Rename the instance of the MotorWidget1 widget.

  3. Repeat the two previous steps and rename the MotorWidget2 widget.

  4. Point the Motor alias of MotorWidget1 to the Motor1 instance.

  5. Point the Motor alias of MotorWidget2 to the Motor2 instance.

See also

Related concepts

Alias

Related procedures

Using aliases

Related APIs

APIs for aliases