0% found this document useful (0 votes)
65 views41 pages

Guide Utilisateur MCS

This document provides a guide for using Machine Control Studio software to program Control Techniques drives. It begins with an overview of key concepts and features for working with drives. It then provides a quick start example to demonstrate the basic workflow of creating a project, editing programs, building/downloading programs to a target drive, and monitoring program execution. The example uses a RAMP block to generate a triangular waveform on a Unidrive M drive for demonstration purposes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views41 pages

Guide Utilisateur MCS

This document provides a guide for using Machine Control Studio software to program Control Techniques drives. It begins with an overview of key concepts and features for working with drives. It then provides a quick start example to demonstrate the basic workflow of creating a project, editing programs, building/downloading programs to a target drive, and monitoring program execution. The example uses a RAMP block to generate a triangular waveform on a Unidrive M drive for demonstration purposes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

®

Machine Control Studio User


Guide

USER MANUAL

© 2022 Control Techniques


Control Techniques
Table of Contents 2

1. Getting Started 3
1.1 Working With Drives .......................................................................................................... 4
1.2 Create a project from a Network Scan .............................................................................. 4
1.3 Updating Drives and Modules ............................................................................................ 6
1.4 Quick Start Example ............................................................................................................ 6
1.4.1 Overview of the Example .............................................................................................. 7
1.4.2 Create a Project ............................................................................................................. 7
1.4.2.1 Creating a Drive onboard Project ................................................................................................................ 7
1.4.2.2 Creating an MCi Module Project ................................................................................................................ 12
1.4.3 Editing the Program ..................................................................................................... 16
1.4.4 Building and Downloading the Program ..................................................................... 31
1.4.5 Monitoring the Program .............................................................................................. 36

Index 41

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started
Getting Started 4

1 Getting Started
1.1 Working With Drives

The following links provide useful information to enable you to get started programming Control
Techniques Drives:

· Supported Features
o This topic covers the different features supported by Control Techniques Drives and Option Modules

· Create a project from a Network Scan


o Learn how to quickly create a project by scanning your network for available devices.

· Online Diagnostics
o Learn about the powerful diagnostic tools available within Machine Control Studio. These include:
§ Immediate Window
§ Watch Window
§ Trace Watch Window

· Advanced Link Editor


o The Advanced Link Editor allows you to quickly and easily configure the real time synchronization of
data between Control Techniques Drives.
§ Version Compatibility
§ Opening the Advanced Link Editor
§ Configuring the Real-time Ethernet devices
§ Creating and deleting a cyclic link
§ Creating a broadcast or multicast link
§ Accessing the mapped parameters from the user program
§ Operation with Easy Mode cyclic links
§ Synchronous links and interaction with the Position task

1.2 Create a project from a Network Scan

The New Project Network Scan feature allows the user to create a new Machine Control Studio project
by scanning the networks (RTU serial and Ethernet) and automatically creating the devices in the Device
tree, however, this will not load the user programs even if any exist in the devices.

Creating a new project from the scanned network devices:


1. Open a new project in Machine Control Studio (Click File > New or the New Project icon )
2. Select the Projects folder
3. Chose an appropriate name and location for the new project files

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 5

4. Select Network Scan to scan the network and create the devices, Machine Control Studio will initially
search the RTU (serial) network for any nodes in the address range 1 to 5 followed by any Ethernet
devices (if suitable serial or Ethernet adapters are found)
5. Any devices found will be shown and can then be added to the project by clicking or

alternatively, the network scanner settings may be changed by clicking

See Also
· Device Features
· MCi Module Features
· Advanced Link Editor
· Online Diagnostics
o Immediate window
o Watch window
o Trace watch window

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 6

1.3 Updating Drives and Modules

The following links provide useful information when updating device software and Machine Control Studio
project.

· Updating the MCi from V1.5 to V1.6


o This topic covers upgrading the module firmware and converting existing Machine Control Studio
projects to work with the updated option module.

1.4 Quick Start Example

This tutorial guides the user through the process of creating a user program and executing it on the
Unidrive M onboard target.

The program that is created is not intended to be a meaningful application, nor is it important to
understand the exact operation of the code. The program is only created for demonstration purposes to
take the user through the following steps:

1. Creating a project.
2. Editing the program(s).
3. Building the program into a downloadable image.
4. Downloading the image to a target.
5. Monitoring the execution of the program on the target.

Prerequisites
To complete the example, the following items will be needed in addition to a copy of Machine Control
Studio:

1. Programmable Device:
a. A Unidrive M (M700 series or greater) with keypad.
b. Optionally - A MCi option module.
2. Machine Control Studio is installed on computer.
3. Communications:
a. A RS485 communications to connect the PC to the RJ45 on the front of the Unidrive M - available
from your Control Techniques supplier, or
b. Ethernet cable to connect either directly to the drive / option module or via a networked
architecture.

Note: Prior to going online with Machine Control Studio and downloading the example program, ensure
that the Unidrive M is powered on. Also, restore the Unidrive M parameter database to defaults using
either the “Reset 50Hz Defs” or “Reset 60Hz Defs” command codes in parameter 0 of any menu
(#mm.000) and pressing the red Reset button on the keypad. By loading defaults the process of going
online and detecting the drive will be made easier.

The user guides for Unidrive M are accessible from the Control Techniques website
(www.controltechniques.com) or from the Start Page of Machine Control Studio.

The next Quick Start stage is:

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 7

· Overview of the Example


1.4.1 Overview of the Example

The remaining stages in the Quick Start will show how to create and execute the following program.

The example program uses a user created RAMP block to generate a triangular waveform. The code in
the Clock Program will initialize some program variables and ensures that the target parameters are set
to execute the Clock task once every 32 milliseconds. The Clock task performs a linear RAMP from its
starting value to a Setpoint value defined by the user, and then back down again to the negative setpoint
value.

It is important to note that the actual program itself is only of secondary importance in this Quick Start
Guide. The primary goal is to familiarize the user with the basic concepts and tools within Machine
Control Studio and its working with the supported targets.

The steps will guide the user through declaring variables, creating function blocks, creating program
code, and finally executing that project on the target.

Note: In the Machine Control Studio programming environment, drive parameters are represented in the
format Mxx.Pyyy, where xx is replaced with the desired Menu number and yyy is replaced with the
desired parameter number within that menu. For example, M18.P020 is the proper way to reference
Parameter 20 within Menu 18. Also note that Mxx.Pyyy can be preceded with a Slot# identifier for
certain parameters, but that is not covered in this programming example.

The next Quick Start stage is:

· Create a Project
1.4.2 Create a Project

To set up a drive onboard project, see the Creating a Drive onboard Project page.

To set up an MCi module project, see the Creating an MCi Module Project page.
1.4.2.1 Creating a Drive onboard Project
This is stage 2 of the Quick Start example for Machine Control Studio with the Unidrive M Onboard
target.

In this stage a new project will be created using the New Project Template selector.

Step 1 – Run the Machine Control Studio application.

Once Machine Control Studio starts up, by default there will not be an active project, and the Start Page
will be visible (as seen in Figure 1 below). The Start Page allows the user quick access to Recent
Projects or other common Getting Started tasks, as well as displays the active version of the Machine
Control Studio tool. Additionally, the Start Page displays a News section which can display a website of
the users choosing (by default will display the introduction to Machine Control Studio page).

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 8

Figure 1 – Machine Control Studio Start Page

Step 2 – Create a new project

Create a new project by selecting File > New Project from the Machine Control Studio menu bar, or
selecting the Create a new project link from the Getting Started section of the Start Page.
When creating a new project, the New Project template selector dialog will appear as seen in Figure 2
below. For this example, we will choose the Drive User Program Project template (see highlighted item
in Figure 2). Name the project “GettingStartedExample” or another name as desired and choose the
desired location to store the project. Spaces and special characters are allowed in project names. When
complete, press the OK button to continue.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 9

Figure 2 – New Project Tem plate Selector Dialog

Step 3 – Configure the Project Settings.

Use the Create a New Drive User Programming Project dialog to define the desired project settings. This
dialog allows the user to define the name that the drive object will appear as in the project tree, the drive
type (Unidrive M or Unidrive M200-M400), as well as choose which Tasks/Programs will be created in
the project. Finally, the desired language for the user programs can be selected here.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 10

Figure 3 – Project Configuration Dialog

3a) Enter any drive name as desired. Spaces and/or special characters are allowed.
3b) Select which drive type is required.
3c) Activate the checkbox to create a Clock task within the project.
3d) Choose Structured Text (ST) as the language for the Clock program. Note that the configuration
dialog refers to programs as POU’s. More discussion of the POU will come later in this document. For
now, you can use the terms POU and Program interchangeably.

Once complete, click OK to accept the settings entered in the previous steps. Machine Control Studio
will then proceed to create a new project matching the information provided in the dialog in Step 3 above.
Figure 4 below shows the result of the newly created project. Note that the Devices tab now contains
tree listing of devices and objects.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 11

Figure 4 – Device List

Figure 5 below shows a closer look at the Devices tree and describes some of the components in more
detail.

Figure 5 – Devices tab tree

Note how the settings defined in Step 3 caused a Task named Clock as well as a Program (also named
Clock) to be created. Machine Control Studio has automatically assigned the Clock Program to run on
the Task of the same name. Simply double-click on the Task item in the Devices Tree to display the
Task Configuration view as seen in Figure 6 below.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 12

Figure 6 – Task Configuration View

This Task configuration view allows the user to assign a Program to run on the chosen Task and to
configure the desired Update Rate (or Interval) for that Task. By default the Clock Task is configured to
have a 32ms interval (or update rate). The Clock task interval for the onboard target can be adjusted by
the user in multiples of 4ms with a low limit of 4ms.

Notice the three empty drive slots at the bottom of the tree in Figure 5 above. If the drive had pluggable
programmable modules attached,those would be defined in the slot holders. Slot Configuration is not
covered in this Quick Start Guide.

For more information on tasks in Unidrive M, see Tasking Model.

This is the end of stage 2 of the Quick Start example.

The next Quick Start stage is:

· Editing the Program

The previous Quick Start stage was:

· Overview of the Example


1.4.2.2 Creating an MCi Module Project

This is stage 2 of the Quick Start example for Machine Control Studio with the MCi module target.

In this stage a new project will be created using the New Project Template selector.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 13

Step 1 – Run the Machine Control Studio application.

Step 2 – Create a new project

Create a new project by selecting File > New Project from the Machine Control Studio menu bar, or
selecting the Create a new project link from the Getting Started section of the Start Page.

Choose the MCi210 option as indicated in the picture below.

Figure 1 - Creating a new MCi project

Step 3 – Configure the Project Settings.

Use the MCi Module dialog to define the desired project settings.

This dialog allows the user to define the name that the drive object will appear as in the project tree, as
well as choose which Tasks/Programs will be created in the project. Finally, the desired language for the
user programs can be selected here.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 14

Figure 2 – Project Configuration Dialog

3a) Select the slot that the MCi Module is installed to.
3b) Activate the checkbox to create a Clock task within the project. Any 1 of the 4 clock tasks would be
suitable.
3c) Choose Structured Text (ST) as the language for the Clock program. Note that the configuration
dialog refers to programs as POU’s. More discussion of the POU will come later in this document. For
now, you can use the terms POU and Program interchangeably.

Once complete, click OK to accept the settings entered in the previous steps. Machine Control Studio
will then proceed to create a new project matching the information provided in the dialog in Step 3 above.
Figure 4 below shows the result of the newly created project. Note that the Devices tab now contains
tree listing of devices and objects.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 15

Figure 3 – Device List

Figure 4 below shows a closer look at the Devices tree and describes some of the components in more
detail.

Figure 4 – Devices tab tree

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 16

Note how the settings defined in Step 3 caused a Task named Clock as well as a Program (also named
Clock) to be created. Machine Control Studio has automatically assigned the Clock Program to run on
the Task of the same name. Simply double-click on the Task item in the Devices Tree to display the
Task Configuration view as seen in Figure 6 below.

Figure 5 – Task Configuration View

The MCi module also contains a Watchdog. This can be set up in the POU tab underneath the Interval
selection as shown above. See the section Watchdog in the main application help.

This Task configuration view allows the user to assign a Program to run on the chosen Task and to
configure the desired Update Rate (or Interval) for that Task. By default the Clock Task is configured to
have a 32ms interval (or update rate). The Clock task interval for the Applications Module target can be
adjusted by the user in multiples of 4ms with a low limit of 4ms.

For more information on tasks in Unidrive M, see Tasking Model.

This is the end of stage 2 of the Quick Start example.

The next Quick Start stage is:

· Editing the Program

The previous Quick Start stage was:

· Overview of the Example


1.4.3 Editing the Program

This is stage 3 of the Quick Start example for Machine Control Studio with the Unidrive M Onboard
target.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 17

In this stage, we will investigate how to modify the user program to perform the desired operation. At the
end of the stage, the program will be ready for building and downloading to the target device.

Step 1 - Open the Clock program editor view

To edit a program, double click the desired program in the Devices tree. Doing so will bring up the
program editor view for the selected program. Double click on the Clock (PRG) item in the tree now to
bring up the editor. Figure 8 below shows the Clock program editing space highlighted within the
Machine Control Studio environment.

Figure 8 – Program Editor View

The program editing view is broken into two sections. The top section is the Variable Declaration section
and is used to declare program variables used within this program. The bottom section is the Coding
section and this is where the actual program code will be created.

Step 2 – Declare Program Variables


To use a variable within a user program, that variable must first be defined in the Variable Declaration
section of the program view. To declare a program variable, simply insert a new line between the labels
“VAR” and “END_VAR”. Then insert the desired variable name and the data type in the following format:

VariableName: DataType;

Figure 9 below is an example which declares a user program variable named “TestVar” with a Data Type
of Integer.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 18

VAR
TestVar: INT; // An example of declaring a variable
END_VAR

Figure 9 – Exam ple of Declaring a Variable

Note that by default, Machine Control Studio will automatically indent your variable and bold and color
the data type identifier keyword. The separation between the colon and the data type can be one or more
spaces as desired. To create a comment for a variable, the syntax is two forward slashes “//” followed by
your desired comment. The two forward slashes indicate a single line comment. If the comment runs
over multiple lines, you will either need to put “//” at the beginning of each line, or use the multi-line
comment syntax of “(*” and “*)” or “{“ and “}”. Anything between those character combinations is
interpreted to be a comment.

Commenting Declared Variables

As in any coding language, comments are a vital part of creating a quality Machine Control Studio
program. Comments allow your code to be easily read by other users, allow you to remember sections
of code that you haven’t touched for long periods of time, help to make code more portable or re-usable,
as well as aid in writing and debugging your program. Because Machine Control Studio uses IntelliSense
tools to help you create programs, it is important that comments are properly placed in the variable
declaration section, otherwise the Intellisense tool will not interpret the comment correctly. If a comment
is not placed in the proper location, it can look fine visually when reading it, but IntelliSense may
associate the comment with the incorrect variable. Valid comments must appear above or on the same
line as the declared variable. Figures 10 and 11 below are examples which show how to correctly and
incorrectly comment your declared variables.

CORRECT

VAR
TestVar1: INT; // Valid comment location for TestVar1

// Valid comment location for TestVar2


TestVar2: INT;
END_VAR

Figure 10 – Correct m ethod of com m enting Declared Variables

INCORRECT

VAR
TestVar: INT;
// Not a valid comment location for TestVar1
END_VAR

Figure 11 – Incorrect m ethod of com m enting Declared Variables

As many variables as desired may be created within the Declaration section. The only key to this is that
all variables must be between the VAR and END_VAR labels, and each one must be given a proper Data
Type.

Initial Values for Declared Variables

Variables may be initialized with a non-zero value if desired. Figure 12 below shows how to properly give

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 19

a declared variable an initial value.

VAR
// Gives TestVar1 an initial value of 5
TestVar: INT :=5;
END_VAR

Figure 12 – Declaring an Initial Value for a Variable

Note that one or more spaces are allowed between the Data Type and the operator and the value.

All variables not explicitly given an initial value will be initialized with a value of zero; however, it is good
programming practice to always define an initial value, even if that value is zero.

Auto-Declaration of Variables

A variable can be declared automatically by just using the desired variable name within the program
coding section. When the user enters a carriage return, then the Auto Declare dialog will pop up
requesting the user to enter the declaration data for the new variable. Figure 13 below shows an example
of the Auto Declare dialog.

Figure 13 – Auto Declare Dialog Box

The Name field of the Auto Declare dialog will automatically be populated with the new variable name
that was typed into the program. The Type field will default to the INT data type, unless the system can
determine what type of variable you want to create based on the context of the line of code. For
example, if you are creating a new variable to be used as the input or output of a function block, the
system already knows what data type the function block is expecting, and populates the Type field
accordingly. Initial Values and Comments can also be added using this dialog as desired.

Click OK to accept the changes when the declaration properties have been filled in. Machine Control
Studio will then automatically add the declaration information into the Variable Declaration section of the
program view.

Note that any variables declared within this program declaration section are local only to this program. In

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 20

other words, other programs or function blocks do not have access to these variables. If it is required to
have access to a variable outside of a given program or function block, the variable must be declared in a
Global Variable List. Global Variable Lists are not covered in this Quick Start guide. Refer to the
Machine Control Studio help system for help on Global Variable Lists.

A little more about variables:

· Variable names cannot begin with a numeric character.


· Variable names cannot contain spaces or other special characters (i.e. @, #, $, etc.); However,
underscores characters are allowed but there may not be more than one in a row.
· Variables are NOT case sensitive (example: TESTVAR, TestVar, and testvar are all the same
variable).
· The length of variable names is not limited.
· Some words are reserved and cannot be used for variable names. For a list of reserved words, right-
click in the program code section and select Input Assistant > Keywords.

For this example program, declare the following variables and give them the initial values as defined
below. Give each variable a basic comment as desired. When complete, your Variable Declaration
section should look similar to the code found in Figure 14 below.

PROGRAM Clock
VAR
UpRate: INT := 500; // Defines the count up rate of the ramp
DownRate: INT := 500; // Defines the count down rate of the ramp
Setpoint: INT := 5000; // Defines the target of the ramp
ClockTaskTime: INT := 0; // Update rate of the Clock task
RampOutVal: INT := 0; // Output value from the ramp block
END_VAR

Figure 14 – Exam ple Program Variable Declaration

These variables will be used to populate the inputs/outputs of a Ramp function block created in the next
step.
For a list of all supported data types in Machine Control Studio refer to the help file section Programming
References > Data Types > Standard Data Types. Note that for the Unidrive M Onboard target, the 32-bit
real (REAL), 64-bit integer (LINT and ULINT), and WSTRING data types are not supported.

Step 3 – Add a Ramp Function Block to the program

In this step, we will add our first Function Block to the user program.

This is a good opportunity to introduce the POU, or Program Organization Unit. Don’t be confused by
this name “POU”. It is simply a generic term used in the software to describe any component within the
programming environment. Individual POUs are combined together to create the overall application
program. POUs come in the following three types:

Program – A Program POU is a high-level object that runs on a specified task. A Program POU can
have its own code to perform a task, but may also call other low-level POU’s (i.e. functions or function
blocks) to perform more specific tasks.

Function Block – A Function Block POU is a lower-level object containing some program functionality,
and is used within a Program POU. Imagine a Function Block as a sort of subroutine that is called by a
program. Function Block POU’s can have one or more Input Variables and one or more Output variables.
Once a Function Block POU is created, it can then be used within a Program POU or another Function

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 21

Block POU. When a Function Block is declared, it allocates memory to hold the instance data, therefore
allowing a Function Block to be used multiple times in a program.

Function – A Function POU, much like a Function Block POU, is a lower-level object that performs
some specific operation within a Program POU. A Function also acts like a subroutine that is called by
a program. The difference between a Function and a Function Block is that a Function only has a single
return variable/type. The single return functionality allows the function to be called as an operation in the
Structured Text language (i.e. ResultVar := Function(Input1, Input2, Input3)). The output of the function
will be assigned to the variable named ResultVar in the previous example. Another difference between a
Function and a Function Block is that a Function does not retain data whereas a Function Block does.
A typical example of a Function POU is a math operation that is passed one or more input values, and
only returns a single result value.

For best practice, when creating Function Block or Function POUs, try not to read or write drive
parameters inside the function. Rather, if a drive value is needed for the function, pass the drive value in
or out as an input or output argument.

Now that we have defined the POU, we will add a Function Block POU to our Clock program. To do this,
right-click on the Application item in the Devices Tree on the left side of the application.

Figure 15 – Right-click on Application to Add a POU

When the context menu appears, select Add Object > POU…. This will cause the Add POU dialog to
appear as seen in Figure 16 below.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 22

Figure 16 – The "Add POU" Dialog Box

In the Add POU dialog, give the function block a name in the Name field. Use a name of “MyRamp” or
any other name of your choosing. Note that POU names follow the same basic rules of variable names
as described in Step 2 above. Select the Function Block type radio button. Finally choose Structured
Text for the Implementation Language of the Function Block. Click Open to create the Function Block.
When complete, the application should open the Function Block Editor for the newly created function
block as seen in Figure 17 below. Note that the Function Block Editor looks almost identical to the
Program Editor. This makes some sense because, remember that Programs and Function Blocks are
simply two slightly different types of POUs.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 23

Figure 17 – Function Block Editor

Upon closer inspection you will find that the Variable Declaration section looks a bit different than it did
for a normal program. The difference is that there are several types of variables to be declared rather than
just basic variables. Because this is a Function Block, you must define Input and Output variables in
addition to the standard variables used within the Function Block. The Input Variables are the values
passed into the block, and Output Variables are the values (or results) passed out of the block. The
Variables Declaration section allows you to declare variables of all three types. See Figure 18 below for
details.

Function Block Variable Declaration

FUNCTION_BLOCK MyRamp
VAR_INPUT
// Input variables are declared here
END_VAR
VAR_OUTPUT
// Output variables are declared here
END_VAR
VAR
// Standard variables used within the FB are declared here
END_VAR

Figure 18 – Function Block Variable Declaration

For this example, declare the variables defined in Table 1 below. Be sure to declare the variables in the
right location based on the type of variable (i.e. Input, Output, or Variable). Modify the comments as
desired.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 24

Var Type Name Data Type Comment

Input Variable Target INT Target value for ramp

Input Variable CountUp INT Rate for ramping up (units/sec)

Input Variable CountDown INT Rate for ramping down (units/sec)

Input Variable TaskTime_msec INT Update rate of task FB is used in

Output Variable Out INT Output ramp value of function block

Variable OutTemp INT Temporary output ramp value


Table 1 – Function Block Variables

Once the above variables have been declared, the program code can be added in the Coding Section of
the editor. Copy the code below and paste it into the Coding Section of the Function Block.

IF Target > Out THEN // Ramp output up (accelerate) to Input Target value

// Add one update increment to ramp output


OutTemp := OutTemp + (CountUp * TaskTime_msec / 1000);

// Clamp the output


IF OutTemp > Target THEN
OutTemp := Target;
END_IF;

ELSIF Target < Out THEN // Ramp output down (decelerate) to Input Target value

// Subtract one update increment from ramp output


OutTemp := OutTemp - (CountDown * TaskTime_msec / 1000);

// Clamp the output


IF OutTemp < Target THEN
OutTemp := Target;
END_IF;

END_IF;

Out := OutTemp; // Set Output

Without going into great detail, the ramp code above will increment or decrement the ramp output value a
certain amount based on the specified ramp input values and the task update time. Understanding the
exact operation of the program is not what is important, so don’t feel like you need to understand the
functionality in detail. The goal of this Getting Started Guide is simply to familiarize the user with the
programming interface and all of its components.

The MyRamp Function Block is now complete. If we were to look at MyRamp as a block diagram, it
would appear as seen in Figure 19 below.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 25

Figure 19 – MyRam p Function Block as Block Diagram

Note that even though the MyRamp function block was created using the Structured Text language,
MyRamp can be used within programs created in any of the IEC-61131 languages. It will automatically
appear in the proper format.

You should now see the MyRamp function block appear in the Devices tree view on the left side of the
user interface as seen in Figure 20 below.

Figure 20 – MyRam p Function Block appears in Devices tree

Once the MyRamp Function Block is created, it doesn’t do anything by itself. It must be used or called
from a within a Program POU to be executed. Let’s go back to our Clock program and use our new
MyRamp Function Block.

Step 4 – Using the new Ramp Function Block within the Clock program

In this step, we will use the new MyRamp Function Block that was created in the previous step.

When using an existing Function Block within the program, we can use the Input Assistant functionality
of Machine Control Studio to create an instance of the block. You may be asking yourself, “Why do we
create an instance of a function block?” The answer to this is because a function block itself is simply a
template which can be reused as many times as desired throughout your program(s). When calling a
function block in a program, you are actually calling an instance of the function block template. If a
function block is used multiple times in a program, it will likely be passed different input data each time,
and therefore you need multiple instances of the block to keep track of the various input and output data
variable values.

To use the Input Assistant, right-click on the line of the Coding Section of the program in which you wish

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 26

to call your function block as seen in Figure 21 below.

Figure 21 – Right-click to select Input Assistant

Doing so will bring up the Input Assistant dialog which allows the user to select an existing variable,
module, function block, etc. to insert into the program. Figure 22 below shows an example of the Input
Assistant dialog box.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 27

Figure 22 – Input Assistant Dialog Box

To insert our function block created in the previous step, first select “Function Blocks” from the
Categories field. Then expand the “Application” branch in the Items field. We are looking in the
Application branch, because we created this function block within our application. If it was a function
block from one of the standard libraries, or a third party library, we would choose the appropriate library
branch containing the desired function block in the Items field instead. Locate and click on the MyRamp
function block. Notice how the Documentation section at the bottom of the dialog shows the input and
output variables for the function block. Note how it has picked up the comments for each input and
output variable that we entered when declaring the variables within the function block editor! Finally, click
OK to insert the function block into the clock program.
Once you click OK to insert the function block, the Auto Declare dialog should appear to help you
declare a new instance of the MyRamp function block, as seen in Figure 23 below. Set the Name field to
“Ramp1” and click OK.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 28

Figure 23 – Declare an instance of MyRam p

When complete, the function block call will be added to the Coding Section, and a declaration of a
variable called Ramp1 of data type MyRamp will be created in the Variable Declaration section. Your
screen should now appear as seen in Figure 24 below.

Figure 24 – Screen after Input Assistant adds Function Block

When the Input Assistant inserts the call to Ramp1 in the program, it breaks each of the Input and

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 29

Output Variables onto separate lines for clarity. The following line of code has all the arguments on a
single line and would work just the same as Figure 24 above.

// This is the same as breaking into multiple lines as in Figure 24


Ramp1(Target:= ,CountUp:= ,CountDown:= ,TaskTime_msec:= ,Out=> );

Note how the Input Variables have the “:=” operator next to them so that we can assign a value or
variable to them, and the Output Variable(s) have “=>” next to them which means a value will be
assigned to whatever variable is specified. Let’s use the variables created several steps ago to pass data
values into the function block. Enter the variables into the function block call as seen in Figure 25 below.

Ramp1(
Target:= Setpoint,
CountUp:= UpRate,
CountDown:= DownRate,
TaskTime_msec:= ClockTaskTime,
Out=> RampOutVal);

Figure 25 – Adding Variables to the Function Block call

This means that we will pass the values of the declared variables into the Ramp1 function block. Once
you have completed assigning variables to the function block parameters, we will add some additional
code to the Clock Program.

When ready, copy and paste the necessary code so that your Clock program looks as shown in Figure
26 below.

// Read the Clock task time from the drive


IF ClockTaskTime = 0 THEN
ClockTaskTime := DINT_TO_INT(M11.P055);
END_IF

// Call the ramp function block


Ramp1(
Target:= Setpoint,
CountUp:= UpRate,
CountDown:= DownRate,
TaskTime_msec:= ClockTaskTime,
Out=> RampOutVal);

// If we have reached the setpoint ramp, in the other direction


IF RampOutVal = Setpoint THEN
Setpoint := -Setpoint;
END_IF

Figure 26 – Com plete Clock Program Code

The program is now complete. Save the program by choosing File > Save Project from the menu bar.

Calling Function Blocks

When calling a function block within a program, it is not mandatory to pass values to all input
parameters or read all output parameters. For example, if we wished to call the Ramp1 function block,
but did not want to write to the CountUp or CountDown arguments, we could simply eliminate them from

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 30

the call instruction as seen in Figure 27 below.

// Call Ramp1, but do not send data to CountUp or CountDown params


Ramp1(
Target:= Setpoint,
TaskTime_msec:= ClockTaskTime,
Out=> RampOutVal);

Figure 27 – Calling Function Block w ithout all I/O data

If this method of selected data is used, then the function block will use the last value of the variable for
processing the block. If no value has ever been written to a function block variable, then it will use the
value defined in the variable declaration section of the function block.

Alternate Method to Access Function Block Data

The way that we have used variables to pass data into the Function Block thus far is referred to as
indirect access to the Function Block. We could use another method to pass data into our get data out
of the function block by using what is called a direct access method. The example below shows the
difference between the indirect and direct access methods of passing a value of 1000 into the CountUp
input parameter on the Ramp1 block.

Indirect Access of Function Block Data

UpRate := 1000; // Set UpRate to 1000

// Value of 1000 gets indirectly passed to Ramp1 – CountUp parameter


// through the UpRate variable
Ramp1(
Target:= Setpoint,
CountUp:= UpRate,
CountDown:= DownRate,
TaskTime_msec:= ClockTaskTime,
Out=> RampOutVal);

Figure 28 – Indirect Access of Function Block Data

Direct Access of Function Block Data

// Value of 1000 gets directly passed to Ramp1 – CountUp parameter


Ramp1.CountUp := 1000;

Figure 29 – Direct Access of Function Block Data

This direct method can be much more efficient since it does not require the allocation of a variable just to
hold the data to be passed into the function block. Note that simply writing directly to the input
parameter of a function block as seen above does not initiate the function block as shown in the Indirect
method.

This is the end of stage 3 of the Quick Start example.

The next Quick Start stage is:

· Building and Downloading the Program

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 31

The previous Quick Start stage was:

· Create a Project
1.4.4 Building and Downloading the Program

This is stage 4 of the Quick Start example for Machine Control Studio.

In this stage the example program is built into a user image, Machine Control Studio is taken online and
the user image is downloaded to the target.

To begin this stage, the example project created in stages 2 and 3 should be open in the application
editor. If the example project has been closed, reopen the example project. If you have followed the
steps exactly, the project should be named “GettingStartedExample”.

To build the project, perform the following steps:

Step 1 - Build the Project

With the project open in the editor, select Build > Build from the Menu Bar, or press the F11 key on the
keyboard. Machine Control Studio will proceed to build (or compile) the user project to verify syntax and
configuration.

Step 2 – Check the results of the Build

The build should take only a few seconds to complete, maybe longer for larger projects, and the results
of the build will be displayed in the Messages window. To view the Messages window (if not already
visible), select View > Messages from the Menu Bar as seen in Figure 30 below.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 32

Figure 30 – Select View > Messages to check the results of the Build

Within the Messages window should be the results from the Build action. If all steps of this Getting
Started Guide were followed properly, then you should not have any build errors. The window should
show “Compile complete – 0 errors, 0 warnings” as seen in Figure 31 below.

If you do encounter build errors, they will be listed in this window with each error listed individually as a
single line item. You can double-click on a given error and the editor will bring you to the line of code in
the Program or Function Block that contains the error. Note that sometimes a single syntax mistake
can cause multiple build errors. Simply work your way down the list of errors one by one. After each
error is fixed, rebuild the project using the same steps as mentioned earlier. Continue this process until
each error is removed from the Build Error list and the project compiles without any errors or warnings.

Figure 31 – The Messages View

Note that the Message Window can be undocked from its current location and moved to a new location
as desired, or left positioned as default. Additionally, you can use the pin icon in the upper right-hand
corner to make the window remain open all the time, or unpin it to allow it to hide automatically when not
using it.

Also notice that the Messages window has a feature called “Precompile” in the bottom left-hand corner
that basically shows the results of the real-time compiler that runs in the background. If you are editing
your program or function block and type a syntax error, the Precompiler will notify you of the error before
you do a full build action.

Step 3 – Check the Application Resources

Once the project has built without any errors or warnings, it is essentially ready to be downloaded to the
Unidrive M Onboard target. One thing we need to verify before downloading is that the project image will
fit within the available resources of the onboard target. To verify the image size, select View >
Application Resources View from the menu bar. The Application Resources tab should appear, and you
simply need to verify that the ROM Used and RAM Used meters are not beyond 100%. If you have
followed each stage of the Getting Started Guide properly, the project should be well within the available
resources as shown in Figure 32 below.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 33

Figure 32 – The Application Resources View

If the ROM/RAM Used values do not exceed 100%, then the project is ready to be downloaded.

If the ROM/RAM Use values exceed 100%, then it is necessary to reduce the program size until it fits
within the available resources. Alternatively, you could chose to switch to using a pluggable applications
module as the target instead of the onboard target.

Step 4 – Connecting the Communications Cable

Connect the RS485 cable between a COM port (or USB Port) on the PC and the RJ45 on the front of the
Unidrive M. Make a note of the PC COM port which the cable is connected to because you will need this
information later. In the case of a USB comms cable, this may be a virtual COM port that you need to
look up in the Device Manager tool in MS Windows.

Step 5 – Going Online (Logging In to the Target)

The process of downloading the project to the target begins by logging in to the target device. This is
done by selecting Online > Login from the Menu Bar as seen in Figure 33 below.

Figure 33 – Logging In to the Controller

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 34

This will cause Machine Control Studio to make a connection between the PC and the hardware target. If
the active project has not established communications before, a dialog will appear notifying the user that
there is no active communications path defined, and asking if you wish to set a path. Click Yes to define
the comms path. After clicking Yes, the Drive Tab and Communications Settings subtab will open up as
seen in Figure 34 below.

Figure 34 – Com m unications Setting View

The communications path to the device is referred to as a Gateway. The Gateway must be configured
with the proper settings to match the controller so that communications may be established. The
controller (or drive) settings can be found on the Unidrive M using the drive keypad by checking the
following parameters.

· M00.P036 has the Baud Rate setting (19200 by default)


· M00.P037 has the Node Address setting (1 by default)

Higher baud rates will work should you chose to modify the default comms settings. It is important that
both the drive and the Machine Control Studio software settings match in order to establish
communications. Note that baud rates up to 115.2kbaud can only be achieved using the USB CT485
lead.

The right side of the window in Figure 34 above shows the current Gateway settings. To modify the
settings, right-click on the Gateway and select “Edit Gateway…” to bring up the Gateway setup dialog
as found in Figure 35 below.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 35

Figure 35 – Editing the Gatew ay Settings

Adjust the settings as necessary to match the drive and select OK to apply those settings. Once
applied, click the “Scan Network” button on the right side of the Communications Settings view. Doing
so will cause Machine Control Studio
to interrogate the network for devices between the Node Search Start Address and End Address defined
on the Gateway settings dialog. Once a device(s) is found, it will appear as a branch under the Gateway
as seen in Figure 36 below.

Figure 36 – Device Detected on Gatew ay

Step 6 – Download the Project to the Target Device


Once the Gateway has been configured properly, and the device has been detected, select the Online >
Login from the menu bar again, or click on the Login icon as identified in Figure 37 below.

Figure 37 – Login Icon on Toolbar

If the Gateway is configured properly, the Login should succeed and a dialog will appear notifying the

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 36

user that the target device (Unidrive M) contains a different version of an Application, and asks if you
wish to perform a download to load the new Project onto the controller. Answer Yes to download the
project. Doing so will cause Machine Control Studio to rebuild the application (in case any changes were
made since the last Build), and also generate the image that runs onboard the target. The image should
then download to the target and Machine Control Studio will remain online with the device.

At this point, you should be online and the project should be downloaded to the device.

This is the end of stage 4 of the Quick Start example.

The next Quick Start stage is:

· Monitoring the Program

The previous Quick Start stage was:

· Editing the Program


1.4.5 Monitoring the Program

This is stage 5 of the Quick Start example for Machine Control Studio.

In this stage the example program is monitored as it executes on the Unidrive M onboard target.

When online, Machine Control Studio adds some new functionality to the user interface. See Figure 38
below for an example.

Figure 38 – Machine Control Studio w hile Online

Notice a few changes to the display:

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 37

· The Device Name and Application are highlighted in green on the Devices tree. This indicates that they
are the active Device and active Application on the device.
· In a program or function block editor view, the Variable Declaration section turns into a Watch
Window, allowing you to monitor and modify variable values within that program or function block. Note
that the Name, Data Type, and Comment all are displayed in the watch window as well.
· The Code Section of the program or function block editor now shows online values for each of the
variables within the program.
· The Status Bar along the bottom of the interface shows the operating status of the tasks/programs.
By default, after downloading, the Status should indicate “STOP” meaning that the application is not
running.

Step 1 – Run the Application

Now that the project has been downloaded, and Machine Control Studio is online with the target, we are
ready to run the application. The user has several options on how to run the application:

· Select Debug > Start from the Menu Bar


· Press the F5 key on your keyboard
· Press the Start icon on the toolbar

Choose one of the above methods to run/start the application. Once started, you should notice that the
Status Bar changes to “RUN” in green, and the variables in the program will begin to change values.

Note that the project can be configured to run automatically on power-up or reboot by setting M11.P047
to a value of Run (1), and saving the drive parameter set. Use caution whenever configuring the program
to run automatically on power-up or reboot, as it could lead to unexpected behavior for those not familiar
with the system operation.

Step 2 – Watch the Clock Program Variables

The program should now be running. Be sure to click on the Clock Program tab to monitor the operation
of the program. You can now monitor the value of the RampOutVal variable in the Clock program. The
RampOutVal should ramp up towards the Setpoint value of 5000. When it reaches 5000, the Setpoint
should automatically change to -5000, and the RampOutVal should ramp down to -5000. The program
should continue in that capacity, ramping back up and then down, repeatedly.

Step 3 – Look Inside the Function Block

After monitoring the Clock Program, you can also look inside the Ramp1 Function Block to see what it
is doing. Click on the MyRamp along the top of the interface, or if it isn’t still open as a tab, simply
double-click it in the Devices tree. You will then see the operation of the ramp Function Block along with
a watch window for each of its internal variables.
Note that if multiple instances of the MyRamp Function Block had been used in a program, you can
double-click on the MyRamp object in the Devices tree, and Machine Control Studio will pop up a dialog
asking you which instance of the function block you with to monitor/debug.

Step 4 – Modify the Setpoint and Ramp Values

We will now modify the Setpoint and one of the Ramp values while online. Navigate back to the Clock
program. While on this view, we will modify the Prepared Value for the Setpoint variable in the watch
window as seen in Figure 39 below.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 38

Figure 39 – Modifying the Prepared Value of “Setpoint”

Enter the new desired value for the Setpoint variable into the Prepared Value field (try using the value
10000). Press Enter on your keyboard to apply the value to the editor. Note that this does not send the
new value to the variable yet. At this point, if you look at the value of the variable within the program, it
will show its actual online value as well as the Prepared Value in <braces> as seen in Figure 40 below.

Figure 40 – Prepared Value Appears in Braces

To apply (or Write) the Prepared Value to the program, either select Debug > Write Values from the
Menu Bar, or press Ctrl + F7 on your keyboard. The value will then be written to the program and take
effect immediately. If this process has worked, you should notice that the ramp now ramps to the new
Setpoint value of 10000 instead of the initial value of 5000.
Repeat the same process for one of the ramp rate parameters (UpRate or DownRate). Set one of them
to 2000 and Write Values to apply it to the program. Watch how the ramp now ramps much faster in the
direction that you modified.

Step 4 – Create a Custom Watch Window

The Watch Windows that are created automatically in the Variable Declaration section are great for
monitoring the variables within a given program or function block. However, imagine a scenario of a
project containing several programs and up to 20 or more function blocks. What if you want to monitor a
variable from several different programs or several different function blocks? How do you do this without
jumping between screens every time you want to see a different variable? This can be done by creating
your own customized Watch Window.

To create your own Watch Window, select View > Watch > Watch 1 as seen in Figure 41 below.

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 39

Figure 41 – Creating a Custom Watch Window

This should cause Machine Control Studio to display a new watch window area in the user interface.
You can undock and move the new window to the desired location or leave it in its default position.
When the window appears, click in the Expression field and begin typing the name of the variable you
wish to display in the window. NOTE: you must prefix the name of the variable with the name of the
program or function block the variable is declared in. For example, the variable Setpoint must be referred
to as Clock. Setpoint since it is declared within the Clock program. Once you begin typing, you should
see the Intellisense list appear allowing you to select the desired item from a dropdown list of available
objects. Once you have entered the desired variable, press enter on the keyboard to add the variable to
the watch window. You may notice that Machine Control Studio changes the variable name to the fully
qualified system name. For example, Clock.Setpoint becomes, DriveName.Application.Clock.Setpoint.
Each of these items can be defined by the user: Drive Name, Application Name, Program (or POU)
Name, and Variable Name. They are combined and separated by dots to make up the fully qualified
system name. You should then see the new variable in the Watch 1 watch window as seen in Figure 42
below.

Figure 42 – Variable Added to a Watch Window

Note how the Watch Window also displays the Data Type, Prepared Value and Comment from the

Machine Control Studio User Guide © 2022 Control Techniques


Getting Started 40

variable declaration. This can be helpful information to determine if you have selected the correct variable
to display. You can also use this Watch Window to prepare values for variables in multiple programs
and/or function blocks so that they can all be written simultaneously.
An alternate method to add variables to the watch window is to double-click in the Expression field and
then click on the search utility icon on the right side of the field. This will launch the Input Assistant
which allows you to find the desired Watch Variable and click OK to add it to the list.

Note that if you select a Function Block as a variable to display in the Watch Window, you will have the
ability to expand and collapse the block. When expanded, you automatically see all of the variables
inside the function block in your Watch Window without having to add them each individually.

Step 5 – Find all Uses of a Variable

The final monitoring/debugging tool to be discussed is the Cross Reference List. This tool helps to debug
a program by allowing you to list all the spots in all programs or function blocks that a particular variable
is used or referenced. To view the Cross Reference List, select View > Cross Reference List from the
Menu Bar. This should cause Machine Control Studio to display the Cross Reference List in the user
interface. You can undock and move the new window to the desired location or leave it in its default
position. When the window appears, click in the Name field and begin typing the name of the variable
you wish to search for. Note that you do not need to further qualify the name by prefixing it with the
program or function block name. Once the variable name is entered, press the magnifier glass icon to
find all references of the variable. See Figure 43 below for an example.

Figure 43 – Cross Reference List

In this example, the variable Setpoint was searched. The Cross Reference List returned five references of
that variable. Note in the Access column, that the first item in the list is the Declaration of the variable.
The remaining items in the list are cases where the variable is read or written within the program or
function block code.

This is the end of the Quick Start example. If you wish to save the project and the other settings that
have been made on the fly, select File > Save Project from the Menu Bar or click the Save icon on the
toolbar. The Project can now be closed.

The previous Quick Start stage was:

· Building and Downloading the Program

Machine Control Studio User Guide © 2022 Control Techniques


Index 41

-Q-
Quick Start
Creating Projects 7
Overview 6, 7

Machine Control Studio User Guide © 2022 Control Techniques

You might also like